1

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.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); 
}
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
user338027
  • 51
  • 1
  • 7
  • Looks like a driver issue to me. What platform are you compiling on? – kvark Mar 19 '11 at 05:23
  • It can work when I declare "vec4 vViewPos" external main method of Vertex Shader. :). But it still misunderstand. @kvark: my video card is Nvidia Geforce 9300M GS 512MB. My OS is windows 7. I also installed AMD Emulator in my computer. – user338027 Mar 19 '11 at 09:16
  • By the way, I would write `length( ( vViewPos - u_eyePos ).xyz )` rather than `sqrt(...)`. – UncleZeiv Apr 07 '11 at 15:15

0 Answers0