2025-02-01 06:44:12 +00:00
|
|
|
|
// fog.shader 构造 fog 效果
|
|
|
|
|
// noise 为配置好的噪音取样纹理
|
|
|
|
|
// texture 为蒙版 mask,用于控制雾气浓度
|
2024-12-23 01:31:10 +00:00
|
|
|
|
shader_type canvas_item;
|
2025-01-26 13:11:38 +00:00
|
|
|
|
uniform sampler2D noise: repeat_enable;
|
2025-02-04 13:30:43 +00:00
|
|
|
|
// x / y
|
|
|
|
|
uniform float ratio = 1.2;
|
|
|
|
|
// 数字越小(越接近 0)越黑,范围在 0-1 之间
|
|
|
|
|
uniform float grey_level = 0.6;
|
2024-12-23 01:31:10 +00:00
|
|
|
|
|
|
|
|
|
void fragment() {
|
2025-02-04 13:30:43 +00:00
|
|
|
|
float fog_alpha_1 = texture(noise, vec2(UV.x / 2.0 * ratio + TIME /100.0, UV.y / 4.0 - TIME / 100.0)).r;
|
|
|
|
|
float fog_alpha_2 = texture(noise, vec2(UV.x / 2.0 * ratio + 0.5 + TIME /50.0, UV.y / 4.0 + 0.5 - TIME / 160.0)).r;
|
|
|
|
|
float fog_alpha_3 = texture(noise, vec2(UV.x / 2.0 * ratio + 0.25 + TIME /25.0, UV.y / 4.0 - 0.25 - TIME / 160.0)).r;
|
2025-01-26 13:11:38 +00:00
|
|
|
|
float fog_alpha = mix(fog_alpha_3, mix(fog_alpha_1, fog_alpha_2, 0.5), 0.7);
|
2025-02-01 06:44:12 +00:00
|
|
|
|
// COLOR.a 越接近 1.0, factor 越接近 1.0;COLOR.a 越接近 0.0, factor 越接近 0.0
|
|
|
|
|
float factor = pow(COLOR.a, 2);
|
|
|
|
|
float strength = smoothstep(.0, .2, COLOR.a);
|
|
|
|
|
// factor 越靠近 1, fog_alpha 也靠近 1; factor 越靠近 0.,fog_alpha 越靠近自己
|
|
|
|
|
//COLOR.a = mix(fog_alpha, 1., factor);
|
|
|
|
|
COLOR.a = mix(fog_alpha, 1., factor) * strength;
|
2025-02-04 13:30:43 +00:00
|
|
|
|
COLOR.rgb = vec3(mix(grey_level, 1., mix(fog_alpha_1, fog_alpha_3, 0.4)));
|
2025-01-03 13:29:22 +00:00
|
|
|
|
}
|