cubereflectshinymapnormal.shader

00001 
00002 varying vec3 vEye;
00003 varying vec3 mT;
00004 varying vec3 mB;
00005 varying vec3 mN;
00006 
00007 attribute vec3 tangent;
00008 
00009 void main() 
00010 {
00011     // Get the normal and normalize
00012     mN = normalize( gl_NormalMatrix * gl_Normal );
00013 
00014     // Get this fragment's position
00015     vec4 vPos = gl_ModelViewMatrix * gl_Vertex;
00016 
00017     // Get the eye vector
00018     vEye = -vPos.xyz;
00019 
00020     //Use the first set of texture coordinates in the fragment shader 
00021     gl_TexCoord[0] = gl_MultiTexCoord0;
00022 
00023 ///// Normal mapping specific:
00024 
00025     // Get the tangent and normalise
00026     mT = normalize( gl_NormalMatrix * tangent );
00027 
00028     // Get the binormal
00029     mB = cross( mN, mT );
00030 
00031     // Transform the position to screen space
00032     gl_Position = ftransform(); 
00033 }
00034 
00035 ~~~~~
00036 
00037 varying vec3 vEye;
00038 varying vec3 mT;
00039 varying vec3 mB;
00040 varying vec3 mN;
00041 
00042 uniform float reflectivity;
00043 
00044 uniform sampler2D Texture0; // Diffuse map
00045 uniform sampler2D Texture1; // Normal map
00046 uniform samplerCube Texture2; // Cube map
00047 // uniform sampler2D Texture3; // Shininess map
00048 // uniform sampler2D Texture4; // Emissive map
00049 
00050 void main() 
00051 {
00052     // Get the bump vector
00053     vec3 vTmp = normalize( texture2D( Texture1, gl_TexCoord[0].xy ).xyz * 2.0 - 1.0 );
00054     vTmp.y = -vTmp.y;
00055     
00056     // Get the tbn matrix
00057     vec3 vT = normalize( mT );
00058     vec3 vB = normalize( mB );
00059     vec3 vN = normalize( mN );
00060 
00061     // Put through the inverse of the TBN matrix
00062     vec3 vBump;
00063     vBump.x = vTmp.x * vT.x + vTmp.y * vB.x + vTmp.z * vN.x;
00064     vBump.y = vTmp.x * vT.y + vTmp.y * vB.y + vTmp.z * vN.y;
00065     vBump.z = vTmp.x * vT.z + vTmp.y * vB.z + vTmp.z * vN.z;
00066     
00067     // Get the eye vector
00068     vec3 vE = normalize( vEye );
00069 
00070     // Get the reflection vector
00071     vec3 vR = reflect( vE, vBump );
00072 
00073     // Put it through the matrix
00074     vR = mat3( gl_TextureMatrix[0] ) * vR;
00075     vR.x = -vR.x;
00076 
00077     // Get the value from the cubemap
00078     gl_FragColor = textureCube( Texture2, vR.xyz );
00079     //gl_FragColor = vec4( vR.xyz * 0.5 + 0.5, 1 );
00080 
00081     // Sample the diffuse texture
00082     vec4 tex = texture2D( Texture0, gl_TexCoord[0].xy );
00083     
00084     // Set the alpha
00085     gl_FragColor.a = reflectivity * tex.a;
00086 }

Generated on Fri Mar 23 12:55:03 2007 for glsldemo by  doxygen 1.5.1-p1