Custom shader light reflection

Hello.

My custom shader is not affected by lighting.
How can I make it affected by ambient lighting like normal three.js materials?
If you have a suitable example, please let me know.

Hi,

You have to set lights to true and to provide all uniforms data regarding light information.

new THREE.ShaderMaterial({
    vertexShader: VertShader,
    fragmentShader: FragShader,
    lights:true,
    uniforms:
    {
        ambientLightColor:{value:new THREE.Color('#ffffff')},
        lightProbe:{value:1},
        directionalLights:{value:new THREE.Vector3(1,0,2)},
        directionalLightShadows:{value:false},
        spotLights:{value:false},
        spotLightShadows:{value:false},
        spotShadowMap:{value:false},
        spotShadowMatrix:{value:false},
        rectAreaLights:{value:false},
        ltc_1:{value:false},
        ltc_2:{value:false},
        pointLights:{value:false},
        pointLightShadows:{value:false},
        pointShadowMap:{value:false},
        pointShadowMatrix:{value:false},
        hemisphereLights:{value:false},
        directionalShadowMap:{value:false},
        directionalShadowMatrix:{value:false}
}
})

the simplest way would be to use one of built-in materials with onBeforeCompile handler to inject your glsl code

1 Like