Caustics with Godot’s shaders

Dec
02

I’ve played a bit with shaders today, what I wished was a water shader that looking not too realistic for using in the game, the result is quite good in my humble opinion, changing the base colors, maybe I could use it for lava too.

here below the code I wrote:

uniform color color_1;
uniform color color_2;
uniform texture map;
uniform float velocity=1;
uniform float intensity=.5;
vec2 uv_1 = vec2( mod(UV.x + TIME*velocity ,1) , mod(UV.y,1) );
vec2 uv_2 = vec2( mod(UV.x ,1) , mod(UV.y + TIME*velocity ,1) );
vec2 uv_3 = vec2( mod(UV.x + TIME*-velocity,1) , mod(UV.y,1) );
vec2 uv_4 = vec2( mod(UV.x,1) , mod(UV.y + TIME*-velocity ,1) );
float mid = .5;
float PI = 3.14159265359;
uv_2 = vec2(cos(PI/2) * (uv_2.x - mid) + sin(PI/2) * (uv_2.y - mid) + mid, cos(PI/2) * (uv_2.y - mid) - sin(PI/2) * (uv_2.x - mid) + mid);
uv_3 = vec2(cos(PI) * (uv_3.x - mid) + sin(PI) * (uv_3.y - mid) + mid, cos(PI) * (uv_3.y - mid) - sin(PI) * (uv_3.x - mid) + mid);
uv_4 = vec2(cos(PI*1.5) * (uv_3.x - mid) + sin(PI*1.5) * (uv_3.y - mid) + mid, cos(PI*1.5) * (uv_3.y - mid) - sin(PI*1.5) * (uv_3.x - mid) + mid);
vec3 caustic = tex(map,uv_1).rrr *intensity/
tex(map,uv_2).rrr *intensity/
tex(map,uv_3).rrr *intensity/
tex(map,uv_4).rrr *intensity;
DIFFUSE = color_2.rgb * caustic + color_1.rgb * (vec3(1,1,1)-caustic);
  • img
    Mark Reply
    Feb 9, 2016 @ 10:27 am

    o_o

  • img
    Zariel Reply
    Feb 10, 2016 @ 0:10 am

    I’m not easily imsdesper. . . but that’s impressing me! 🙂

Popular posts

  • No popular posts!

Follow us!

"@mux213 I would say the time spent on terrain is not wasted at all :-)"
"@mux213 so you are in Italy and you don't tell me anything? :-D"
"@mux213 will be possible varying the texture of the particles too?"
"@mux213 awesome, it would be even better if you could add some randomness in the grass particles"
Skip to toolbar