I try to compile shader in a book: Opengl es 2.0 programming guide- chapter 10 - linear fog by both RenderMonkey and Visual studio 2008
But it throws the same error: Error linking program
vertex info
fatal error C9999: * exception during compilation *
I try to fix it, but still cannot. Could you tell me what is problem and how can solve it ???
Vertex and Fragment shader code:
//-------------------------------------vertex shader--------------------------------------
uniform mat4 matViewProjection;
uniform mat4 matView;
uniform vec4 u_eyePos;
attribute vec4 rm_Vertex;
attribute vec2 rm_TexCoord0;
varying vec2 v_texCoord;
varying float v_eyeDist;
void main( void )
{
// Transform vertex to view-space
vec4 vViewPos = matView * rm_Vertex;
// Compute the distance to eye
v_eyeDist = sqrt( (vViewPos.x - u_eyePos.x) *
(vViewPos.x - u_eyePos.x) +
(vViewPos.y - u_eyePos.y) *
(vViewPos.y - u_eyePos.y) +
(vViewPos开发者_如何学C.z - u_eyePos.z) *
(vViewPos.z - u_eyePos.z) );
gl_Position = matViewProjection * rm_Vertex;
v_texCoord = rm_TexCoord0.xy;
}
//-------------------------------------fragment shader-------------------------------------
precision mediump float;
uniform vec4 u_fogColor;
uniform float u_fogMaxDist;
uniform float u_fogMinDist;
uniform sampler2D baseMap;
varying vec2 v_texCoord;
varying float v_eyeDist;
float computeLinearFogFactor()
{
float factor;
// Compute linear fog equation
factor = (u_fogMaxDist - v_eyeDist) /
(u_fogMaxDist - u_fogMinDist );
// Clamp in the [0,1] range
factor = clamp( factor, 0.0, 1.0 );
return factor;
}
void main( void )
{
float fogFactor = computeLinearFogFactor();
vec4 fogColor = fogFactor * u_fogColor;
vec4 baseColor = texture2D( baseMap, v_texCoord );
// Compute final color as a lerp with fog factor
gl_FragColor = baseColor * fogFactor +
fogColor * (1.0 - fogFactor);
}
精彩评论