Three.js ShaderMaterial issue with lights

ε祈祈猫儿з 提交于 2020-02-04 14:30:29

问题


Helo, here's part of my code - earth globe :)

    function createGlobe(){
        var normalMap = THREE.ImageUtils.loadTexture("images/earth_normal_2048.jpg");
        var surfaceMap = THREE.ImageUtils.loadTexture("images/earth_surface_2048.jpg");
        var specularMap = THREE.ImageUtils.loadTexture("images/earth_specular_2048.jpg");

        var shader = THREE.ShaderLib["phong"];
        var uniforms = THREE.UniformsUtils.clone(shader.uniforms);

        uniforms["tNormal"] = {type:"t", value:normalMap};
        uniforms["tDiffuse"] = {type:"t", value:surfaceMap};
        uniforms["tSpecular"] = {type:"t", value:specularMap};

        //uniforms["enableDiffuse"] = true;
        //uniforms["enableSpecular"] = true;

        var shaderMaterial = new THREE.ShaderMaterial({
            fragmentShader:shader.fragmentShader,
            vertexShader:shader.vertexShader,
            uniforms:uniforms,
            lights:false
            });

        var globeGeometry = new THREE.SphereGeometry(1,32,32);

        //tangents are needed for the shader
        globeGeometry.computeTangents();

        globe = new THREE.Mesh(globeGeometry, shaderMaterial);

        globe.rotation.z = 0.41;

        earthgroup.add(globe);

        }

The problematic spot is at ShaderMaterial parameter "lights:true", when set there is following error

Uncaught TypeError: Cannot set property 'value' of undefined three.js:23875
refreshUniformsLights three.js:23875
setProgram three.js:23593
renderBuffer three.js:22018
renderObjects three.js:22689
render three.js:22563
render Earth-clouds.html:100
wrappedCallback

which is

function refreshUniformsLights ( uniforms, lights ) {

        uniforms.ambientLightColor.value = lights.ambient;
                ....
}

and that seems to me that lights are not defined? Well I got them. When I set lights:false it renders the globe with the default material. It looks like a bug that could by in my code :-)

来源:https://stackoverflow.com/questions/16508280/three-js-shadermaterial-issue-with-lights

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!