-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a05c4c2
commit ee73eb6
Showing
10 changed files
with
159 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,106 @@ | ||
[gd_resource type="ShaderMaterial" load_steps=8 format=3 uid="uid://vbqj6uwb6wph"] | ||
[gd_resource type="ShaderMaterial" load_steps=6 format=3 uid="uid://vbqj6uwb6wph"] | ||
|
||
[sub_resource type="Shader" id="Shader_ty6yi"] | ||
code = "shader_type spatial; | ||
render_mode cull_disabled; | ||
|
||
uniform vec3 albedo : source_color; | ||
uniform vec3 albedo2 : source_color; | ||
uniform float metallic : hint_range(0.0, 1.0) = 0; | ||
uniform float roughness : hint_range(0.0, 1.0) = 0.02; | ||
uniform sampler2D wave; | ||
uniform sampler2D texture_normal; | ||
uniform sampler2D texture_normal2; | ||
uniform vec2 wave_direction = vec2(2.0,0.0); // Direction of wave 1 | ||
uniform vec2 wave_direction2 = vec2(0.0,1.0); // Direction of wave 2 | ||
uniform float time_scale : hint_range(0.0, 0.2, 0.005) = 0.025; // Rate of movement multiplied by TIME | ||
uniform float noise_scale = 10.0; | ||
uniform float height_scale = 0.15; | ||
uniform float wave_speed = 0.0; | ||
uniform float wave_time = 0.0; | ||
|
||
uniform vec4 color_deep : source_color; // Deep depth color | ||
uniform vec4 color_shallow : source_color; // Shallow depth color | ||
uniform float beers_law = 2.0; // Beer's law application | ||
uniform float depth_offset = -0.75; // Offset | ||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap, repeat_disable; | ||
uniform sampler2D DEPTH_TEXTURE : hint_depth_texture, filter_linear_mipmap; | ||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap; | ||
|
||
uniform float edge_scale = 0.1; | ||
uniform float near = 1.0; | ||
uniform float far = 100.0; | ||
uniform vec3 edge_color : source_color; | ||
uniform float uv_scale = 1.0; | ||
uniform float normal_scale = 1.0; | ||
uniform float roughness_scale = 1.0; | ||
uniform float metallic_scale = 1.0; | ||
uniform float time_scale = 1.0; | ||
uniform float distortion_smoothing : hint_range(100.0, 1000.0) = 1.0; | ||
uniform vec3 water_color : source_color; | ||
uniform sampler2D wave : hint_normal; | ||
uniform float depth_distance : hint_range(0.0, 10.0, 0.1) = 0.5; | ||
|
||
// Varying variables | ||
varying float height; | ||
varying vec3 world_pos; | ||
uniform float noise_scale = 10.0; | ||
uniform float height_scale = 0.15; | ||
uniform float wave_speed = 0.0; | ||
uniform float wave_time = 0.0; | ||
|
||
float fresnel(float amount, vec3 normal, vec3 view) | ||
{ | ||
return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0 )), amount); | ||
} | ||
float edge(float depth){ | ||
depth = 2.0 * depth - 1.0; | ||
return near * far / (far + depth * (near - far)); | ||
} | ||
uniform sampler2D foam_texture; | ||
uniform float foam_intensity : hint_range(0.0, 1.0) = 0.5; | ||
uniform float foam_scale : hint_range(0.0, 10.0) = 1.0; | ||
uniform float foam_blend : hint_range(0.0, 1.0) = 0.5; | ||
uniform float foam_edge_fade : hint_range(0.0, 1.0) = 0.5; | ||
|
||
void vertex() { | ||
world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; | ||
height = texture(wave, world_pos.xz / noise_scale + wave_time * wave_speed * time_scale).r; | ||
vec3 world_pos = (MODEL_MATRIX * vec4(VERTEX.xy, 1.0, 1.0)).xyz; | ||
float height = texture(wave, world_pos.xz / noise_scale + wave_time * wave_speed * time_scale).r; | ||
VERTEX.y += height * height_scale; | ||
} | ||
|
||
void fragment() { | ||
// Depth variables and calc | ||
float depth_texture = texture(DEPTH_TEXTURE, SCREEN_UV).r * 2.0 - 1.0; | ||
float depth = PROJECTION_MATRIX[3][2] / (depth_texture + PROJECTION_MATRIX[2][2]); | ||
float depth_blend = exp((depth+VERTEX.z + depth_offset) * -beers_law); | ||
depth_blend = clamp(1.0 - depth_blend, 0.0, 1.0); | ||
float depth_blend_power = clamp(pow(depth_blend, 2.5), 0.0, 1.0); | ||
|
||
// Retrieving depth color and applying the deep and shallow colors | ||
vec3 screen_color = textureLod(SCREEN_TEXTURE, SCREEN_UV, depth_blend_power * 2.5).rgb; | ||
vec3 depth_color = mix(color_shallow.rgb, color_deep.rgb, depth_blend_power); | ||
vec3 color = mix(screen_color * depth_color, depth_color * 0.25, depth_blend_power * 0.5); | ||
|
||
// Getting edge depth calc | ||
float z_depth = edge(texture(DEPTH_TEXTURE, SCREEN_UV).x); | ||
float z_pos = edge(FRAGCOORD.z); | ||
float z_dif = z_depth - z_pos; | ||
|
||
// Time calculations for wave (normal map) movement | ||
vec2 time = (TIME * wave_direction) * time_scale; // Movement rate of first wave | ||
vec2 time2 = (TIME * wave_direction2) * time_scale; // Movement rate of second wave | ||
|
||
// Blend normal maps into one | ||
vec3 normal_blend = mix(texture(texture_normal,world_pos.xz + time).rgb, texture(texture_normal2,world_pos.xz + time2).rgb, 0.5); | ||
|
||
// Calculate Fresnel | ||
float fresnel = fresnel(5.0, NORMAL, VIEW); | ||
vec3 surface_color = mix(albedo, albedo2, fresnel); // Interpolate albedo values by frensel | ||
|
||
vec3 depth_color_adj = mix(edge_color, color, step(edge_scale, z_dif)); | ||
|
||
ALBEDO = clamp(surface_color + depth_color_adj,vec3(0.0),vec3(1.0)); | ||
METALLIC = metallic; | ||
ROUGHNESS = roughness; | ||
NORMAL_MAP = normal_blend; | ||
}" | ||
|
||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_h6xj0"] | ||
noise_type = 3 | ||
seed = 3 | ||
frequency = 0.001 | ||
fractal_type = 2 | ||
vec2 _uv = UV * 100.0 * uv_scale; | ||
|
||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_ii1dt"] | ||
seamless = true | ||
seamless_blend_skirt = 0.465 | ||
as_normal_map = true | ||
bump_strength = 4.9 | ||
noise = SubResource("FastNoiseLite_h6xj0") | ||
_uv.x += sin(TIME * time_scale + (_uv.x + _uv.y) * 25.0) / distortion_smoothing; | ||
_uv.y += cos(TIME * time_scale + (_uv.x - _uv.y) * 25.0) / distortion_smoothing; | ||
|
||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_b8lbv"] | ||
noise_type = 3 | ||
seed = 10 | ||
frequency = 0.001 | ||
fractal_type = 2 | ||
float depth_r = textureLod(DEPTH_TEXTURE, SCREEN_UV, 0.0).r; | ||
vec4 world = INV_PROJECTION_MATRIX * vec4(SCREEN_UV, depth_r, 1.0); | ||
world.xyz /= world.w; | ||
float depth_blend = smoothstep(world.z + depth_distance, world.z, VERTEX.z); | ||
vec3 screen = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb; | ||
|
||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_mq8m3"] | ||
seamless = true | ||
as_normal_map = true | ||
bump_strength = 3.1 | ||
noise = SubResource("FastNoiseLite_b8lbv") | ||
// Foam calculation with edge fading | ||
float foam_depth = 1.0 - depth_blend; | ||
vec2 foam_uv = _uv * foam_scale; | ||
foam_uv += vec2(sin(TIME), cos(TIME)) * 0.01; | ||
float foam_mask = texture(foam_texture, foam_uv).r * foam_intensity; | ||
|
||
// Calculate the edge fade based on depth | ||
float edge_fade = smoothstep(0.0, foam_edge_fade, foam_depth); | ||
|
||
foam_mask *= 1.0 - edge_fade; // Apply the edge fade to the foam | ||
foam_mask = smoothstep(0.2, 1.0, foam_mask); // Smoothing foam appearance | ||
|
||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_pg80e"] | ||
noise_type = 3 | ||
// Mix foam with the final color | ||
vec3 final_color = mix(water_color, vec3(1.0), foam_mask * foam_blend); | ||
|
||
ALBEDO = final_color * depth_blend; | ||
NORMAL_MAP = texture(wave, _uv).rgb; | ||
NORMAL *= normal_scale; | ||
ROUGHNESS *= roughness_scale; | ||
METALLIC *= metallic_scale; | ||
} | ||
" | ||
|
||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_53sse"] | ||
frequency = 0.0931 | ||
|
||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_nwgoj"] | ||
noise = SubResource("FastNoiseLite_53sse") | ||
|
||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_i5ash"] | ||
frequency = 0.002 | ||
fractal_type = 2 | ||
|
||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_xuqt8"] | ||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_0sg6a"] | ||
seamless = true | ||
noise = SubResource("FastNoiseLite_pg80e") | ||
as_normal_map = true | ||
noise = SubResource("FastNoiseLite_i5ash") | ||
|
||
[resource] | ||
render_priority = 1 | ||
shader = SubResource("Shader_ty6yi") | ||
shader_parameter/albedo = Color(0.376471, 0.603922, 1, 1) | ||
shader_parameter/albedo2 = Color(0.203922, 0.266667, 1, 1) | ||
shader_parameter/metallic = 0.0 | ||
shader_parameter/roughness = 0.02 | ||
shader_parameter/wave_direction = Vector2(2, 0) | ||
shader_parameter/wave_direction2 = Vector2(0, 1) | ||
shader_parameter/time_scale = 0.025 | ||
shader_parameter/uv_scale = 0.04 | ||
shader_parameter/normal_scale = 3.98 | ||
shader_parameter/roughness_scale = 0.005 | ||
shader_parameter/metallic_scale = 0.025 | ||
shader_parameter/time_scale = 1.0 | ||
shader_parameter/distortion_smoothing = 142.877 | ||
shader_parameter/water_color = Color(0.108915, 0.471554, 0.752786, 1) | ||
shader_parameter/depth_distance = 10.0 | ||
shader_parameter/noise_scale = 10.0 | ||
shader_parameter/height_scale = 0.135 | ||
shader_parameter/wave_speed = 2.215 | ||
shader_parameter/wave_time = 6.75 | ||
shader_parameter/color_deep = Color(0, 0, 0.65098, 1) | ||
shader_parameter/color_shallow = Color(0.321569, 0.52549, 1, 1) | ||
shader_parameter/beers_law = 2.0 | ||
shader_parameter/depth_offset = -0.75 | ||
shader_parameter/edge_scale = 0.59 | ||
shader_parameter/near = 1.0 | ||
shader_parameter/far = 100.0 | ||
shader_parameter/edge_color = Color(1, 1, 1, 1) | ||
shader_parameter/wave = SubResource("NoiseTexture2D_xuqt8") | ||
shader_parameter/texture_normal = SubResource("NoiseTexture2D_ii1dt") | ||
shader_parameter/texture_normal2 = SubResource("NoiseTexture2D_mq8m3") | ||
shader_parameter/height_scale = 0.15 | ||
shader_parameter/wave_speed = 0.01 | ||
shader_parameter/wave_time = 0.0 | ||
shader_parameter/foam_intensity = 1.0 | ||
shader_parameter/foam_scale = 0.645 | ||
shader_parameter/foam_blend = 0.358 | ||
shader_parameter/foam_edge_fade = 0.008 | ||
shader_parameter/wave = SubResource("NoiseTexture2D_0sg6a") | ||
shader_parameter/foam_texture = SubResource("NoiseTexture2D_nwgoj") |
Oops, something went wrong.