static Color GetColorFromHitRecord(Ray ray, HitableList list) { var rec = new HitRecord(); if (list.Hit(ray, 0.001f, float.MaxValue, ref rec)) { var target = rec.Point + rec.Normal + RayTraceUtility.GetRandomPointInUnitSphere(); return(0.5f * GetColorFromHitRecord(new Ray(rec.Point, target - rec.Point), list)); } var t = (ray.NormalizedDirection.y + 1f) * 0.5f; return((1 - t) * Color.white + t * new Color(0.5f, 0.7f, 1f)); }
static Color GetColorForTestMetal(Ray ray, HitableList hitableList, int depth) { HitRecord record = new HitRecord(); if (hitableList.Hit(ray, 0.0001f, float.MaxValue, ref record)) { Ray r = new Ray(Vector3.zero, Vector3.zero); Color attenuation = Color.black; if (depth < MAX_SCATTER_TIME && record.material.Scatter(ray, record, ref attenuation, ref r)) { Color c = GetColorForTestMetal(r, hitableList, depth + 1); return(new Color(c.r * attenuation.r, c.g * attenuation.g, c.b * attenuation.b)); } return(Color.black); } float t = 0.5f * ray.normalDirection.y + 1f; return((1 - t) * new Color(1, 1, 1) + t * new Color(0.5f, 0.7f, 1)); }
static Color GetColorFromHitRecord(Ray ray, HitableList list, int depth) { var record = new HitRecord(); if (list.Hit(ray, 0.001f, float.MaxValue, ref record)) { var scatterdRay = new Ray(Vector3.zero, Vector3.zero); var attenuation = Color.black; if (depth < MaxDepth && record.Material.Scatter(ray, record, ref attenuation, ref scatterdRay)) { var c = GetColorFromHitRecord(scatterdRay, list, depth + 1); return(new Color(c.r * attenuation.r, c.g * attenuation.g, c.b * attenuation.b)); } else { return(Color.black); } } var t = (ray.NormalizedDirection.y + 1f) * 0.5f; return((1 - t) * Color.white + t * new Color(0.5f, 0.7f, 1f)); }