Using lights in three.js shader

后端 未结 1 552
面向向阳花
面向向阳花 2021-01-06 12:44

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

相关标签:
1条回答
  • 2021-01-06 13:12

    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

    0 讨论(0)
提交回复
热议问题