Getting no uniforms even when set in onBeforeCompile

Hi,

I´m expanding MeshStandardMaterial by using onBeforeCompile. Im adding some
uniforms like

    this.shaderUniforms = {
      time: {value: 0,0},
    }

    myMaterial.onBeforeCompile = shader => {
        shader.uniforms.time = this.shaderUniforms.time;
        shader.vertexShader = `
                        uniform float time;

      ` + shader.vertexShader;
        return shader;
    };

    this.powder = new THREE.Mesh( powderGeometry, powderMaterial );

But when console.log checking for mesh.material.uniforms → it seems my onBeforeCompile mods didn´t work as I do not have uniforms in there…

?
B

Please demonstrate the issue with a live example. Having a time uniform seems to work fine in the following fiddle: https://jsfiddle.net/8n0edab7/

1 Like

Hmmm… your example is using userData.shader to store the scope… I thought if I use onBeforeCompile and add uniforms, they would be kind of the modified “material”. No?

No since built-in materials have no uniforms property.

1 Like