Updated shader and fixed PNG output
This commit is contained in:
@@ -49,7 +49,7 @@ float normalizedFisheyeRadius(float theta, float halfFov)
|
||||
|
||||
float3 equirectangularRay(float2 uv)
|
||||
{
|
||||
float longitude = (uv.x - 0.5) * TWO_PI + radiansFromDegrees(seamAngleDegrees);
|
||||
float longitude = (uv.x - 0.5) * TWO_PI;
|
||||
float latitude = (0.5 - uv.y) * PI;
|
||||
float latitudeCos = cos(latitude);
|
||||
|
||||
@@ -60,6 +60,39 @@ float3 equirectangularRay(float2 uv)
|
||||
));
|
||||
}
|
||||
|
||||
float sourceUvOutsideDistance(float2 uv)
|
||||
{
|
||||
float2 lower = max(-uv, float2(0.0, 0.0));
|
||||
float2 upper = max(uv - 1.0, float2(0.0, 0.0));
|
||||
return max(max(lower.x, lower.y), max(upper.x, upper.y));
|
||||
}
|
||||
|
||||
float4 sampleEdgeFilledVideo(float2 sourceUv, ShaderContext context)
|
||||
{
|
||||
float outsideDistance = sourceUvOutsideDistance(sourceUv);
|
||||
if (outsideDistance <= 0.0)
|
||||
return sampleVideo(sourceUv);
|
||||
|
||||
float fillDistance = max(edgeFill, 0.0);
|
||||
if (outsideDistance > fillDistance)
|
||||
return outsideColor;
|
||||
|
||||
float2 clampedUv = saturate(sourceUv);
|
||||
float2 inward = clampedUv - sourceUv;
|
||||
float inwardLength = max(length(inward), 0.000001);
|
||||
inward /= inwardLength;
|
||||
|
||||
float blurDistance = max(edgeBlur, 0.0);
|
||||
float4 color = sampleVideo(clampedUv) * 0.32;
|
||||
color += sampleVideo(saturate(clampedUv + inward * blurDistance * 0.35)) * 0.26;
|
||||
color += sampleVideo(saturate(clampedUv + inward * blurDistance * 0.75)) * 0.20;
|
||||
color += sampleVideo(saturate(clampedUv + inward * blurDistance * 1.20)) * 0.14;
|
||||
color += sampleVideo(saturate(clampedUv + inward * blurDistance * 1.75)) * 0.08;
|
||||
|
||||
float edgeFade = smoothstep(fillDistance * 0.78, fillDistance, outsideDistance);
|
||||
return lerp(color, outsideColor, edgeFade);
|
||||
}
|
||||
|
||||
float4 shadeVideo(ShaderContext context)
|
||||
{
|
||||
float3 ray = equirectangularRay(context.uv);
|
||||
@@ -86,8 +119,9 @@ float4 shadeVideo(ShaderContext context)
|
||||
center.y - sin(phi) * fisheyeRadius * radius.y
|
||||
);
|
||||
|
||||
if (sourceUv.x < 0.0 || sourceUv.x > 1.0 || sourceUv.y < 0.0 || sourceUv.y > 1.0)
|
||||
float2 guard = 0.5 / max(context.inputResolution, float2(1.0, 1.0));
|
||||
if (edgeFill <= 0.0 && (sourceUv.x < -guard.x || sourceUv.x > 1.0 + guard.x || sourceUv.y < -guard.y || sourceUv.y > 1.0 + guard.y))
|
||||
return outsideColor;
|
||||
|
||||
return sampleVideo(sourceUv);
|
||||
return sampleEdgeFilledVideo(sourceUv, context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user