@ karwosts : Did what you advised and the water plane is completely black (Fig.1)
Here is the render function followed with 3 diffrent shaders,
all 3 using same render function below, use the reference image at the end of this post to see the result foreach shader version.
( also note that printing the infolog after compiling the shader shows no errors )
Render Function :
void render_main(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt( ex,ey,ez, tx,ty,tz, 0.0f,1.0f,0.0f ); shader_water.render(); SDL_GL_SwapBuffers();}void rcShaderObject_Water::render(){if(!this->bLoaded){ return; } /* lame exit *//* various states */glDisable( GL_DEPTH_TEST );glDisable( GL_LIGHT0 );glDisable( GL_LIGHTING );glColor3f( 1.0f, 1.0f, 1.0f );/* enable custom shader */glUseProgramObjectARB( this->shader_prog );/* enable and bind texture(s) : *//* normap map */glActiveTextureARB( GL_TEXTURE0_ARB );glEnable( GL_TEXTURE_2D );glBindTexture( GL_TEXTURE_2D, this->TEXID_NORMAL );/* cube map */glActiveTextureARB( GL_TEXTURE1_ARB );glEnable( GL_TEXTURE_CUBE_MAP_ARB );glBindTexture( GL_TEXTURE_CUBE_MAP_ARB, this->TEXID_CUBE );/* uniform(s) for fragment shader : */glUniform1iARB( this->locTexNormal, 0 );glUniform1iARB( this->locTexCube, 1 );/* enable states */glEnableClientState( GL_VERTEX_ARRAY );glEnableClientState( GL_NORMAL_ARRAY ); /* absolute ? */glEnableClientState( GL_TEXTURE_COORD_ARRAY );/* arrays for vertices, normals and texcoords */glVertexPointer( 3, GL_FLOAT, 0, MyMngrMsh.mesh[ this->MSHID_WATER ]->arr_v );glNormalPointer( GL_FLOAT, 0, MyMngrMsh.mesh[ this->MSHID_WATER ]->arr_n ); /* absolute ? */glTexCoordPointer( 2, GL_FLOAT, 0, MyMngrMsh.mesh[ this->MSHID_WATER ]->arr_t );/* draw */glDrawArrays( GL_TRIANGLES, 0, MyMngrMsh.mesh[ this->MSHID_WATER ]->tri_qty*3 );/* disable states */glDisableClientState( GL_TEXTURE_COORD_ARRAY );glDisableClientState( GL_NORMAL_ARRAY ); /* absolute ? */glDisableClientState( GL_VERTEX_ARRAY );/* disable texture(s) : *//* cube map */glActiveTextureARB( GL_TEXTURE1_ARB );glDisable( GL_TEXTURE_CUBE_MAP_ARB );/* normal map */glActiveTextureARB( GL_TEXTURE0_ARB );glDisable( GL_TEXTURE_2D );/* restore to opengl default shader */glUseProgramObjectARB( 0 );/* various states */glEnable( GL_DEPTH_TEST );glEnable( GL_LIGHT0 );glEnable( GL_LIGHTING );}
Shader Version 1 :
Check the texcoords for normal-map, see Fig.2 in reference image, shows correct.
/* vertex shader */void main(void) { gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0;}/* fragment shader */uniform sampler2D TexNormal;uniform samplerCube TexSkyBox; /* NOT USED, but required for 'glUniform1iARB()' in render function */void main(void) { vec3 mat_normal = texture2D( TexNormal, gl_TexCoord[0].xy ).rgb; gl_FragColor = vec4( mat_normal, 1.0 );}
Shader Version 2 :
Check the reflected cubemap from a STATIC tangent-normal, see Fig.3 in reference image, shows correct.
/* vertex shader */varying vec3 E;void main(void) { vec3 t = gl_NormalMatrix * vec3(1,0,0); /* tangent */ vec3 b = gl_NormalMatrix * vec3(0,1,0); /* bitangent */ vec3 n = gl_NormalMatrix * vec3(0,0,1); /* normal */ vec3 V = vec3( gl_ModelViewMatrix * gl_Vertex ); E.x = dot( V, t ); E.y = dot( V, b ); E.z = dot( V, n ); gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; /* normalmap */}/* fragment shader */uniform sampler2D TexNormal; /* NOT USED, but required for 'glUniform1iARB()' in render function */uniform samplerCube TexSkyBox;varying vec3 E;void main(void) { vec3 mat_normal = vec3( 0.5, 0.5, 1.0 ); vec3 N = normalize( mat_normal * 2.0 - 1.0 ); vec3 mat_skybox = textureCube( TexSkyBox, reflect(E,N).xyz ).rgb; gl_FragColor = vec4( mat_skybox, 1.0 );}
Shader Version 3 :
Check the reflected cubemap from the normal-map, see Fig.4 in reference image, shows incorrect abivious... the water palne is not visible
/* vertex shader */varying vec3 E;void main(void) { vec3 t = gl_NormalMatrix * vec3(1,0,0); /* tangent */ vec3 b = gl_NormalMatrix * vec3(0,1,0); /* bitangent */ vec3 n = gl_NormalMatrix * vec3(0,0,1); /* normal */ vec3 V = vec3( gl_ModelViewMatrix * gl_Vertex ); E.x = dot( V, t ); E.y = dot( V, b ); E.z = dot( V, n ); gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0; /* normalmap */}/* fragment shader */uniform sampler2D TexNormal;uniform samplerCube TexSkyBox;varying vec3 E;void main(void) { vec3 mat_normal = texture2D( TexNormal, gl_TexCoord[0].xy ).rgb; vec3 N = normalize( mat_normal * 2.0 - 1.0 ); vec3 mat_skybox = textureCube( TexSkyBox, reflect(E,N).xyz ).rgb; gl_FragColor = vec4( mat_skybox, 1.0 );}
Reference image :