GLSL realizes simple Displace Mapping water Simulation fluid drawing "turn"

Source: Internet
Author: User
Tags vc9

Http://blog.csdn.net/a3070173/archive/2008/11/20/3342062.aspx

  1. Dislace mapping is actually in the vertex shader.
  2. Displacement offsets of vertices are often used for water simulation of fluid rendering.
  3. Vertex shader:
  4. Uniform float G_fscale;
  5. Uniform sampler2d g_displacetexture;
  6. void Main ()
  7. {
  8. float fdisplace = Texture2dlod (g_displacetexture, Gl_multitexcoord0.st, 0.0). R;
  9. VEC4 Vec4newvertex = VEC4 (gl_vertex.x, gl_vertex.y + g_fscale*fdisplace, GL_VERTEX.ZW);
  10. Gl_texcoord[0] = gl_multitexcoord0;
  11. Gl_position = Gl_modelviewprojectionmatrix*vec4newvertex;
  12. }
  13. Slice shader:
  14. Uniform sampler2d g_decaltexture;
  15. void Main ()
  16. {
  17. Gl_fragcolor = Texture2d (g_decaltexture, gl_texcoord[0].st);
  18. }
  19. Demo Effect:
  20. EXE file:http://www.fileupyours.com/view/219112/GLSL/Simple%20Displace%20Mapping.rar
  21. VC9 Run Library:http://www.fileupyours.com/view/219112/GLSL/VC9%26%2336816%3B%26%2334892%3B%26%2326102%3B%26% 2324211%3b.rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.