public Vector3D GetDirection(ref ShadeRec sr) { SamplePoint = GeoObj.Sample(); SampleNormal = GeoObj.GetNormal(SamplePoint); Wi = SamplePoint - sr.HitPoint; return(Wi); }
public override Vector3D SampleF(ref ShadeRec sr, ref Vector3D wo, out Vector3D wi, out double pdf) { float NDotWo = (float)sr.Normal.DotProduct(wo); wi = -wo + 2.0 * sr.Normal.ScaleBy(NDotWo); pdf = Math.Abs(sr.Normal * wi); return(Cr.ScaleBy(Kr)); }
public override Vector3D AreaLightShade(ref ShadeRec SR) { if (-SR.Normal.DotProduct(SR.Ray.Direction) > 0.0) { return(ce.ScaleBy(ls)); } else { return(PreDefColor.BlackColor); } }
public ShadeRec(ShadeRec SR) { HitAnObject = false; Material = null; HitPoint = new Vector3D(); LocalHitPoint = new Vector3D(); Normal = new Vector3D(); Ray = new Ray(); Depth = 0; RayParam = SR.RayParam; this.World = SR.World; }
public bool CheckInShadow(ref Ray ShadowRay, ref ShadeRec SR) { float t = 0.0f; foreach (GeometryObject GeoObj in SR.World.Objects) { if (GeoObj.ShadowHit(ref ShadowRay, ref t)) { return(true); } } return(false); }
public Vector3D L(ref ShadeRec sr) { float NDotD = (float)-SampleNormal.DotProduct(Wi); if (NDotD > 0.0f) { return(GeoObj.Material.Le(ref sr)); } else { return(PreDefColor.BlackColor); } }
public override Vector3D PathShading(ref ShadeRec SR) { Vector3D wo = -SR.Ray.Direction; Vector3D wi; double pdf; Vector3D f = DiffuseBRDF.SampleF(ref SR, ref wo, out wi, out pdf); float NDotWi = (float)(SR.Normal.DotProduct(wi) / pdf); ReflectRay.Origin = SR.HitPoint; ReflectRay.Direction = wi; Vector3D Rslt = SR.World.RayTracer.TraceRay(ref ReflectRay, SR.Depth + 1); return(new Vector3D(f.X * Rslt.X * NDotWi, f.Y * Rslt.Y * NDotWi, f.Z * Rslt.Z * NDotWi)); }
public override Vector3D TraceRay(ref Ray TestRay) { ShadeRec SR = WorldInstance.HitBareBoneObjects(ref TestRay); if (SR.HitAnObject) { SR.Ray = TestRay; return(SR.Material.Shading(ref SR)); } else { return(WorldInstance.BackgroundColor); } }
public override Vector3D PathShading(ref ShadeRec SR) { Vector3D wo = -SR.Ray.Direction; Vector3D wi; double pdf; Vector3D fr = PefSpecularBRDF.SampleF(ref SR, ref wo, out wi, out pdf); ReflectRay.Origin = SR.HitPoint; ReflectRay.Direction = wi; Vector3D Rslt = SR.World.RayTracer.TraceRay(ref ReflectRay, SR.Depth + 1); double p = (SR.Normal.DotProduct(wi) / pdf); return(new Vector3D(fr.X * Rslt.X * p, fr.Y * Rslt.Y * p, fr.Z * Rslt.Z * p)); }
public override Vector3D Factor(ref ShadeRec sr, ref Vector3D wo, ref Vector3D wi) { Vector3D L = new Vector3D(); double NDotWi = sr.Normal.DotProduct(wi); Vector3D r = -wi + sr.Normal.ScaleBy(NDotWi).ScaleBy(2.0); double RDotWo = r.DotProduct(wo); if (RDotWo > 0.0) { L = new Vector3D(1, 1, 1).ScaleBy(Math.Pow(RDotWo, Exp)).ScaleBy(Ks); } return(L); }
public override ColorRGB TraceRay(ref Ray TestRay) { ShadeRec SR = new ShadeRec(WorldInstance); double t = 0; if (WorldInstance.TestSphere.Hit(TestRay, ref t, ref SR)) { return(new ColorRGB(1, 0, 0)); } else { return(new ColorRGB(0, 0, 0)); } }
public override Vector3D AreaLightShade(ref ShadeRec SR) { Vector3D L = base.Shading(ref SR); Vector3D Wo = -SR.Ray.Direction; Vector3D Wi; double pdf; Vector3D fr = GlossySpecularBRDF.SampleF(ref SR, ref Wo, out Wi, out pdf); Ray ReflectedRay = new Ray(ref SR.HitPoint, ref Wi); // ReflectedRay.Depth = SR.Depth + 1; Vector3D FrTemp = fr.ScaleBy(SR.Normal.DotProduct(Wi)) / pdf; Vector3D Rslt = SR.World.RayTracer.TraceRay(ref ReflectedRay, SR.Depth + 1); L += new Vector3D(Rslt.X * FrTemp.X, Rslt.Y * FrTemp.Y, Rslt.Z * FrTemp.Z); return(L); }
public bool CheckInShadow(ref Ray ShadowRay, ref ShadeRec SR) { float t = 0.0f; int NumObjects = SR.World.Objects.Count; for (int j = 0; j < NumObjects; j++) { if (SR.World.Objects[j].ShadowHit(ref ShadowRay, ref t)) { return(true); } } return(false); }
public bool CheckInShadow(ref Ray ShadowRay, ref ShadeRec SR) { float t = .0f; float ts = (float)(SamplePoint - ShadowRay.Origin).DotProduct(ShadowRay.Direction); foreach (GeometryObject Obj in SR.World.Objects) { if (Obj.ShadowHit(ref ShadowRay, ref t) && (t < ts)) { return(true); } } return(false); }
public override bool Hit(Ray TheRay, ref double Param, ref ShadeRec SR) { double t = (PassthoughPoint - TheRay.Origin).DotProduct(Normal) / TheRay.Direction.DotProduct(Normal); if (t > Epsilon) { Param = t; SR.Normal = Normal; SR.LocalHitPoint = TheRay.Origin + t * TheRay.Direction; return(true); } else { return(false); } }
public override bool Hit(Ray TheRay, ref double Param, ref ShadeRec SR) { Vector3D Temp = TheRay.Origin - Center; double a = TheRay.Direction.DotProduct(TheRay.Direction); double b = 2.0 * Temp.DotProduct(TheRay.Direction); double c = Temp.DotProduct(Temp) - Radius * Radius; double disc = b * b - 4.0 * a * c; if (disc < 0.0) { return(false); } else { double e = Math.Sqrt(disc); double denom = 2.0 * a; double t = (-b - e) / denom; if (t > 1000) { return(false); } if (t > Epsilon) { Param = t; SR.Normal = (Temp + t * TheRay.Direction) / Radius; SR.LocalHitPoint = TheRay.Origin + t * TheRay.Direction; return(true); } t = (-b + e) / denom; if (t > Epsilon) { Param = t; SR.Normal = (Temp + t * TheRay.Direction) / Radius; SR.LocalHitPoint = TheRay.Origin + t * TheRay.Direction; return(true); } return(false); } }
public override Vector3D SampleF(ref ShadeRec sr, ref Vector3D wo, out Vector3D wi, out double pdf) { Vector3D w = sr.Normal; Vector3D v = new Vector3D(0.0034, 1, 0.0071); v = v.CrossProduct(w); v = v.Normalize().ToVector3D(); Vector3D u = v.CrossProduct(w); Vector3D sp = SamplerRef.SampleHemisphere(); wi = sp.X * u + sp.Y * v + sp.Z * w; wi = wi.Normalize().ToVector3D(); pdf = (float)(sr.Normal * wi * (1.0 / Math.PI)); return(Cd.ScaleBy(Kd * (1.0 / Math.PI))); }
public override Vector3D TraceRay(ref Ray TestRay, int depth) { if (depth > WorldInstance.VP.MaxDepth) { return(PreDefColor.BlackColor); } else { ShadeRec SR = WorldInstance.HitBareBoneObjects(ref TestRay); if (SR.HitAnObject) { SR.Depth = depth; SR.Ray = TestRay; return(SR.Material.AreaLightShade(ref SR)); } else { return(WorldInstance.BackgroundColor); } } }
public override Vector3D AreaLightShade(ref ShadeRec SR) { Vector3D Wo = -SR.Ray.Direction; Vector3D RHO = AmbientBRDF.RHO(ref SR, ref Wo); Vector3D LtFac = SR.World.AmbientLight.L(ref SR); Vector3D L = new Vector3D(RHO.X * LtFac.X, RHO.Y * LtFac.Y, RHO.Z * LtFac.Z); if ((L.X + L.Y + L.Z) <= 0.001f) { return(L); } foreach (Light Lt in SR.World.Lights) { Vector3D Wi = Lt.GetDirection(ref SR).Normalize().ToVector3D(); double NDotWi = SR.Normal.DotProduct(Wi); if (NDotWi > 0.0) { bool bInShadow = false; if (Lt.EnableCastShadow()) { ShadowRay.Origin = SR.HitPoint; ShadowRay.Direction = Wi; bInShadow = Lt.CheckInShadow(ref ShadowRay, ref SR); } if (!bInShadow) { RHO = DiffuseBRDF.Factor(ref SR, ref Wo, ref Wi) + SpecularBRDF.Factor(ref SR, ref Wo, ref Wi); LtFac = Lt.L(ref SR); float G = Lt.GeoTerms(ref SR) / Lt.PDF(ref SR); L += new Vector3D(RHO.X * LtFac.X * NDotWi * G, RHO.Y * LtFac.Y * NDotWi * G, RHO.Z * LtFac.Z * NDotWi * G); } } } return(L); }
public override Vector3D Shading(ref ShadeRec SR) { return(AreaLightShade(ref SR)); }
public float PDF(ref ShadeRec SR) { return(1.0f); }
public float GeoTerms(ref ShadeRec SR) { return(1.0f); }
public Vector3D GetDirection(ref ShadeRec sr) { return(SamplerRef.SampleHemisphere()); }
public virtual Vector3D Le(ref ShadeRec sr) { return(PreDefColor.BlackColor); }
public virtual Vector3D AreaLightShade(ref ShadeRec SR) { return(PreDefColor.BlackColor); }
public virtual Vector3D PathShading(ref ShadeRec SR) { return(PreDefColor.BlackColor); }
public Vector3D GetDirection(ref ShadeRec sr) { return(Dir); }
public Vector3D L(ref ShadeRec sr) { return(Color.ScaleBy(ls)); }
public virtual Vector3D RHO(ref ShadeRec sr, ref Vector3D wo) { return(PreDefColor.BlackColor); }
public override Vector3D Le(ref ShadeRec sr) { return(ce.ScaleBy(ls)); }