add cloud shadow - godrays
This commit is contained in:
62
Shaders/godrays.gdshader
Normal file
62
Shaders/godrays.gdshader
Normal file
@@ -0,0 +1,62 @@
|
||||
shader_type spatial;
|
||||
|
||||
// RENDER MODE ESSENZIALI PER EFFETTI LUCE
|
||||
// blend_add: Somma i colori, perfetto per la luce pura.
|
||||
// unshaded: Non riceve ombre, è lui che illumina.
|
||||
// depth_draw_never: Non blocca gli oggetti dietro, evita artefatti.
|
||||
// cull_disabled: Visibile da entrambi i lati.
|
||||
render_mode blend_add, depth_draw_never, cull_disabled, unshaded;
|
||||
|
||||
uniform sampler2D depth_texture : hint_depth_texture, filter_nearest;
|
||||
uniform sampler2D noise_texture : repeat_enable, filter_linear;
|
||||
|
||||
uniform vec3 ray_color : source_color = vec3(1.0, 0.9, 0.7);
|
||||
uniform float base_alpha : hint_range(0.0, 1.0) = 0.5;
|
||||
|
||||
group_uniforms Noise_Stirato;
|
||||
// --- I PARAMETRI CHE CERCAVI ---
|
||||
uniform float noise_stretching : hint_range(1.0, 50.0) = 20.0; // Quanto allungare il noise
|
||||
uniform float noise_scale : hint_range(0.1, 10.0) = 1.0; // Grandezza generale
|
||||
uniform vec2 scrolling_speed = vec2(0.0, -0.1); // Velocità e direzione del movimento (Y negativa va in giù)
|
||||
|
||||
group_uniforms Fades;
|
||||
uniform float depth_softness = 1.0; // Ammorbidisce il contatto con terreno/alberi
|
||||
uniform float edge_fade_power = 2.0; // Sfuma i bordi laterali del piano
|
||||
|
||||
// --- IL PARAMETRO PER LO SCRIPT ---
|
||||
uniform float intensity_multiplier : hint_range(0.0, 1.0) = 0.0;
|
||||
|
||||
void fragment() {
|
||||
// 1. LA MAGIA DEL NOISE STIRATO E IN MOVIMENTO
|
||||
// Prendiamo le coordinate UV standard
|
||||
vec2 stretchy_uv = UV * noise_scale;
|
||||
|
||||
// STIRAMENTO: Moltiplichiamo X per allungare il noise in verticale
|
||||
stretchy_uv.x *= noise_stretching;
|
||||
|
||||
// MOVIMENTO: Aggiungiamo il tempo moltiplicato per la velocità
|
||||
stretchy_uv += TIME * scrolling_speed;
|
||||
|
||||
// Leggiamo il noise (basta un canale perché è in bianco e nero)
|
||||
float noise = texture(noise_texture, stretchy_uv).r;
|
||||
|
||||
// 2. SISTEMA DI DISSOLVENZE (FADES) PER NASCONDERE IL PIANO
|
||||
// A. Soft Intersection: Legge la profondità per sfumare il contatto con gli oggetti
|
||||
float depth = textureLod(depth_texture, SCREEN_UV, 0.0).r;
|
||||
vec4 upos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, depth, 1.0);
|
||||
vec3 pixel_position = upos.xyz / upos.w;
|
||||
float depth_fade = clamp((VERTEX.z - pixel_position.z) / depth_softness, 0.0, 1.0);
|
||||
|
||||
// B. Edge Fade: Sfuma orizzontalmente (UV.x) per non avere bordi netti ai lati del piano
|
||||
float edge_fade = smoothstep(0.0, 0.5, UV.x) * smoothstep(1.0, 0.5, UV.x);
|
||||
edge_fade = pow(edge_fade, edge_fade_power); // Rende la sfumatura più o meno aggressiva
|
||||
|
||||
// C. Vertical Fade: Sfuma verticalmente (UV.y) per far sparire la base nel nulla
|
||||
float vertical_fade = smoothstep(0.0, 0.2, UV.y) * smoothstep(1.0, 0.7, UV.y);
|
||||
|
||||
// 3. COMPOSIZIONE FINALE
|
||||
ALBEDO = ray_color;
|
||||
|
||||
// Combiniamo tutte le sfumature con il noise e il moltiplicatore dello script
|
||||
ALPHA = noise * base_alpha * depth_fade * edge_fade * vertical_fade * intensity_multiplier;
|
||||
}
|
||||
Reference in New Issue
Block a user