question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

THREE.UniformUtils.merge silently fails with 2d textures

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
medmr1commented, Jul 16, 2013

It would be nice if simply enabling lights on a material enabled these uniforms as well.

2reactions
cassielcommented, Apr 11, 2016

Oh, there’s some explanation here: https://github.com/mrdoob/three.js/issues/8016

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found