FunGame-Godot/scenes/第一章.gdshader
2026-02-03 01:38:51 +08:00

22 lines
772 B
Plaintext
Raw Permalink 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.

shader_type canvas_item;
// 获取屏幕内容注意Godot 4 必须写这个提示符)
uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap;
// 模糊强度
uniform float blur_amount : hint_range(0.0, 5.0) = 0.0;
// 边缘硬度
uniform float vignette_softness : hint_range(0.0, 1.0) = 0.5;
void fragment() {
// 1. 计算当前像素距离中心点的距离
float dist = distance(UV, vec2(0.5));
// 2. 根据距离计算权重中心为0四周渐变为1
float mask = smoothstep(0.2, vignette_softness + 0.5, dist);
// 3. 采样屏幕图像,根据权重决定该像素的模糊程度
vec4 screen_color = textureLod(screen_texture, SCREEN_UV, mask * blur_amount);
COLOR = screen_color;
}