xiandie/scene/ground/script/c03/鱼眼镜头.gdshader

43 lines
1.2 KiB
Plaintext
Raw Normal View History

2025-06-17 07:18:56 +00:00
shader_type canvas_item;
2025-07-22 11:59:08 +00:00
2025-06-17 07:18:56 +00:00
// 鱼眼效果强度控制
uniform float fish_intensity : hint_range(0.0, 2.0) = 1.0;
2025-07-22 11:59:08 +00:00
2025-06-17 07:18:56 +00:00
void fragment() {
2025-07-22 11:59:08 +00:00
// 获取纹理分辨率
vec2 iResolution = vec2(textureSize(TEXTURE, 0));
// 基础UV坐标
2025-06-17 07:18:56 +00:00
vec2 uv = UV;
// 宽高比计算
float aspectRatio = iResolution.x / iResolution.y;
// 计算强度参数
float strength = fish_intensity * 0.03;
vec2 intensity = vec2(
strength * aspectRatio,
strength * aspectRatio
);
// 坐标转换到[-1, 1]范围
2025-07-22 11:59:08 +00:00
vec2 coords = (uv - 0.5) * 2.0;
2025-06-17 07:18:56 +00:00
// 计算坐标偏移量
vec2 realCoordOffs;
realCoordOffs.x = (1.0 - coords.y * coords.y) * intensity.y * coords.x;
realCoordOffs.y = (1.0 - coords.x * coords.x) * intensity.x * coords.y;
// 应用偏移
vec2 fuv = uv - realCoordOffs;
2025-07-22 11:59:08 +00:00
2025-06-17 07:18:56 +00:00
// 边界检查
if(fuv.x < 0.0 || fuv.x > 1.0 || fuv.y < 0.0 || fuv.y > 1.0) {
2025-07-22 11:59:08 +00:00
COLOR = vec4(0.0, 0.0, 0.0, 0.0); // 超出范围显示透明
2025-06-17 07:18:56 +00:00
} else {
2025-07-22 11:59:08 +00:00
vec4 color = texture(TEXTURE, fuv);
// 应用RGB/BGR混合效果基于距离中心的距离
COLOR.rgb = mix(color.rgb, color.bgr, length(fuv - 0.5));
COLOR.a = color.a;
2025-06-17 07:18:56 +00:00
}
}