我已经在我的代码和着色器中设置了我的照明,但除了我目前拥有的四边形之外什么都看不到。灯光不工作,我真的看不出哪里出错了。
我有一个带有纹理的四边形,其中四边形旋转了 90 度,因此它平放,在我的代码中,我已经完成了这样的照明......
// Set light direction in model space
PVRTVec4 vLightDirModel;
vLightDirModel = modelView.inverse() * PVRTVec4(0.57735f, 0.57735f, 0.57735f, 0);
glUniform3fv(m_ShaderProgram.auiLoc[eLight], 1, &vLightDirModel.x);
// Set eye position in model space
PVRTVec4 vEyePosModel;
vEyePosModel = modelView.inverse() * PVRTVec4(0, 0, 0, 1);
glUniform3fv(m_ShaderProgram.auiLoc[eEyePos], 1, &vEyePosModel.x);
这是我的着色器
垂直着色器:
attribute highp vec3 inVertex;
attribute mediump vec2 inTexCoord;
uniform highp mat4 MVPMatrix;
uniform mediump vec3 LightDir;
uniform mediump vec3 EyePos;
varying mediump vec3 EyeDir;
varying lowp float specIntensity;
varying mediump vec2 TexCoord;
const mediump float cShininess = 10.0;
void main()
{
// Transform position
gl_Position = MVPMatrix * vec4(inVertex,1.0);
// Calculate direction from eye position in model space
mediump vec3 EyeDir = normalize(EyePos - inVertex);
// Specular lighting
// We ignore that N dot L could be negative (light coming
// from behind the surface)
mediump vec3 halfVector = normalize(LightDir + EyeDir);
lowp float NdotH = max(dot(inNormal, halfVector), 0.0);
specIntensity = pow(NdotH, cShininess);
TexCoord = inTexCoord;
}
这是我的碎片着色器
均匀采样器2D反射Tex;
varying mediump vec2 TexCoord;
varying lowp float specIntensity;
//This gets updated within the main code
uniform highp float Time;
void main()
{
lowp vec3 refColor = texture2D(reflectionTex, TexCoord).rgb;
gl_FragColor = vec4(refColor + specIntensity, 1.0);
}