Skip to content

Commit

Permalink
feat: apply wind settings to clouds
Browse files Browse the repository at this point in the history
Changes in the cloud shader were necessary; texture reads are multiplied with a wind-direction

Refs: #312
  • Loading branch information
Mathias Baumgartinger~ committed Aug 8, 2023
1 parent 187d26e commit ce2f372
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 2 additions & 0 deletions World/Environment/WorldEnvironment.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions World/Environment/WorldEnvironment.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions addons/clouds/clouds.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -141,16 +142,15 @@ 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);
float base_cloud = remap(n.r, -(1.0-fbm), 1.0, 0.0, 1.0);
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));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ce2f372

Please sign in to comment.