xiandie/asset/shader/fog.gdshader

19 lines
938 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;
// 数字越小(越接近 0越黑范围在 0-1 之间
uniform float grey_level = 0.6;
uniform float speed = 1.;
void fragment() {
float delta = TIME * .004 * speed;
float fog_alpha_1 = texture(noise, vec2(UV.x + delta * 7., UV.y + delta * 2.)).r;
float fog_alpha_2 = texture(noise, vec2(UV.x + 0.5 + delta * 4., UV.y + 0.5 - delta)).r;
float fog_alpha_3 = texture(noise, vec2(UV.x + 0.25 + delta, UV.y - 0.25 + delta * 3.)).r;
float fog_alpha = mix(fog_alpha_3, mix(fog_alpha_1, fog_alpha_2, 0.5), 0.66);
// factor 越靠近 1 fog_alpha 也靠近 1 factor 越靠近 0.fog_alpha 越靠近自己
COLOR.a = mix(fog_alpha, 1., COLOR.a * COLOR.a) * smoothstep(.0, .2, COLOR.a);
COLOR.rgb *= mix(grey_level, 1., fog_alpha);
}