xiandie/asset/shader/fog.gdshader

18 lines
975 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// fog.shader 构造 fog 效果
// noise 为配置好的噪音取样纹理
// texture 为蒙版 mask用于控制雾气浓度
shader_type canvas_item;
uniform sampler2D noise: repeat_enable;
void fragment() {
float fog_alpha_1 = texture(noise, vec2(UV.x / 2.0 + TIME /100.0, UV.y / 4.0 - TIME / 100.0)).r;
float fog_alpha_2 = texture(noise, vec2(UV.x / 2.0 + 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 + 0.25 + TIME /25.0, UV.y / 4.0 - 0.25 - TIME / 160.0)).r;
float fog_alpha = mix(fog_alpha_3, mix(fog_alpha_1, fog_alpha_2, 0.5), 0.7);
// COLOR.a 越接近 1.0 factor 越接近 1.0COLOR.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;
}