shader330.frag 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #version 330 core
  2. uniform sampler2D diffuse_texture;
  3. uniform sampler2D displacement_texture;
  4. uniform sampler2D framebuffer_texture;
  5. uniform mat3 fragcoord2uv;
  6. uniform float backbuffer;
  7. uniform float game_time;
  8. uniform vec2 animate;
  9. uniform vec2 displacement_animate;
  10. in vec4 diffuse_var;
  11. in vec2 texcoord_var;
  12. out vec4 fragColor;
  13. void main(void)
  14. {
  15. if (backbuffer == 0.0)
  16. {
  17. vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time));
  18. fragColor = color;
  19. }
  20. else if (true)
  21. {
  22. vec4 pixel = texture(displacement_texture, texcoord_var.st + (displacement_animate * game_time));
  23. vec2 displacement = (pixel.rg - vec2(0.5, 0.5)) * 255;
  24. float alpha = pixel.a;
  25. vec2 uv = (fragcoord2uv * (gl_FragCoord.xyw + vec3(displacement.xy * alpha, 0))).xy;
  26. uv = vec2(uv.x, 1.0 - uv.y);
  27. vec4 back_color = texture(framebuffer_texture, uv);
  28. vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st + (animate * game_time));
  29. fragColor = vec4(mix(color.rgb, back_color.rgb, alpha), color.a);
  30. }
  31. else
  32. {
  33. // water reflection
  34. vec4 color = diffuse_var * texture(diffuse_texture, texcoord_var.st);
  35. vec2 uv = (fragcoord2uv * gl_FragCoord.xyw).xy + vec2(0, 0.05);
  36. uv.x = uv.x + 0.005 * sin(game_time + uv.y * 100);
  37. uv = vec2(uv.x, 1.0 - uv.y);
  38. vec4 back_color = texture(framebuffer_texture, uv);
  39. if (backbuffer == 0.0)
  40. fragColor = color;
  41. else
  42. if (uv.y > 0.5)
  43. fragColor = vec4(mix(vec3(0,0,0.75), mix(color.rgb, back_color.rgb, 0.95 * backbuffer), (1.2 - uv.y) * (1.2 - uv.y)), 1.0);
  44. else
  45. fragColor = color;
  46. }
  47. }
  48. /* EOF */