我想使用Normal.js的法线贴图着色器渲染具有置换贴图的球体。我也在场景中使用了PointLight。
问题是我不能让我的位移球体正确点亮。事实上,如果我省略纹理,球体全部是黑色的,带有法线贴图着色器材质,但是使用简单的meshLambertMaterial可以正确点亮它。 (见下图)
我尝试使用normalmap / displacement shader和meshLambertMaterial进行多材质网格,但结果并不确定。
在创建着色器材质时我做错了什么(参见下面的代码)?
var specularColor = 0xcccccc;
var diffuseColor = 0xffffff;
var ambiantColor = 0x888888;
var shader = THREE.ShaderLib["normalmap"];
var uniforms = THREE.UniformsUtils.clone(shader.uniforms);
uniforms["enableAO"].value = 0;
uniforms["enableDiffuse"].value = 1;
uniforms["enableSpecular"].value = 1;
uniforms["enableReflection"].value = 0;
uniforms["enableDisplacement"].value = 1;
uniforms["tNormal"].value = normalTexture;
uniforms["tSpecular"].value = specularTexture;
uniforms["uNormalScale"].value = 1.0;
uniforms["tDisplacement"].value = heightTexture;
uniforms["uDisplacementScale"].value = 5;
uniforms["uDiffuseColor"].value.setHex(diffuseColor);
uniforms["uSpecularColor"].value.setHex(specularColor);
uniforms["uAmbientColor"].value.setHex(ambiantColor);
uniforms["uShininess"].value = 1;
var parameters = {
fragmentShader : shader.fragmentShader,
vertexShader : shader.vertexShader,
uniforms : uniforms,
lights : true
};
var material = new THREE.ShaderMaterial(parameters);
var geometry = new THREE.SphereGeometry(radius, 100, 100);
geometry.computeTangents();
var mesh = new THREE.Mesh(geometry, material);
答案 0 :(得分:2)
有一件事显然是错误的。它应该是
uniforms[ "uNormalScale" ].value.set( 1.0, 1.0 );
three.js r.58