From 453eda75bbb56f6c4b70033227899653c4215af1 Mon Sep 17 00:00:00 2001 From: florianvazelle Date: Wed, 3 Jan 2024 18:39:10 +0100 Subject: [PATCH] refactor: update the sky shaders --- .reuse/dep5 | 11 +- plug.gd | 6 - resources/fog_env.tres | 40 +++++-- ...anoramic_textured_sky_with_clouds.gdshader | 109 ++++++++++++++++++ 4 files changed, 145 insertions(+), 21 deletions(-) create mode 100644 shaders/panoramic_textured_sky_with_clouds.gdshader diff --git a/.reuse/dep5 b/.reuse/dep5 index 1e399c3..ff2903b 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -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 @@ -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 diff --git a/plug.gd b/plug.gd index 36543ec..041d4df 100644 --- a/plug.gd +++ b/plug.gd @@ -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", diff --git a/resources/fog_env.tres b/resources/fog_env.tres index a97e737..eac3ebd 100644 --- a/resources/fog_env.tres +++ b/resources/fog_env.tres @@ -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") @@ -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 diff --git a/shaders/panoramic_textured_sky_with_clouds.gdshader b/shaders/panoramic_textured_sky_with_clouds.gdshader new file mode 100644 index 0000000..5d1c725 --- /dev/null +++ b/shaders/panoramic_textured_sky_with_clouds.gdshader @@ -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); + } +}