Shader format
ShaderMania shaders are Metal fragment-style programs. Each shader provides a mainImage function that receives a mutable Data structure.
void mainImage(thread Data &data)
{
float2 uv = data.uv;
data.outColor = float4(uv.x, uv.y, 0.0, 1.0);
}
Incoming data
typedef struct
{
float2 uv; // UV coordinate 0..1
float2 viewSize; // Viewport size
float2 fragCoord; // uv * viewSize
float time; // Global time in seconds
unsigned int frame; // Frame number
float4 outColor; // Resulting RGBA color, default (0,0,0,1)
texture2d<float> slot0; // Texture input slots
texture2d<float> slot1;
texture2d<float> slot2;
texture2d<float> slot3;
} Data;
Write the final shader color to data.outColor.
UI parameters
Parameter declarations create editable controls in ShaderMania. Parameter values are stored with the shader and reset when the parameter name changes. Up to 10 parameters per shader are supported.
Float slider
float size = ParamFloat<UI: "Slider", name: "Size", min: 0, max: 1, default: 0.8>
Color picker
float3 diskColor = ParamFloat3<UI: "Color", name: "Disk Color", default: #ffffff>
URL button
ShaderMania adds https:// automatically.
ParamUrl<name: "Watch Tutorial", url: "example.com/tutorial">
Texture inputs
Shaders can declare up to 4 named input slots.
texture2d<float> input = ParamInput<name: "Input Slot Name">
Sample from texture inputs with the provided helpers:
getLinearSample(texture2d<float>, float2 coord);
getNearestSample(texture2d<float>, float2 coord);
Example:
void mainImage(thread Data &data)
{
float4 source = getLinearSample(data.slot0, data.uv);
data.outColor = source;
}