# Can I make a TSL uniform node specific to a material, and not global?

**URL:** <https://discourse.threejs.org/t/can-i-make-a-tsl-uniform-node-specific-to-a-material-and-not-global/85864>\
**Category:** Questions\
**Tags:** uniforms, tsl, shaders\
**Created:** [August 5, 2025, 6:28pm UTC](https://discourse.threejs.org/t/can-i-make-a-tsl-uniform-node-specific-to-a-material-and-not-global/85864 "2025-08-05T18:28:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![torrent](https://avatars.discourse-cdn.com/v4/letter/t/4bbf92/32.png) [@torrent](https://discourse.threejs.org/u/torrent)\
**Post date:** [August 5, 2025, 6:29pm UTC](https://discourse.threejs.org/t/can-i-make-a-tsl-uniform-node-specific-to-a-material-and-not-global/85864/1 "2025-08-05T18:29:00Z")

</div>

Let’s say I have a simple TSL node like this:

```javascript
const goGreen = tsl.uniform(0);
const myTslNode = tsl.Fn(() => { 
    const n = tsl.vec4().toVar();
    tsl.If(goGreen.equal(1), () => {
        n.assign(tsl.vec4(0, 1, 0, 1));
    }).Else(() => {
        n.assign(tsl.vec4(1, 0, 0, 1));
    });
    return n;
})();

```

My question is, how can I make `myTslNode` reusable in multiple different materials? Right now, if I try to use `myTslNode` in multiple materials, then every time I update the `goGreen` uniform’s value (for example `goGreen.value = 0`), it will update it for all the materials I am using `goGreen` in. I would like the `goGreen` uniform to be material-specific, not global.

This way, I don’t have to duplicate the same node for every material I use it in.

Theoretically this could be supported, if I could create a “uniform of a uniform”. Instead of directly providing `myTslNode` with the `goGreen` node, we would provide it with a uniform that resolves to **another** uniform, where each “inner” uniform would be the material-specific uniform that resolves to `1` or `0`.

---

<div class="post-metadata">

**Author:** ![aset\_rahmgaliev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/aset_rahmgaliev/32/16449_2.png) [@aset\_rahmgaliev](https://discourse.threejs.org/u/aset_rahmgaliev)\
**Post date:** [August 6, 2025, 7:43am UTC](https://discourse.threejs.org/t/can-i-make-a-tsl-uniform-node-specific-to-a-material-and-not-global/85864/2 "2025-08-06T07:43:19Z")

</div>

Wouldn’t it be easier then for the function to take a parameter?

---

<div class="post-metadata">

**Author:** ![Oxyn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/oxyn/32/12902_2.png) [@Oxyn](https://discourse.threejs.org/u/Oxyn)\
**Post date:** [August 6, 2025, 9:03am UTC](https://discourse.threejs.org/t/can-i-make-a-tsl-uniform-node-specific-to-a-material-and-not-global/85864/3 "2025-08-06T09:03:31Z")

</div>

```javascript
let shaderMode;

const myShader = Fn(() => { 
	If( shaderMode.equal(0), () => {
		//some TSL code here
	})

	.ElseIf( shaderMode.equal(1), () => {
		//some TSL code here
	})
})();

const outputA = Fn(() => { // first variation
	shaderMode = uniform(0);
	const result = myShader;
	return result;
})();

const outputB = Fn(() => { // second variation
	shaderMode = uniform(1);
	const result = myShader;
	return result;
})();

materials[0].colorNode = outputA;
materials[1].colorNode = outputB;

```

Something like this?  
Here the main code (myShader) is written only one time, but three.js will compute two shaders using different uniforms for the outputs.

This is one of the cool feature of TSL, you can combine reuse and **nest** as many `Fn` functions you want to create infinite twisted shenanigans.

---

<div class="post-metadata">

**Author:** ![Hackerham](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/hackerham/32/68507_2.png) [@Hackerham](https://discourse.threejs.org/u/Hackerham)\
**Post date:** [April 20, 2026, 6:16pm UTC](https://discourse.threejs.org/t/can-i-make-a-tsl-uniform-node-specific-to-a-material-and-not-global/85864/4 "2026-04-20T18:16:06Z")

</div>

I’ve made issue/draftPR: [TSL: Override UniformGroup with data from Object · Issue #33428 · mrdoob/three.js · GitHub](https://github.com/mrdoob/three.js/issues/33428)
