// Cheap shadows are hard. In fact, I'd almost say, shadowing particular scenes with limited // iterations is impossible... However, I'd be very grateful if someone could prove me wrong. :) private static float SoftShadow(Float3 ro, Float3 lp, Float3 n, float k) { const int iter = 24; ro += n * 0.0015f; Float3 rd = lp - ro; float shade = 1.0f; float t = 0; float end = Hlsl.Max(Hlsl.Length(rd), 0.0001f); rd /= end; for (int i = 0; i < iter; i++) { float d = M(ro + rd * t); shade = Hlsl.Min(shade, k * d / t); t += Hlsl.Clamp(d, 0.01f, 0.25f); if (d < 0.0f || t > end) { break; } } return(Hlsl.Max(shade, 0.0f)); }