Timing and saftey pass
This commit is contained in:
54
shaders/happy-accident/shader.json
Normal file
54
shaders/happy-accident/shader.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"id": "happy-accident",
|
||||
"name": "Happy Accident",
|
||||
"description": "Raymarched generative line field. CC0 original 'Clearly a bug' adapted from https://www.shadertoy.com/view/33cGDj.",
|
||||
"category": "Generative",
|
||||
"entryPoint": "shadeVideo",
|
||||
"parameters": [
|
||||
{
|
||||
"id": "speed",
|
||||
"label": "Speed",
|
||||
"type": "float",
|
||||
"default": 1.0,
|
||||
"min": 0.0,
|
||||
"max": 4.0,
|
||||
"step": 0.01
|
||||
},
|
||||
{
|
||||
"id": "scale",
|
||||
"label": "Scale",
|
||||
"type": "float",
|
||||
"default": 1.0,
|
||||
"min": 0.25,
|
||||
"max": 3.0,
|
||||
"step": 0.01
|
||||
},
|
||||
{
|
||||
"id": "raySteps",
|
||||
"label": "Ray Steps",
|
||||
"type": "float",
|
||||
"default": 77.0,
|
||||
"min": 8.0,
|
||||
"max": 77.0,
|
||||
"step": 1.0
|
||||
},
|
||||
{
|
||||
"id": "intensity",
|
||||
"label": "Intensity",
|
||||
"type": "float",
|
||||
"default": 1.0,
|
||||
"min": 0.1,
|
||||
"max": 4.0,
|
||||
"step": 0.01
|
||||
},
|
||||
{
|
||||
"id": "sourceMix",
|
||||
"label": "Source Mix",
|
||||
"type": "float",
|
||||
"default": 0.0,
|
||||
"min": 0.0,
|
||||
"max": 1.0,
|
||||
"step": 0.01
|
||||
}
|
||||
]
|
||||
}
|
||||
61
shaders/happy-accident/shader.slang
Normal file
61
shaders/happy-accident/shader.slang
Normal file
@@ -0,0 +1,61 @@
|
||||
float happyNoise(float2 p)
|
||||
{
|
||||
return frac(dot(p, sin(p))) - 0.5;
|
||||
}
|
||||
|
||||
float2x2 rotateAroundZ(float angle)
|
||||
{
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
return float2x2(c, s, -s, c);
|
||||
}
|
||||
|
||||
float2x2 happyAccidentMatrix(float3 originalPosition, float timeCos)
|
||||
{
|
||||
return float2x2(
|
||||
cos(originalPosition.x),
|
||||
sin(originalPosition.y),
|
||||
-sin(originalPosition.z),
|
||||
timeCos);
|
||||
}
|
||||
|
||||
float4 shadeVideo(ShaderContext context)
|
||||
{
|
||||
float2 resolution = max(context.outputResolution, float2(1.0, 1.0));
|
||||
float2 fragCoord = context.uv * resolution;
|
||||
float2 normalizedCoord = (fragCoord - 0.5 * resolution) / resolution.y / max(scale, 0.001);
|
||||
float time = context.time * speed;
|
||||
float timeCos = cos(0.1 * time);
|
||||
float3 direction = normalize(float3(normalizedCoord, 1.0));
|
||||
float3 origin = float3(0.0, 0.0, time);
|
||||
|
||||
float z = happyNoise(fragCoord);
|
||||
float distanceToSurface = 0.0;
|
||||
float4 accumulated = float4(0.0, 0.0, 0.0, 0.0);
|
||||
float clampedSteps = clamp(raySteps, 1.0, 77.0);
|
||||
|
||||
for (int i = 0; i < 77; ++i)
|
||||
{
|
||||
if (float(i) >= clampedSteps)
|
||||
break;
|
||||
|
||||
z += 0.6 * distanceToSurface;
|
||||
|
||||
float3 position = origin + z * direction;
|
||||
float3 originalPosition = position;
|
||||
|
||||
position.xy = mul(rotateAroundZ(2.0 + originalPosition.z), position.xy);
|
||||
position.xy = mul(happyAccidentMatrix(originalPosition, timeCos), position.xy);
|
||||
|
||||
float colorSeed = 0.5 * originalPosition.z + length(position - originalPosition);
|
||||
float4 palette = 1.0 + sin(colorSeed + float4(0.0, 4.0, 3.0, 6.0));
|
||||
palette /= 0.5 + 2.0 * dot(originalPosition.xy, originalPosition.xy);
|
||||
|
||||
position = abs(frac(position) - 0.5);
|
||||
distanceToSurface = abs(min(length(position.xy) - 0.125, min(position.x, position.y) + 0.001)) + 0.001;
|
||||
accumulated += palette.w * palette / distanceToSurface;
|
||||
}
|
||||
|
||||
float4 color = float4(tanh((accumulated.rgb * intensity) / 20000.0), 1.0);
|
||||
return saturate(lerp(color, context.sourceColor, sourceMix));
|
||||
}
|
||||
Reference in New Issue
Block a user