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

43 lines
1.2 KiB
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.

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