/// <inheritdoc/> public float4 Execute() { float2 position = ((float2)(256 * ThreadIds.XY)) / DispatchSize.X + time; float4 color = 0; for (int i = 0; i < 6; i++) { float2 a = Hlsl.Floor(position); float2 b = Hlsl.Frac(position); float4 w = Hlsl.Frac( (Hlsl.Sin(a.X * 7 + 31.0f * a.Y + 0.01f * time) + new float4(0.035f, 0.01f, 0, 0.7f)) * 13.545317f); color.XYZ += w.XYZ * 2.0f * Hlsl.SmoothStep(0.45f, 0.55f, w.W) * Hlsl.Sqrt(16.0f * b.X * b.Y * (1.0f - b.X) * (1.0f - b.Y)); position /= 2.0f; color /= 2.0f; } color.XYZ = Hlsl.Pow(color.XYZ, new float3(0.7f, 0.8f, 0.5f)); color.W = 1.0f; return(color); }
/// <inheritdoc/> public float4 Execute() { float2 uv = (ThreadIds.XY - (float2)DispatchSize.XY * 0.5f) / DispatchSize.Y; float3 col = 0; float t = time * 0.3f; for (float i = 0.0f; i <= 1.0f; i += 1.0f / NumberOfLayers) { float d = Hlsl.Frac(i + t); float s = Hlsl.Lerp(5.0f, 0.5f, d); float f = d * Hlsl.SmoothStep(1.0f, 0.9f, d); col += Tex(new float3(uv.X * s, uv.Y * s, i * 4.0f)).XYZ *f; } col /= NumberOfLayers; col *= new float3(2, 1.0f, 2.0f); col = Hlsl.Pow(col, 0.5f); return(new(col.X, col.Y, col.Z, 1.0f)); }
// The scene's distance function: There'd be faster ways to do this, but it's // more readable this way. Plus, this is a pretty simple scene, so it's // efficient enough. private static float M(Float3 p) { float fl = -p.Z; float obj = Truchet(p.XY); obj = Hlsl.Max(obj, Hlsl.Abs(p.Z) - 0.125f) - Hlsl.SmoothStep(0.03f, 0.25f, -obj) * 0.1f; float studs = 1e5f; const float sc = 0.5f; Float2 q = p.XY + 0.5f * sc; Float2 iq = Hlsl.Floor(q / sc) + 0.5f; q -= iq * sc; if (Mod(iq.X + iq.Y, 2.0f) > 0.5f) { studs = Hlsl.Max(Hlsl.Length(q) - 0.1f * sc - 0.02f, Hlsl.Abs(p.Z) - 0.26f); } objID = fl < obj && fl < studs ? 0 : obj < studs ? 1 : 2; return(Hlsl.Min(Hlsl.Min(fl, obj), studs)); }