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! 🙂

Skip to toolbar