Files
VCCPlusOSS/platforms/macos/App/DisplayShader.txt
T

23 lines
1.4 KiB
Plaintext

// SPDX-License-Identifier: GPL-3.0-or-later
#include <metal_stdlib>
using namespace metal;
struct RasterVertex { float4 position [[position]]; float2 uv; };
vertex RasterVertex vccVertex(uint index [[vertex_id]]) {
const float2 positions[] = {float2(-1,-1), float2(3,-1), float2(-1,3)};
const float2 coords[] = {float2(0,1), float2(2,1), float2(0,-1)};
return {float4(positions[index],0,1), coords[index]};
}
fragment float4 vccFragment(RasterVertex input [[stage_in]], texture2d<float> frame [[texture(0)]], constant float4& region [[buffer(0)]], constant float2& effects [[buffer(1)]]) {
constexpr sampler nearest(coord::normalized, address::clamp_to_edge, filter::nearest);
// Fractional viewport edges can cover a fragment center just outside the
// picture. Clamp to active texel centers so no guest-border pixel leaks in.
const float2 halfTexel = 0.5 / float2(frame.get_width(), frame.get_height());
const float2 uv = clamp(region.xy + input.uv * region.zw,
region.xy + halfTexel, region.xy + region.zw - halfTexel);
constexpr sampler smooth(coord::normalized, address::clamp_to_edge, filter::linear);
float3 color = effects.x > 0.5 ? frame.sample(smooth, uv).rgb : frame.sample(nearest, uv).rgb;
const uint row = uint(floor((uv.y - region.y) * frame.get_height()));
if (row & 1) color *= 1.0 - effects.y;
return float4(color, 1.0);
}