heat.fp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Modified by AFADoomer from http://www.blog.nathanhaze.com/glsl-desert-mirageheat-wave-effect/
  2. // and https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson5
  3. const float stepsize = 0.000015; // The amplitude of the distortion waves
  4. const float stepscale = 2.5; // The scale of the effect (this controls the number of repetitions of the pattern that are crammed into screen space, so higher numbers means more repetitions, so smaller effect scale)
  5. const float timescale = 0.15; // The speed of the effect (modifies timer, so 0.5 means every two timer ticks, 2.0 means every half timer tick, etc.)
  6. const float bluramt = 25; // The max amount of blur to give the scene
  7. float random()
  8. {
  9. vec2 co = vec2(mod(timer, 1000.0) / 1000.0, 1.0);
  10. return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); // This is a commonly used pseudo-random number algortihm for GLSL
  11. }
  12. void main()
  13. {
  14. // Max amount is 128
  15. float amt = clamp(amount, 0.0, 128.0);
  16. // Calculate timer-based modifier value that accounts for stepsize
  17. float step = stepsize * 8750000.0; // No idea why I'm using this modifier value, but it works. Trial and error...
  18. float t = step + mod(radians(timer * timescale), radians(90.0)) * step;
  19. // Re-center the coordinates so that the edges of the screen actually distort equally
  20. float coordx = mod(timer * timescale, 750.0) / 1000.0 - abs(TexCoord.x - 0.5);
  21. vec2 offset = vec2(0.0);
  22. offset.x = stepsize * amt * sin(stepscale * TexCoord.y) * sin(t * mod(coordx, 1.0));
  23. offset.y = stepsize * amt * sin(stepscale * TexCoord.x) * sin(t * TexCoord.y);
  24. // Add blur effect
  25. float radius = 0.0001 * min(amt, bluramt); // Scale blur up with shader control inventory amount, up to a max of bluramt.
  26. float hstep = 0.7;
  27. float vstep = 1.0;
  28. vec4 sum = vec4(0.0);
  29. sum += texture(InputTexture, vec2(TexCoord.x - 2.0 * radius * hstep, TexCoord.y - 2.0 * radius * vstep) + offset) * 0.0162162162;
  30. sum += texture(InputTexture, vec2(TexCoord.x - 1.5 * radius * hstep, TexCoord.y - 1.5 * radius * vstep) + offset) * 0.0540540541;
  31. sum += texture(InputTexture, vec2(TexCoord.x - 1.0 * radius * hstep, TexCoord.y - 1.0 * radius * vstep) + offset) * 0.1216216216;
  32. sum += texture(InputTexture, vec2(TexCoord.x - 0.5 * radius * hstep, TexCoord.y - 0.5 * radius * vstep) + offset) * 0.1945945946;
  33. sum += texture(InputTexture, vec2(TexCoord.x, TexCoord.y) + offset) * 0.2270270270;
  34. sum += texture(InputTexture, vec2(TexCoord.x + 0.5 * radius * hstep, TexCoord.y + 0.5 * radius * vstep) + offset) * 0.1945945946;
  35. sum += texture(InputTexture, vec2(TexCoord.x + 1.0 * radius * hstep, TexCoord.y + 1.0 * radius * vstep) + offset) * 0.1216216216;
  36. sum += texture(InputTexture, vec2(TexCoord.x + 1.5 * radius * hstep, TexCoord.y + 1.5 * radius * vstep) + offset) * 0.0540540541;
  37. sum += texture(InputTexture, vec2(TexCoord.x + 2.0 * radius * hstep, TexCoord.y + 2.0 * radius * vstep) + offset) * 0.0162162162;
  38. sum /= 0.2270270270 + 0.772972973;
  39. FragColor = vec4(sum.rgb, 1.0);
  40. }