Added trigger
This commit is contained in:
59
shaders/trigger-ripple/shader.json
Normal file
59
shaders/trigger-ripple/shader.json
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"id": "trigger-ripple",
|
||||
"name": "Trigger Ripple",
|
||||
"description": "A water-drop style ripple that expands across the video whenever the trigger is pressed.",
|
||||
"category": "Utility",
|
||||
"entryPoint": "shadeVideo",
|
||||
"parameters": [
|
||||
{
|
||||
"id": "drop",
|
||||
"label": "Drop",
|
||||
"type": "trigger"
|
||||
},
|
||||
{
|
||||
"id": "center",
|
||||
"label": "Center",
|
||||
"type": "vec2",
|
||||
"default": [0.5, 0.5],
|
||||
"min": [0.0, 0.0],
|
||||
"max": [1.0, 1.0],
|
||||
"step": [0.01, 0.01]
|
||||
},
|
||||
{
|
||||
"id": "strength",
|
||||
"label": "Strength",
|
||||
"type": "float",
|
||||
"default": 0.12,
|
||||
"min": 0.0,
|
||||
"max": 0.3,
|
||||
"step": 0.001
|
||||
},
|
||||
{
|
||||
"id": "speed",
|
||||
"label": "Duration",
|
||||
"type": "float",
|
||||
"default": 0.3,
|
||||
"min": 0.3,
|
||||
"max": 5.0,
|
||||
"step": 0.01
|
||||
},
|
||||
{
|
||||
"id": "width",
|
||||
"label": "Wave Width",
|
||||
"type": "float",
|
||||
"default": 0.09,
|
||||
"min": 0.01,
|
||||
"max": 0.25,
|
||||
"step": 0.001
|
||||
},
|
||||
{
|
||||
"id": "damping",
|
||||
"label": "Damping",
|
||||
"type": "float",
|
||||
"default": 0.25,
|
||||
"min": 0.05,
|
||||
"max": 3.0,
|
||||
"step": 0.05
|
||||
}
|
||||
]
|
||||
}
|
||||
34
shaders/trigger-ripple/shader.slang
Normal file
34
shaders/trigger-ripple/shader.slang
Normal file
@@ -0,0 +1,34 @@
|
||||
float4 shadeVideo(ShaderContext context)
|
||||
{
|
||||
if (drop <= 0)
|
||||
return context.sourceColor;
|
||||
|
||||
float age = max(context.time - dropTime, 0.0);
|
||||
float2 aspect = float2(context.outputResolution.x / max(context.outputResolution.y, 1.0), 1.0);
|
||||
float2 fromDrop = (context.uv - center) * aspect;
|
||||
float radius = length(fromDrop);
|
||||
|
||||
float2 c0 = (float2(0.0, 0.0) - center) * aspect;
|
||||
float2 c1 = (float2(1.0, 0.0) - center) * aspect;
|
||||
float2 c2 = (float2(0.0, 1.0) - center) * aspect;
|
||||
float2 c3 = (float2(1.0, 1.0) - center) * aspect;
|
||||
float maxRadius = max(max(length(c0), length(c1)), max(length(c2), length(c3)));
|
||||
float progress = saturate(age / max(speed, 0.001));
|
||||
float waveRadius = progress * maxRadius;
|
||||
float distanceToWave = radius - waveRadius;
|
||||
float waveWidth = max(width * maxRadius, 0.0001);
|
||||
float ring = (1.0 - smoothstep(waveWidth, waveWidth * 1.65, abs(distanceToWave))) * exp(-progress * damping * 0.35);
|
||||
float crest = 1.0 - smoothstep(0.0, waveWidth * 0.35, abs(distanceToWave));
|
||||
float ripple = ring * (distanceToWave >= 0.0 ? 1.0 : -0.55);
|
||||
|
||||
float2 direction = radius > 0.0001 ? fromDrop / radius : float2(0.0, 0.0);
|
||||
float2 uvOffset = direction * (ripple * strength);
|
||||
uvOffset.x /= aspect.x;
|
||||
|
||||
float2 refractedUv = clamp(context.uv - uvOffset, float2(0.0, 0.0), float2(1.0, 1.0));
|
||||
float4 refracted = sampleVideo(refractedUv);
|
||||
|
||||
float highlight = saturate(ring * 0.75 + crest * 0.55);
|
||||
refracted.rgb += highlight * 0.075;
|
||||
return saturate(refracted);
|
||||
}
|
||||
Reference in New Issue
Block a user