public static float3 Color(Ray r, HitableArray <Sphere> world, int depth, ref Random rng) { var rec = new HitRecord(); if (world.Hit(r, 0.001f, float.MaxValue, ref rec)) { Ray scattered = new Ray(); float3 attenuation = new float3(); if (depth < 50) { if (r.Scatter(rec, ref attenuation, ref scattered, ref rng)) { return(attenuation * Color(scattered, world, depth + 1, ref rng)); } } else { // this ray has run out of bounces - draw a black pixel return(new float3()); } } // the ray didn't hit anything, so draw the background color for this pixel return(Utils.BackgroundColor(ref r)); }
public static float3 Color(Ray r, HitableArray <Sphere> world) { var rec = new HitRecord(); if (world.Hit(r, 0f, float.MaxValue, ref rec)) { var rn = rec.normal; return(0.5f * new float3(rn.x + 1f, rn.y + 1f, rn.z + 1f)); } return(Utils.BackgroundColor(ref r)); }
public float3 Color(Ray r, HitableArray <Sphere> world) { var rec = new HitRecord(); if (recursionCounter < maxHits && world.Hit(r, 0.001f, float.MaxValue, ref rec)) { recursionCounter++; var target = rec.p + rec.normal + Utils.RandomInUnitSphere(random); return(absorbRate * Color(new Ray(rec.p, target - rec.p), world)); } return(Utils.BackgroundColor(ref r)); }