water.frag 615 B

12345678910111213141516171819
  1. #version 130
  2. uniform sampler2D texture;
  3. uniform sampler2D heightmap;
  4. const vec2 size = vec2(2.0, 0.0);
  5. const ivec3 offset = ivec3(-1, 0, 1);
  6. void main(void)
  7. {
  8. vec2 coord = gl_TexCoord[0].xy;
  9. float s01 = textureOffset(heightmap, coord, offset.xy).x;
  10. float s21 = textureOffset(heightmap, coord, offset.zy).x;
  11. float s10 = textureOffset(heightmap, coord, offset.yx).x;
  12. float s12 = textureOffset(heightmap, coord, offset.yz).x;
  13. vec3 va = normalize(vec3(size.xy, s21 - s01));
  14. vec3 vb = normalize(vec3(size.yx, s12 - s10));
  15. vec2 dudv = cross(va, vb).rg;
  16. gl_FragColor = texture2D(texture, coord + dudv * 0.2);
  17. }