22 lines
772 B
Plaintext
22 lines
772 B
Plaintext
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;
|
||
}
|