shader_type canvas_item; uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest; // 效果控制参数 uniform float fisheye_strength : hint_range(0.0, 2.0) = 1.0; uniform float curve_strength : hint_range(0.0, 2.0) = 1.0; uniform float chromatic_aberration : hint_range(0.0, 0.01) = 0.002; uniform float scanline_intensity : hint_range(0.0, 1.0) = 0.35; uniform float scanline_speed : hint_range(0.0, 10.0) = 3.5; uniform float vignette_intensity : hint_range(0.0, 1.0) = 0.3; uniform float brightness : hint_range(0.5, 10.0) = 5.0; uniform float distortion_amount : hint_range(0.0, 0.02) = 0.0017; uniform vec3 color_shift = vec3(0.95, 1.05, 0.95); // 优化后的鱼眼效果 vec2 apply_fisheye(vec2 uv) { vec2 centered = uv - 0.5; float dist = length(centered); // 避免除零和优化计算 if (dist < 0.001) return uv; // 使用更高效的鱼眼公式 float factor = 1.0 + (fisheye_strength - 1.0) * dist * dist; return 0.5 + centered * factor; } // 优化后的CRT曲线效果 vec2 apply_crt_curve(vec2 uv) { vec2 centered = (uv - 0.5) * 2.0; centered *= 1.1 * curve_strength; // 简化的曲线计算 vec2 curve_factor; curve_factor.x = 1.0 + pow(abs(centered.y) * 0.2, 2.0); curve_factor.y = 1.0 + pow(abs(centered.x) * 0.25, 2.0); centered *= curve_factor; centered = centered * 0.5 + 0.5; // 边界调整 return centered * 0.92 + 0.04; } // 优化的色差效果 vec3 sample_with_chromatic_aberration(sampler2D tex, vec2 uv, float offset) { vec3 color; color.r = texture(tex, uv + vec2(offset, 0.0)).r; color.g = texture(tex, uv).g; color.b = texture(tex, uv - vec2(offset, 0.0)).b; return color; } void fragment() { vec2 screen_uv = SCREEN_UV; // 应用畸变效果 vec2 distorted_uv = apply_fisheye(screen_uv); distorted_uv = apply_crt_curve(distorted_uv); // 边界检查(提前返回以节省计算) if (distorted_uv.x < 0.0 || distorted_uv.x > 1.0 || distorted_uv.y < 0.0 || distorted_uv.y > 1.0) { COLOR = vec4(0.0, 0.0, 0.0, 1.0); } else{ // 计算扭曲偏移 float time_factor = TIME * 0.3; float distortion = sin(time_factor + distorted_uv.y * 21.0) * sin(TIME * 0.7 + distorted_uv.y * 29.0) * sin(0.3 + TIME * 0.33 + distorted_uv.y * 31.0) * distortion_amount; // 采样并应用色差 vec2 sample_uv = distorted_uv + vec2(distortion, 0.0); vec3 color = sample_with_chromatic_aberration(screen_texture, sample_uv, chromatic_aberration); // 添加辉光效果(简化版) vec3 glow = sample_with_chromatic_aberration(screen_texture, sample_uv * 0.75, chromatic_aberration * 1.5); color += glow * 0.07; // 色彩调整 color = clamp(color * 0.6 + 0.4 * color * color, 0.0, 1.0); // 晕影效果 vec2 vignette_coord = distorted_uv * (1.0 - distorted_uv); float vignette = pow(vignette_coord.x * vignette_coord.y * 16.0, vignette_intensity); color *= vignette; // 扫描线效果 float scanline = sin(distorted_uv.y * 1.0 / SCREEN_PIXEL_SIZE.y * 1.5 + TIME * scanline_speed); scanline = clamp(scanline_intensity + scanline_intensity * scanline, 0.0, 1.0); color *= 0.4 + 0.7 * pow(scanline, 1.7); // 颜色偏移和亮度调整 color *= color_shift * brightness; // CRT像素网格效果 float pixel_mask = 1.0 - 0.65 * step(0.5, mod(FRAGCOORD.x, 2.0)); color *= pixel_mask; // 轻微的闪烁效果 color *= 1.0 + 0.01 * sin(TIME * 110.0); COLOR = vec4(color, 1.0); } }