THREE.UniformUtils.merge silently fails with 2d textures
See original GitHub issueThis has been somewhat addressed in Issue #1179 and #1135 with the answer being not to use it. Why brush this under the rug?
The result is that my tNormal texture shown below only returns black as opposed to its assigned texture. Also note that tCube still gets sampled correctly.
My goal is to easily add the uniforms necessary for lighting. Here’s my my basic (broken) test:
uniforms = {
time: { type: "f", value: 1.0 },
uRepeat: { type: "v2", value: new THREE.Vector2(5.0, 5.0) },
tCube: { type: "t", value: skyCubemap },
tNormal: { type: "t", value: normalmap }
};
// Add lighting uniforms
uniforms = THREE.UniformsUtils.merge( [uniforms, THREE.UniformsLib[ "lights" ] ]);
The code below works but is unnecessarily verbose:
uniforms = {
time: { type: "f", value: 1.0 },
uRepeat: { type: "v2", value: new THREE.Vector2(5.0, 5.0) },
tCube: { type: "t", value: skyCubemap },
tNormal: { type: "t", value: normalmap },
ambientLightColor : { type: "fv", value: [] },
directionalLightDirection : { type: "fv", value: [] },
directionalLightColor : { type: "fv", value: [] },
hemisphereLightDirection : { type: "fv", value: [] },
hemisphereLightSkyColor : { type: "fv", value: [] },
hemisphereLightGroundColor : { type: "fv", value: [] },
pointLightColor : { type: "fv", value: [] },
pointLightPosition : { type: "fv", value: [] },
pointLightDistance : { type: "fv1", value: [] },
spotLightColor : { type: "fv", value: [] },
spotLightPosition : { type: "fv", value: [] },
spotLightDirection : { type: "fv", value: [] },
spotLightDistance : { type: "fv1", value: [] },
spotLightAngleCos : { type: "fv1", value: [] },
spotLightExponent : { type: "fv1", value: [] }
};
Issue Analytics
- State:
- Created 10 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
UniformsUtils – three.js docs
Merges the given uniform definitions into a single object. ... it performs a deep-copy when producing the merged uniform definitions.
Read more >Custom shaders with Three.JS: Uniforms, textures and lighting
In this post, I'll show you how to setup a custom shader with a three.js geometry, pass it your own uniforms, bind a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It would be nice if simply enabling lights on a material enabled these uniforms as well.
Oh, there’s some explanation here: https://github.com/mrdoob/three.js/issues/8016