Skip to content

Commit

Permalink
refactor: update the sky shaders (#4)
Browse files Browse the repository at this point in the history
* refactor: update the sky shaders

* chore: add entry in changelog
  • Loading branch information
florianvazelle authored Jan 13, 2024
1 parent 5694973 commit 9c7e43a
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 21 deletions.
11 changes: 5 additions & 6 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ Copyright: 2023-present Hugo Locurcio and contributors
License: MIT
Source: https://github.com/godot-extended-libraries/godot-debug-menu

Files: addons/gpsx/*
Copyright: 2021 Uneven Prankster
License: MIT
Source: https://github.com/GithubPrankster/gpsx

Files: addons/goat/*
Copyright: 2019-2020 Miskatonic Studio
License: MIT
Expand Down Expand Up @@ -156,9 +151,13 @@ Copyright: 2010 qubodup
License: CC0-1.0
Source: https://opengameart.org/content/door-open-door-close-set


# Shaders

Files: shaders/panoramic_textured_sky_with_clouds.gdshader
Copyright: 2023 Gyrth
License: CC0-1.0
Source: https://godotshaders.com/shader/panoramic-textured-sky-with-clouds/

Files: shaders/psx_model.gdshader
Copyright: 2023 Grau
License: CC0-1.0
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Added
### Changed
- Optimize images via ImgBot [#1](https://github.com/MechanicalFlower/HazyRoad/pull/1)
- Update sky shader to add clouds [#4](https://github.com/MechanicalFlower/HazyRoad/pull/4)
### Deprecated
### Removed
### Fixed
Expand Down
6 changes: 0 additions & 6 deletions plug.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ func _plugging():
"include": ["addons/goat/images"]
}
)
plug("GithubPrankster/gpsx", {
"commit": "64b1c5f83daa4df3c714a65a8fd2f1294575dce3",
"install_root": "addons/gpsx",
"include": ["example/materials/shaders"]
}
)
plug("samclee/EZ-Sfx-and-Music", {"commit": "ac2b77c0336ff6edf6b26aa9342628d2ad63f359"})
plug("HolonProduction/godot_kanban_tasks", {
"commit": "cfc914caa1dabd085024ff196bcb8578eaee1e67",
Expand Down
40 changes: 31 additions & 9 deletions resources/fog_env.tres
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
[gd_resource type="Environment" load_steps=5 format=3 uid="uid://dtgnbg8pmfbjy"]
[gd_resource type="Environment" load_steps=7 format=3 uid="uid://dtgnbg8pmfbjy"]

[ext_resource type="Shader" path="res://addons/gpsx/example/materials/shaders/misc/gpsx_sky.gdshader" id="1_g6wkn"]
[ext_resource type="Texture2D" uid="uid://dxmmrih8af3qb" path="res://assets/textures/nightsky.hdr" id="2_6xap7"]
[ext_resource type="Shader" path="res://shaders/panoramic_textured_sky_with_clouds.gdshader" id="1_akepw"]
[ext_resource type="Texture2D" uid="uid://dxmmrih8af3qb" path="res://assets/textures/nightsky.hdr" id="2_711um"]

[sub_resource type="FastNoiseLite" id="FastNoiseLite_vqi2a"]
noise_type = 4
frequency = 0.05
fractal_type = 3
fractal_gain = 0.0

[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_l5wex"]
width = 128
height = 128
generate_mipmaps = false
seamless = true
noise = SubResource("FastNoiseLite_vqi2a")

[sub_resource type="ShaderMaterial" id="ShaderMaterial_mvojt"]
shader = ExtResource("1_g6wkn")
shader_parameter/mixer = Color(0.290196, 0.282353, 1, 1)
shader_parameter/tex = ExtResource("2_6xap7")
shader_parameter/dithering = true
shader_parameter/banding = true
shader = ExtResource("1_akepw")
shader_parameter/add_clouds = true
shader_parameter/clouds_below = false
shader_parameter/cloud_scale = 0.25
shader_parameter/speed = 0.002
shader_parameter/cloud_dark = 0.5
shader_parameter/cloud_light = 0.3
shader_parameter/cloud_cover = 0.2
shader_parameter/cloud_alpha = 8.0
shader_parameter/sky_tint = 0.5
shader_parameter/height_offset = 0.0
shader_parameter/sky_contribution = 0.5
shader_parameter/source_panorama = ExtResource("2_711um")
shader_parameter/noise_texture = SubResource("NoiseTexture2D_l5wex")

[sub_resource type="Sky" id="Sky_85p4l"]
sky_material = SubResource("ShaderMaterial_mvojt")
Expand All @@ -19,11 +41,11 @@ sky = SubResource("Sky_85p4l")
ambient_light_source = 3
ambient_light_color = Color(0.388235, 0, 0.392157, 1)
ambient_light_energy = 16.0
tonemap_mode = 2
glow_intensity = 2.0
glow_bloom = 1.0
fog_enabled = true
fog_light_color = Color(0.0117647, 0, 0.239216, 1)
fog_light_energy = 0.5
fog_sky_affect = 0.75
volumetric_fog_emission = Color(0.0352941, 0.0352941, 0.0352941, 1)
volumetric_fog_sky_affect = 0.3
109 changes: 109 additions & 0 deletions shaders/panoramic_textured_sky_with_clouds.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
shader_type sky;

render_mode use_half_res_pass;

uniform sampler2D source_panorama : filter_linear,
source_color,
hint_default_black;
uniform bool add_clouds = true;
uniform bool clouds_below = false;
uniform float cloud_scale : hint_range(0.0, 1.0, 0.01) = 0.25;
uniform float speed : hint_range(0.0, 0.25, 0.001) = 0.002;
uniform float cloud_dark : hint_range(0.0, 1.0, 0.01) = 0.5;
uniform float cloud_light : hint_range(0.0, 1.0, 0.01) = 0.3;
uniform float cloud_cover : hint_range(0.0, 1.0, 0.01) = 0.2;
uniform float cloud_alpha : hint_range(0.0, 10.0, 0.01) = 8.0;
uniform float sky_tint : hint_range(0.0, 1.0, 0.001) = 0.5;
uniform float height_offset : hint_range(0.0, 1.0, 0.001) = 0.2;
uniform float sky_contribution : hint_range(0.0, 1.0, 0.1) = 0.5;
uniform sampler2D noise_texture : filter_linear,
source_color,
hint_default_black;

const mat2 m = mat2(vec2(1.6, 1.2), vec2(-1.2, 1.6));

vec2 hash(vec2 p) {
p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));
return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
}

float noise(in vec2 p) { return texture(noise_texture, p).r; }

float fbm(vec2 n) {
float total = 0.0, amplitude = 0.1;
total += noise(n) * amplitude;
n = m * n;
amplitude *= 0.4;
return total;
}

void sky() {
COLOR = texture(source_panorama, SKY_COORDS).rgb;
if (AT_CUBEMAP_PASS) {
COLOR *= sky_contribution;
} else if (add_clouds) {
vec3 normal = normalize(EYEDIR);
vec3 plane_intersect = normal / (normal.y + height_offset);

if (clouds_below) {
plane_intersect = normal / -(normal.y - height_offset);
}

vec2 p = plane_intersect.xz;
p.y *= -1.0;
vec2 uv = p;

float time = TIME * speed;
float q = fbm(uv * cloud_scale * 0.5);

// ridged noise shape
float r = 0.0;
uv *= cloud_scale;
uv -= q - time;
float weight = 0.8;
r += abs(weight * noise(uv));
uv = m * uv + time;
weight *= 0.7;

// noise shape
float f = 0.0;
uv = p;
uv *= cloud_scale;
uv -= q - time;
weight = 0.7;
f += weight * noise(uv);
uv = m * uv + time;
weight *= 0.6;

f *= r + f;

// noise colour
float c = 0.0;
time = TIME * speed * 2.0;
uv = p;
uv *= cloud_scale * 2.0;
uv -= q - time;
weight = 0.4;
c += weight * noise(uv);
uv = m * uv + time;
weight *= 0.6;

vec3 skycolour = COLOR;
vec3 cloudcolour =
vec3(1.1, 1.1, 0.9) * clamp((cloud_dark + cloud_light * c), 0.0, 1.0);
float horizon_fall_off = max(normal.y, 0.0);

if (clouds_below) {
horizon_fall_off = max(-normal.y, 0.0);
}

f = cloud_cover + cloud_alpha * f * r;

vec3 result =
mix(skycolour, clamp(sky_tint * skycolour + cloudcolour, 0.0, 1.0),
clamp(f + c, 0.0, 1.0) * horizon_fall_off);

// Convert the color to black and white.
COLOR = vec3((result.r + result.g + result.b) / 3.0);
}
}

0 comments on commit 9c7e43a

Please sign in to comment.