0

下面的代码将地球渲染为黑色地球。请注意,我是 WebGL 的初学者,也在我在某人的代码中找到并使用它的“制服”和参数部分下方。

如果我添加普通材质,它可以工作,但使用着色器它就不起作用。

脚本链接: https ://threejsdoc.appspot.com/doc/three.js/examples/js/ShaderExtras.js

<script type="text/javascript" src="js/three.min.js"></script>
<script type="text/javascript" src="js/ShaderExtras.js"></script>



//Earth
var earthTexture   = THREE.ImageUtils.loadTexture( "img/planets/earth_atmos_2048.jpg" );
var earthCloudsTexture   = THREE.ImageUtils.loadTexture( "img/planets/earth_clouds_1024.png" );
var earthNormalTexture   = THREE.ImageUtils.loadTexture( "img/planets/earth_normal_2048.jpg" );
var earthSpecularTexture = THREE.ImageUtils.loadTexture( "img/planets/earth_specular_2048.jpg" );

var earthShader = THREE.ShaderUtils.lib[ "normal" ];
var earthUniforms = THREE.UniformsUtils.clone( earthShader.uniforms );

    earthUniforms[ "tNormal" ].texture = earthNormalTexture;
    earthUniforms[ "uNormalScale" ].value = 0.85;

    earthUniforms[ "tDiffuse" ].texture = earthNormalTexture;
    earthUniforms[ "tSpecular" ].texture = earthSpecularTexture;

    earthUniforms[ "enableAO" ].value = false;
    earthUniforms[ "enableDiffuse" ].value = true;
    earthUniforms[ "enableSpecular" ].value = true;

    earthUniforms[ "uDiffuseColor" ].value.setHex( 0xffffff );
    earthUniforms[ "uSpecularColor" ].value.setHex( 0x333333 );
    earthUniforms[ "uAmbientColor" ].value.setHex( 0x000000 );
    earthUniforms[ "uShininess" ].value = 15;

var earthParameters = {

                fragmentShader: earthShader.fragmentShader,
                vertexShader: earthShader.vertexShader,
                uniforms: earthUniforms,
                lights: true,
                fog: true

                };

var earth_mat = new THREE.ShaderMaterial( earthParameters );

var earth_geom = new THREE.SphereGeometry( 200, 32, 32 );
earth_geom.computeTangents();
var earth = new THREE.Mesh( earth_geom, earth_mat );
earth.position.x = 6000;
scene.add( earth );
4

0 回答 0