Skip to content

Instantly share code, notes, and snippets.

@hecomi
Last active May 13, 2019 16:53
Show Gist options
  • Save hecomi/3402e71d61a8b3effd152859a3f7f387 to your computer and use it in GitHub Desktop.
Save hecomi/3402e71d61a8b3effd152859a3f7f387 to your computer and use it in GitHub Desktop.
Truchet Tentacles
// original code: https://www.shadertoy.com/view/ldfGWn
inline float rand(float3 r)
{
return frac(sin(dot(r.xy, r.yz)));
}
inline float truchetarc(float3 pos)
{
float p = 4.0 + 2.0 * _SinTime.w;
float r = length(pos.xy);
float t = 0.12 + 0.02 * _SinTime.w;
return pow(
pow(abs(r - 0.5), p) + pow(abs(pos.z - 0.5), p),
rcp(p)
) - t;
}
inline float truchetcell(float3 pos)
{
return min(min(
truchetarc(pos),
truchetarc(float3(pos.z, 1.0 - pos.x, pos.y))),
truchetarc(float3(1.0 - pos.y, 1.0 - pos.z, pos.x)));
}
inline float map(float3 pos)
{
float3 c = frac(pos);
float r = rand(floor(pos));
if (r < 0.125) return truchetcell(float3(c.x, c.y, c.z));
else if (r < 0.250) return truchetcell(float3(c.x, 1.0 - c.y, c.z));
else if (r < 0.375) return truchetcell(float3(1.0 - c.x, c.y, c.z));
else if (r < 0.500) return truchetcell(float3(1.0 - c.x, 1.0 - c.y, c.z));
else if (r < 0.625) return truchetcell(float3(c.y, c.x, c.z));
else if (r < 0.750) return truchetcell(float3(c.y, 1.0 - c.x, c.z));
else if (r < 0.875) return truchetcell(float3(1.0 - c.y, c.x, c.z));
else return truchetcell(float3(1.0 - c.y, 1.0 - c.x, c.z));
}
inline float DistanceFunction(float3 pos)
{
return map(pos);
}
inline void PostEffect(RaymarchInfo ray, inout PostEffectOutput o)
{
o.Albedo = 0.5 + 0.5 * normalize(ray.endPos);
}
@hecomi
Copy link
Author

hecomi commented Apr 14, 2017

capture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment