FakeCaustics - 图1

    1. // Found this on GLSL sandbox. I really liked it, changed a few things and made it tileable.
    2. // by David Hoskins.
    3. // Water turbulence effect by joltz0r 2013-07-04, improved 2013-07-07
    4. // Updated 1/4/2020 by Saul Espinosa for Redshift 3D
    5. // This file is licensed under Apache 2.0 license
    6. // Redefine below to see the tiling...
    7. //#define SHOW_TILING
    8. #define TAU 6.28318530718
    9. shader FakeCaustics
    10. [[ string help = "generates a psuedo caustic like noise pattern",
    11. string label = "Fake Caustics" ]]
    12. (
    13. point Po = P,
    14. float Time = 0
    15. [[
    16. float min = 0, float max = 100
    17. ]],
    18. int iterations = 5
    19. [[
    20. int min = 0, int max = 20
    21. ]],
    22. output color Out = 0,
    23. )
    24. {
    25. float tt = Time * .5+23.0;
    26. // uv should be the 0-1 uv of texture...
    27. vector uv = Po;
    28. vector p = mod(uv*TAU*2.0, TAU)-250.0;
    29. // vector p = mod(uv*TAU, TAU)-250.0;
    30. vector i = vector(p);
    31. float c = 1.0;
    32. float inten = .005;
    33. for (int n = 0; n < iterations; n++)
    34. {
    35. float t = tt * (1.0 - (3.5 / float(n+1)));
    36. i = p + vector(cos(t - i[0]) + sin(t + i[1]), sin(t - i[1]) + cos(t + i[0]),0);
    37. c += 1.0/length(vector(p[0] / (sin(i[0]+t)/inten),p[1] / (cos(i[1]+t)/inten),0));
    38. }
    39. c /= float(iterations);
    40. c = 1.17-pow(c, 1.4);
    41. vector colour = vector(pow(abs(c), 8.0));
    42. colour = clamp(colour + vector(0.0, 0.35, 0.5), 0.0, 1.0);
    43. /*
    44. #ifdef SHOW_TILING
    45. // Flash tile borders...
    46. vec2 pixel = 2.0 / iResolution.xy;
    47. uv *= 2.0;
    48. float f = floor(mod(iTime*.5, 2.0)); // Flash value.
    49. vec2 first = step(pixel, uv) * f; // Rule out first screen pixels and flash.
    50. uv = step(fract(uv), pixel); // Add one line of pixels per tile.
    51. colour = mix(colour, vec3(1.0, 1.0, 0.0), (uv.x + uv.y) * first.x * first.y); // Yellow line
    52. */
    53. Out = vector(colour);
    54. Out = pow(Out,2.2);
    55. }