From ce2f37211ff757f0fd8d1968eda9518b9b193a34 Mon Sep 17 00:00:00 2001 From: Mathias Baumgartinger~ Date: Tue, 8 Aug 2023 18:33:37 +0200 Subject: [PATCH] feat: apply wind settings to clouds Changes in the cloud shader were necessary; texture reads are multiplied with a wind-direction Refs: #312 --- World/Environment/WorldEnvironment.gd | 2 ++ World/Environment/WorldEnvironment.tscn | 8 ++++---- addons/clouds/clouds.gdshader | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/World/Environment/WorldEnvironment.gd b/World/Environment/WorldEnvironment.gd index cf84d67a..e85a4fed 100644 --- a/World/Environment/WorldEnvironment.gd +++ b/World/Environment/WorldEnvironment.gd @@ -58,6 +58,8 @@ func apply_wind_direction(new_wind_direction): func apply_wind(): var rotated_vector = Vector2.UP.rotated(deg_to_rad(wind_direction)) + environment.sky.get_material().set_shader_parameter("_time_scale", remap(wind_speed, 0, 50, 0, 20)) + environment.sky.get_material().set_shader_parameter("wind_direction", -rotated_vector) $Rain.wind_direction = Vector3(rotated_vector.x, -1, rotated_vector.y) $Rain.wind_speed = wind_speed diff --git a/World/Environment/WorldEnvironment.tscn b/World/Environment/WorldEnvironment.tscn index c70b0343..8cf622d3 100644 --- a/World/Environment/WorldEnvironment.tscn +++ b/World/Environment/WorldEnvironment.tscn @@ -10,10 +10,10 @@ [sub_resource type="ShaderMaterial" id="ShaderMaterial_ywyjs"] shader = ExtResource("1_p31xn") -shader_parameter/wind_direction = Vector2(1, 0) -shader_parameter/_density = 0.137 -shader_parameter/cloud_coverage = 0.461 -shader_parameter/_time_scale = 1.0 +shader_parameter/wind_direction = Vector2(1, 1) +shader_parameter/_density = 0.2 +shader_parameter/cloud_coverage = 0.32 +shader_parameter/_time_scale = 20.0 shader_parameter/_time_offset = 0.0 shader_parameter/rayleigh = 2.0 shader_parameter/rayleigh_color = Color(0.26, 0.41, 0.58, 1) diff --git a/addons/clouds/clouds.gdshader b/addons/clouds/clouds.gdshader index 289337b9..d9f02f2f 100644 --- a/addons/clouds/clouds.gdshader +++ b/addons/clouds/clouds.gdshader @@ -7,7 +7,8 @@ uniform sampler3D worlnoise : filter_linear_mipmap, repeat_enable; uniform sampler3D perlworlnoise : filter_linear_mipmap, repeat_enable; uniform sampler2D weathermap : filter_linear_mipmap, repeat_enable; -uniform float _density : hint_range(0.01, 0.2) = 0.05; +uniform vec2 wind_direction = vec2(1, 0); +uniform float _density : hint_range(0.05, 0.2) = 0.05; uniform float cloud_coverage :hint_range(0.1, 1.0) = 0.25; uniform float _time_scale :hint_range(0.0, 20.0) = 1.0; uniform float _time_offset : hint_range(0.0, 1000.0, 0.5) = 0.0; @@ -141,8 +142,8 @@ float intersectSphere(vec3 pos, vec3 dir,float r) { float density(vec3 pip, vec3 weather, float mip) { float time = TIME * _time_scale; vec3 p = pip; - p.x += time * 10.0 + _time_offset; float height_fraction = GetHeightFractionForPoint(length(p)); + p.xz += time * 20.0 * normalize(wind_direction) * 0.6; vec4 n = textureLod(perlworlnoise, p.xyz*0.00008, mip-2.0); float fbm = n.g*0.625+n.b*0.25+n.a*0.125; float g = densityHeightGradient(height_fraction, weather.r); @@ -150,7 +151,6 @@ float density(vec3 pip, vec3 weather, float mip) { float weather_coverage = cloud_coverage*weather.b; base_cloud = remap(base_cloud*g, 1.0-(weather_coverage), 1.0, 0.0, 1.0); base_cloud *= weather_coverage; - p.xy -= time * 20.0; vec3 hn = textureLod(worlnoise, p*0.001, mip).rgb; float hfbm = hn.r*0.625+hn.g*0.25+hn.b*0.125; hfbm = mix(hfbm, 1.0-hfbm, clamp(height_fraction*4.0, 0.0, 1.0)); @@ -181,8 +181,8 @@ vec4 march(vec3 pos, vec3 end, vec3 dir, int depth) { vec3 atmosphere_ground = atmosphere(normalize(vec3(1.0, -1.0, 0.0))); const float weather_scale = 0.00006; - float time = TIME * 0.003 * _time_scale + 0.005*_time_offset; - vec2 weather_pos = vec2(time * 0.9, time); + float time = TIME * 0.001 * _time_scale + 0.005 * _time_offset; + vec2 weather_pos = time * normalize(wind_direction); for (int i = 0; i < depth; i++) { p += dir * ss;