shader100.frag 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #version 100
  2. precision mediump float;
  3. uniform sampler2D diffuse_texture;
  4. uniform sampler2D displacement_texture;
  5. uniform sampler2D framebuffer_texture;
  6. uniform mat3 fragcoord2uv;
  7. uniform float backbuffer;
  8. uniform float game_time;
  9. uniform vec2 animate;
  10. uniform vec2 displacement_animate;
  11. varying vec2 texcoord_var;
  12. varying vec4 diffuse_var;
  13. void main(void)
  14. {
  15. if (backbuffer == 0.0)
  16. {
  17. vec4 color = diffuse_var * texture2D(diffuse_texture, texcoord_var.st + (animate * game_time));
  18. gl_FragColor = color;
  19. }
  20. else
  21. {
  22. vec4 pixel = texture2D(displacement_texture, texcoord_var.st + (displacement_animate * game_time));
  23. vec2 displacement = (pixel.rg - vec2(0.5, 0.5)) * 255.0;
  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 = texture2D(framebuffer_texture, uv);
  28. vec4 color = diffuse_var * texture2D(diffuse_texture, texcoord_var.st + (animate * game_time));
  29. gl_FragColor = vec4(mix(color.rgb, back_color.rgb, alpha), color.a);
  30. }
  31. }
  32. /* EOF */