public Ray GetRay(float s, float t) { var lensPos = lensRadius * RayTraceUtility.GetRandomPointInUnitDisk(); var offset = lensPos.x * u + lensPos.y * v; return(new Ray(Position + offset, LowerLeft + s * Horizontal + t * Vertical - Position - offset)); }
public bool Scatter(Ray rayIn, HitRecord record, ref Color attenuation, ref Ray scatteredRay) { var target = RayTraceUtility.Reflect(rayIn.NormalizedDirection, record.Normal); scatteredRay = new Ray(record.Point, target); attenuation = albedo; return(Vector3.Dot(record.Normal, scatteredRay.Direction) > 0); }
public bool Scatter(Ray rayIn, HitRecord record, ref Color attenuation, ref Ray scatteredRay) { var target = record.Point + record.Normal + RayTraceUtility.GetRandomPointInUnitSphere(); scatteredRay = new Ray(record.Point, target - record.Point); attenuation = albedo; return(true); }
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)); }
public bool Scatter(Ray rayIn, HitRecord record, ref Color attenuation, ref Ray scatteredRay) { Vector3 outwardNormal; attenuation = Color.white; var eta = 0f; var cosi = 0f; var reflectProb = 0f; if (Vector3.Dot(rayIn.Direction, record.Normal) > 0) { outwardNormal = -record.Normal; eta = this.eta; cosi = eta * Vector3.Dot(rayIn.NormalizedDirection, record.Normal); } else { outwardNormal = record.Normal; eta = 1f / this.eta; cosi = -Vector3.Dot(rayIn.NormalizedDirection, record.Normal); } var refracted = Vector3.zero; if (RayTraceUtility.Refract(rayIn.Direction, outwardNormal, eta, ref refracted)) { reflectProb = RayTraceUtility.Schlick(cosi, eta); } else { reflectProb = 1f; } if (Random.Range(0f, 1f) <= reflectProb) { var reflected = RayTraceUtility.Reflect(rayIn.Direction, record.Normal); scatteredRay = new Ray(record.Point, reflected); } else { scatteredRay = new Ray(record.Point, refracted); } return(true); }