我已经在我的代码和着色器中设置了我的灯光,但除了我目前的四边形之外看不到任何东西。照明不起作用,我无法真正看到我出错的地方。
我有一个带有纹理的四边形,其中四边形旋转了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);
这是我的着色器
VERT SHADER:
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;
}
这是我的片段着色器
均匀sampler2D reflectionTex;
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);
}
答案 0 :(得分:0)
您正在混淆照明计算。在你的评论中,你说你正在计算镜面照明术语。所以对于你的平面,你希望用你的代码看到的最多就是四边形上的一个小的白色区域, IF 光线正好相反。即便如此,由于您没有计算反射光矢量,因此计算错误。
基本的phong照明模型包括另外两个术语,漫反射(漫反射(根据正常和光的vec之间的角度改变颜色,即角度越大,颜色越深)和Ambient(为每个片段添加均匀的光)模拟环境光。)
我建议你阅读这篇优秀的教程并将其改编为ES: http://www.ozone3d.net/tutorials/glsl_lighting_phong.php