Advertisement
Mux213

Godot water shader

Apr 8th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. shader_type spatial;
  2.  
  3. uniform vec4 base_color : hint_color;
  4. uniform sampler2D seabed;
  5. uniform sampler2D dudv_map;
  6.  
  7. uniform float wave_speed = 0.05;
  8. uniform vec2 wave_strength = vec2(0.05, 0.005);
  9.  
  10. varying vec3 world_pos;
  11.  
  12. void vertex() {
  13.     world_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0)).rgb;
  14. }
  15.  
  16. void fragment() {
  17.     float mix_value = 0.94;
  18.    
  19.     // calculate our distortion using our DuDv map
  20.     vec2 start_uv = vec2(world_pos.x * 0.01, world_pos.z * 0.01);
  21.     vec2 distortion = texture(dudv_map, vec2(start_uv.x + (TIME * wave_speed), start_uv.y)).rg * wave_strength.x;
  22.     distortion = (texture(dudv_map, vec2(start_uv.x + distortion.x, start_uv.y + distortion.y + (TIME * wave_speed))).rg * 2.0 - 1.0) * wave_strength.y;
  23.    
  24.     // this need to change and not use screen texture but use a texture from a viewport with a proper clip plane
  25.     vec3 ground_color = textureLod(seabed, start_uv + distortion, 0.0).rgb;
  26.     ALBEDO = mix(ground_color, base_color.rgb, mix_value);
  27.    
  28.     NORMAL = (INV_CAMERA_MATRIX * WORLD_MATRIX * vec4(normalize(vec3(distortion.x, 0.01, distortion.y)), 0.0)).xyz;
  29.    
  30.     SPECULAR = 0.5;
  31.     ROUGHNESS = 0.6;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement