Http://blog.csdn.net/a3070173/archive/2008/11/20/3342062.aspx
- Dislace mapping is actually in the vertex shader.
- Displacement offsets of vertices are often used for water simulation of fluid rendering.
- Vertex shader:
- Uniform float G_fscale;
- Uniform sampler2d g_displacetexture;
- void Main ()
- {
- float fdisplace = Texture2dlod (g_displacetexture, Gl_multitexcoord0.st, 0.0). R;
- VEC4 Vec4newvertex = VEC4 (gl_vertex.x, gl_vertex.y + g_fscale*fdisplace, GL_VERTEX.ZW);
- Gl_texcoord[0] = gl_multitexcoord0;
- Gl_position = Gl_modelviewprojectionmatrix*vec4newvertex;
- }
- Slice shader:
- Uniform sampler2d g_decaltexture;
- void Main ()
- {
- Gl_fragcolor = Texture2d (g_decaltexture, gl_texcoord[0].st);
- }
- Demo Effect:
- EXE file:http://www.fileupyours.com/view/219112/GLSL/Simple%20Displace%20Mapping.rar
- VC9 Run Library:http://www.fileupyours.com/view/219112/GLSL/VC9%26%2336816%3B%26%2334892%3B%26%2326102%3B%26% 2324211%3b.rar