THREE.UniformsUtils.merge shoudnt clone the texture

Merging should use the existing texture, not cloning it ( same for others parameters ), its counter intuitive and memory expensive. I find myself in the case I wanted to just add some fog uniforms & other common to my rawShader and it take me time to figure out my texture was cloning and thats why my shader wasnt working and my texture share between all my instance not updated..

If the user want to clone the texture then he should use UniformsUtils.clone(myUniforms) and then merging it, trying to hide this step can lead to some serious bugs.

Author: Fantashit

2 thoughts on “THREE.UniformsUtils.merge shoudnt clone the texture

  1. I believe the intention is for you to merge the uniforms data structures and assign values afterward.

    var a = { texture: { type: 't', value: null } };
    var b = { opacity: { type: 'f', value: 0 } };
    var uniforms = THREE.UniformsUtils.merge( [ a, b ] );
    uniforms.texture.value = myTexture;

    This is how it is done in the examples.

    If you assign the texture a value prior to merging, the texture will be cloned and the needsUpdate flag will be set to false. Obviously, that is not what you want.

  2. @Makio64

    Sounds like one can use Object.assign (which is already polyfilled in the library)

    var a = { texture: { value: mytexture } }
    var b = { opacity: { value: 0 } }
    var uniforms = Object.assign( a, b )

    Knowing this, we could start deprecating UniformsUtils.merge() in favour of Obect.assign(). I think this is better than changing the current behaviour of UniformsUtils.merge().

Comments are closed.