Example shaders
This commit is contained in:
57
shaders/safe-area-guides/shader.json
Normal file
57
shaders/safe-area-guides/shader.json
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"id": "safe-area-guides",
|
||||
"name": "Safe Area Guides",
|
||||
"description": "Overlays broadcast action/title safe guides plus optional center marks and aspect matte.",
|
||||
"category": "Utility",
|
||||
"entryPoint": "shadeVideo",
|
||||
"parameters": [
|
||||
{ "id": "showActionSafe", "label": "Action Safe", "type": "bool", "default": true },
|
||||
{ "id": "showTitleSafe", "label": "Title Safe", "type": "bool", "default": true },
|
||||
{ "id": "showCenter", "label": "Center Marks", "type": "bool", "default": true },
|
||||
{
|
||||
"id": "lineColor",
|
||||
"label": "Line Color",
|
||||
"type": "color",
|
||||
"default": [1.0, 1.0, 1.0, 1.0]
|
||||
},
|
||||
{
|
||||
"id": "lineOpacity",
|
||||
"label": "Line Opacity",
|
||||
"type": "float",
|
||||
"default": 0.65,
|
||||
"min": 0.0,
|
||||
"max": 1.0,
|
||||
"step": 0.01
|
||||
},
|
||||
{
|
||||
"id": "lineThicknessPixels",
|
||||
"label": "Line Thickness",
|
||||
"type": "float",
|
||||
"default": 2.0,
|
||||
"min": 0.5,
|
||||
"max": 12.0,
|
||||
"step": 0.1
|
||||
},
|
||||
{
|
||||
"id": "aspectMode",
|
||||
"label": "Aspect Matte",
|
||||
"type": "enum",
|
||||
"default": "none",
|
||||
"options": [
|
||||
{ "value": "none", "label": "None" },
|
||||
{ "value": "239", "label": "2.39:1" },
|
||||
{ "value": "185", "label": "1.85:1" },
|
||||
{ "value": "square", "label": "1:1" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "matteOpacity",
|
||||
"label": "Matte Opacity",
|
||||
"type": "float",
|
||||
"default": 0.35,
|
||||
"min": 0.0,
|
||||
"max": 1.0,
|
||||
"step": 0.01
|
||||
}
|
||||
]
|
||||
}
|
||||
58
shaders/safe-area-guides/shader.slang
Normal file
58
shaders/safe-area-guides/shader.slang
Normal file
@@ -0,0 +1,58 @@
|
||||
float edgeLine(float value, float target, float pixels, float resolution)
|
||||
{
|
||||
float halfWidth = max(pixels, 0.5) * 0.5 / max(resolution, 1.0);
|
||||
return 1.0 - smoothstep(halfWidth, halfWidth * 2.0, abs(value - target));
|
||||
}
|
||||
|
||||
float rectGuide(float2 uv, float2 inset, float2 resolution)
|
||||
{
|
||||
float mask = 0.0;
|
||||
float thickness = max(lineThicknessPixels, 0.5);
|
||||
if (uv.x >= inset.x && uv.x <= 1.0 - inset.x && uv.y >= inset.y && uv.y <= 1.0 - inset.y)
|
||||
{
|
||||
mask = max(mask, edgeLine(uv.x, inset.x, thickness, resolution.x));
|
||||
mask = max(mask, edgeLine(uv.x, 1.0 - inset.x, thickness, resolution.x));
|
||||
mask = max(mask, edgeLine(uv.y, inset.y, thickness, resolution.y));
|
||||
mask = max(mask, edgeLine(uv.y, 1.0 - inset.y, thickness, resolution.y));
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
float aspectMatte(float2 uv, float2 resolution)
|
||||
{
|
||||
if (aspectMode == 0)
|
||||
return 0.0;
|
||||
|
||||
float targetAspect = aspectMode == 1 ? 2.39 : (aspectMode == 2 ? 1.85 : 1.0);
|
||||
float frameAspect = resolution.x / max(resolution.y, 1.0);
|
||||
if (frameAspect <= targetAspect)
|
||||
{
|
||||
float contentHeight = frameAspect / targetAspect;
|
||||
float inset = (1.0 - contentHeight) * 0.5;
|
||||
return (uv.y < inset || uv.y > 1.0 - inset) ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
float contentWidth = targetAspect / frameAspect;
|
||||
float inset = (1.0 - contentWidth) * 0.5;
|
||||
return (uv.x < inset || uv.x > 1.0 - inset) ? 1.0 : 0.0;
|
||||
}
|
||||
|
||||
float4 shadeVideo(ShaderContext context)
|
||||
{
|
||||
float2 resolution = max(context.outputResolution, float2(1.0, 1.0));
|
||||
float3 color = lerp(context.sourceColor.rgb, float3(0.0, 0.0, 0.0), aspectMatte(context.uv, resolution) * saturate(matteOpacity));
|
||||
|
||||
float mask = 0.0;
|
||||
if (showActionSafe)
|
||||
mask = max(mask, rectGuide(context.uv, float2(0.05, 0.05), resolution));
|
||||
if (showTitleSafe)
|
||||
mask = max(mask, rectGuide(context.uv, float2(0.10, 0.10), resolution));
|
||||
if (showCenter)
|
||||
{
|
||||
mask = max(mask, edgeLine(context.uv.x, 0.5, lineThicknessPixels, resolution.x) * step(abs(context.uv.y - 0.5), 0.035));
|
||||
mask = max(mask, edgeLine(context.uv.y, 0.5, lineThicknessPixels, resolution.y) * step(abs(context.uv.x - 0.5), 0.035));
|
||||
}
|
||||
|
||||
float opacity = mask * saturate(lineOpacity) * lineColor.a;
|
||||
return float4(lerp(color, lineColor.rgb, opacity), context.sourceColor.a);
|
||||
}
|
||||
Reference in New Issue
Block a user