I\'m trying to access the scene\'s lights from a shader in three.js.
This question is nearly a duplicate of Three.js ShaderMaterial issue with lights but the comment
If you want to use scene lights with ShaderMaterial
, in addition to setting lights: true
, you need to create your uniforms using this pattern:
var uniforms = THREE.UniformsUtils.merge( [
THREE.UniformsLib[ "ambient" ],
THREE.UniformsLib[ "lights" ]
] );
var material = new THREE.ShaderMaterial( {
uniforms: uniforms,
vertexShader: document.getElementById('vertexShader').innerHTML,
fragmentShader: document.getElementById('fragmentShader').innerHTML,
lights: true
} );
Updated fiddle: https://jsfiddle.net/zhkvcajs/3/
three.js r.74