Three.js ShaderMaterial问题与灯光

时间:2013-05-12 14:14:50

标签: three.js

Helo,这是我的代码的一部分 - 地球地球:)

    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);

        }

问题点在ShaderMaterial参数“lights:true”,设置时出现以下错误

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

function refreshUniformsLights ( uniforms, lights ) {

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

在我看来,灯没有定义?好吧,我得到了它们。 当我设置灯光:false时,它会使用默认材质渲染地球仪。它看起来像我的代码中可能出现的错误: - )

0 个答案:

没有答案