THREE.UniformUtils.merge silently fails with 2d textures

This 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: [] }
                };

Author: Fantashit

2 thoughts on “THREE.UniformUtils.merge silently fails with 2d textures

Comments are closed.