SierpinskiGasket.HLSL
https://gyazo.com/9aa3f8f059c9af592706feeee83cd4eb
code:SielpinskiGasket.HLSL
float2 mod(float2 x, float y) {
return x - floor(x/y)*y;
}
float sdBox(float2 p, float2 s) {
float2 q = abs(p) - s;
float2 d = max(q, float2(.0));
return length(d) + min(max(q.x, q.y), 0.);
}
float sdCross(float2 p) {
p = abs(p);
return min(p.x, p.y) - 1.0;
}
float sierpinski(float2 p)
{
float d = sdBox(p, float2(1,1));
float s = 1.0;
for (int i = 0; i < 4; i++) {
float2 a = mod(p * s, 2.0) - 1.0;
float2 r = 1.0 - 3.0 * abs(a);
s *= 3.0;
float c = sdCross(r) / s;
d = max(d, c);
}
return d;
}
fixed4 frag (v2f i) : SV_Target
{
float2 p = 2*i.uv-1;
float d = sierpinski(p);
fixed4 col = (1).xxxx;
return col * d;
}