Advertisement
charlie_oh

Untitled

Mar 10th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Godot GLSL 3.82 KB | Source Code | 0 0
  1. // image texture download - https://imgur.com/a/aa6Vz0P
  2. shader_type spatial;
  3. render_mode cull_back;
  4.  
  5. group_uniforms textures;
  6. uniform sampler2D DEPTH_TEXTURE: hint_depth_texture;
  7. uniform sampler2D water_tex : filter_linear_mipmap;
  8.  
  9. group_uniforms colours;
  10. uniform float alpha : hint_range(0.0, 1.0, 0.01) = 1.0;
  11. uniform vec3 top_detail_colour : source_color = vec3(0.0);
  12. uniform vec3 bottom_detail_colour : source_color = vec3(0.0);
  13. uniform vec3 base_colour : source_color = vec3(0.0);
  14.  
  15. group_uniforms water;
  16. uniform float water_scale : hint_range(-10.0, 50.0, 0.01) = 1.0;
  17. uniform vec3 water_offset = vec3(0.0);
  18. uniform float water_speed : hint_range(0.0, 10.0, 0.01);
  19. uniform vec3 second_layer_offset = vec3(0.0);
  20. uniform float second_layer_speed : hint_range(0.0, 10.0, 0.01) = 1.0;
  21.  
  22. group_uniforms waves;
  23. uniform float edge_distance = 0.1;
  24. uniform float edge_toggle : hint_range(0.0, 1.0, 1.0) = 1.0;
  25. uniform float wave_size : hint_range(0.0, 20.0, 0.01) = 0.5;
  26. uniform float wave_speed : hint_range(0.0, 20.0, 0.01) = 4.0;
  27.  
  28. group_uniforms displacement;
  29. uniform float displacement_amount : hint_range(0.0, 1.0, 0.01) = 0.0;
  30.  
  31. group_uniforms distortion;
  32. uniform float distortion_amount : hint_range(0.0, 1.0, 0.01) = 0.0;
  33. uniform float distortion_scale : hint_range(-10.0, 10.0, 0.01) = 1.0;
  34. uniform vec3 distortion_offset = vec3(0.0);
  35. uniform float distortion_speed : hint_range(0.0, 10.0, 0.01);
  36.  
  37. group_uniforms side_mask;
  38. uniform float offset : hint_range(-1.0, 1.0) = 0.5;
  39. uniform float fade : hint_range(0.0, 1.0) = 0.1;
  40.  
  41. void vertex() {
  42.     float distortion_tex = texture(water_tex,
  43.     UV * vec2(distortion_scale) + distortion_offset.xy * distortion_speed * TIME).z;
  44.    
  45.     VERTEX = vec3(distortion_tex) * vec3(displacement_amount) * NORMAL + VERTEX;
  46. }
  47.  
  48. void fragment() {
  49.     // Apply distortion to UVs
  50.     float distortion_tex = texture(water_tex,
  51.     UV * vec2(distortion_scale) + distortion_offset.xy * distortion_speed * TIME).z;
  52.     vec2 base_uv = UV;
  53.     base_uv.y += distortion_tex * distortion_amount;
  54.    
  55.     // Apply movement to textures
  56.     vec2 texture_water = texture(water_tex,
  57.     base_uv * vec2(water_scale) + water_offset.xy * water_speed * TIME).xy;
  58.     vec2 texture_water_2 = texture(water_tex,
  59.     base_uv * vec2(water_scale) + water_offset.xy * second_layer_speed * water_speed * TIME + second_layer_offset.xy).xy;
  60.    
  61.     // Blend colours
  62.     float detail_blend = step(0.5, 1.0 - ((1.0-texture_water.x) * texture_water_2.x));
  63.     vec3 detail_colour = mix(bottom_detail_colour, top_detail_colour, detail_blend);
  64.     float base_blend = step(0.5 ,texture_water.x + texture_water_2.x);
  65.     vec3 colour = mix(base_colour, detail_colour, base_blend);
  66.    
  67.     // Proximity fade from proximity fade node
  68.     float depth = texture(DEPTH_TEXTURE, SCREEN_UV,0.0).r;
  69.    
  70.     vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
  71.     vec4 world = INV_VIEW_MATRIX * INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
  72.     float depth_texture_y = world.y / world.w;
  73.     float vertex_y = (INV_VIEW_MATRIX * vec4(VERTEX, 1.0)).y;
  74.    
  75.     // World normal modified from https://github.com/Arnklit/TutorialResources/blob/main/world_normal_mix_shader_4/world_normal_mix_4.gdshader
  76.    
  77.     vec3 up_vector_viewspace = mat3(VIEW_MATRIX) * vec3(0.0, 1.0, 0.0);
  78.     float dot_product = dot(up_vector_viewspace, NORMAL);
  79.     float side_mask = smoothstep(offset - fade, offset + fade, dot_product);
  80.    
  81.     float prox_blend = 1.0 - clamp((vertex_y - depth_texture_y) / edge_distance, 0.0, 1.0);
  82.     float sin_ripple = abs(sin((prox_blend + TIME * wave_speed) * wave_size)) * prox_blend;
  83.     float waves_mask = step(1.0, pow(prox_blend, 8.0) + sin_ripple);
  84.     waves_mask = mix(0.0 ,waves_mask , side_mask);
  85.    
  86.     ALBEDO = mix(colour, top_detail_colour, waves_mask * edge_toggle);
  87.    
  88.    
  89.     ALPHA = alpha;
  90. }
  91.  
Tags: Shader
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement