我正在尝试使用 Phong 着色为基于地球的场景照亮照明。我目前正在使用 Gouraud 着色,它不会像预期的那样产生球体的真实感。除此之外,我还显示了一个在顶点处发生的高光,如图所示
这是我的场景的相关代码。
照明计算;
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoordinates;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
varying vec2 vTextureCoordinates;
varying vec3 vNormalEye;
varying vec4 vPosition;
void main() {
vNormalEye = normalize(uNMatrix * aVertexNormal);
vPosition = uMVMatrix * vec4(aVertexPosition,1.0);
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition,1.0);
vTextureCoordinates = aTextureCoordinates;
}
</script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec2 vTextureCoordinates;
varying vec3 vNormalEye;
varying vec4 vPosition;
uniform sampler2D uSampler;
uniform vec3 uAmbientLightColor;
uniform vec3 uLightPosition;
uniform vec3 uDiffuseLightColor;
uniform vec3 uSpecularLightColor;
const float shine = 32.0;
void main() {
vec3 direction = normalize(-vPosition.xyz + uLightPosition);
vec3 reflection = reflect(-direction,vNormalEye);
float rdotv = max(dot(reflection,direction),0.0);
float specularLightWeighting = pow(rdotv,shine);
float directionalLightWeighting = max(dot(vNormalEye,uLightPosition),0.0);
vec3 vLightWeighting = uAmbientLightColor + uDiffuseLightColor * directionalLightWeighting + uSpecularLightColor * specularLightWeighting;
vec4 textureColor = texture2D(uSampler,vec2(vTextureCoordinates.s,vTextureCoordinates.t));
gl_FragColor = vec4(textureColor.rgb * vLightWeighting, textureColor.a);
}
</script>
照明配置;
function setupLights() {
var angleDegree = 60;
var lightDistance = 3.5;//Light intensity
var angleRadian = angleDegree * Math.PI / 180; //Work out 60 degrees from180 degress
var xDir = Math.cos(angleRadian);
var yDir = Math.sin(angleRadian);
gl.uniform3fv(pwgl.uniformLightPositionLoc, [lightDistance * xDir, lightDistance * yDir, 0.0]);
gl.uniform3fv(pwgl.uniformAmbientLightColorLoc, [0.4, 0.4, 0.4]);
gl.uniform3fv(pwgl.uniformDiffuseLightColorLoc, [0.7, 0.7, 0.7]);
gl.uniform3fv(pwgl.uniformSpecularLightColorLoc, [0.8, 0.8, 0.8]);
}
这是解决此问题的最佳方法是什么?我需要实施什么样的照明计算?
此外,哪种类型的阴影最适合球体的真实感?