public Ray GenerateRay(LocalGeo geo, out RTColor color) { color = Color; RTVector ray = Source - geo.Point; return(new Ray(geo.Point, ray.Normalize(), 1e-3f, ray.Length, false)); }
private RTColor Shading(LocalGeo geo, ShadingInfos si, Ray camRay, Ray lightRay, RTColor lightCol) { float nDotL = RTVector.DotProduct(geo.Normal, lightRay.Vector); RTColor lambert = lightCol * si.Diffuse * (nDotL > 0 ? nDotL : 0.0f); RTVector half = (lightRay.Vector - camRay.Vector.Normalize()).Normalize(); float nDotH = RTVector.DotProduct(geo.Normal, half); RTColor phong = lightCol * si.Specular * (float)Math.Pow((nDotH > 0 ? nDotH : 0.0f), si.Shininess); float r = lightRay.Directional ? 0 : lightRay.TMax; // Dans le cas d'un point, le t max est la distance entre le point et la source RTColor res = (lambert + phong) / (Attenuation.Constant + Attenuation.Linear * r + Attenuation.Quadratic * (float)Math.Pow(r, 2)); return(res); }
public bool Intersect(Ray ray, bool computeGeo, out LocalGeo geo, out float pos) { RTPoint A = Vertices[0].Location; RTPoint B = Vertices[1].Location; RTPoint C = Vertices[2].Location; RTVector p0 = new RTVector(ray.Point); pos = RTVector.DotProduct(A - ray.Point, Normal) / RTVector.DotProduct(ray.Vector, Normal); geo = new LocalGeo(); if (pos >= ray.TMin && pos <= ray.TMax) { geo.Point = ray.Point + pos * ray.Vector; geo.Normal = Normal; RTVector u = B - A; RTVector v = C - A; RTVector w = geo.Point - A; RTVector vCrossW = RTVector.CrossProduct(v, w); RTVector vCrossU = RTVector.CrossProduct(v, u); if (RTVector.DotProduct(vCrossW, vCrossU) < 0) { return(false); } RTVector uCrossW = RTVector.CrossProduct(u, w); RTVector uCrossV = RTVector.CrossProduct(u, v); if (RTVector.DotProduct(uCrossW, uCrossV) < 0) { return(false); } float denom = uCrossV.Length; float r = vCrossW.Length / denom; float t = uCrossW.Length / denom; return(r + t <= 1); } return(false); }
public bool Intersect(Ray ray, bool computeGeo, out LocalGeo geo, out float t) { return(Shape.Intersect(ray, computeGeo, out geo, out t)); }
public ShadingInfos GetShading(LocalGeo geo) { return(Material.GetShading(geo)); }
public bool Intersect(Ray ray, bool computeGeo, out LocalGeo geo, out float t) { RTPoint tPoint = Transformation.ApplyInverseTo(new RTPoint(ray.Point.X, ray.Point.Y, ray.Point.Z)); RTVector tVec = Transformation.ApplyInverseTo(new RTVector(ray.Vector.X, ray.Vector.Y, ray.Vector.Z)); RTVector ec = tPoint - Center; float a = RTVector.DotProduct(tVec, tVec); float b = 2.0f * RTVector.DotProduct(tVec, ec); float c = RTVector.DotProduct(ec, ec) - (float)Math.Pow(Radius, 2); float det = (float)Math.Pow(b, 2) - 4.0f * a * c; t = float.MaxValue; bool intersect = false; if (det == 0d) { intersect = true; t = -b / (2.0f * a); } else if (det > 0d) { float t1 = (-b + (float)Math.Sqrt(det)) / (2.0f * a); float t2 = (-b - (float)Math.Sqrt(det)) / (2.0f * a); if ((t1 > 0 && t2 < 0) || (t1 < 0 && t2 > 0)) { intersect = true; if (t1 > 0) { t = t1; } else { t = t2; } } else if (t1 > 0 && t2 > 0) { intersect = true; if (t1 < t2) { t = t1; } else { t = t2; } } } geo = new LocalGeo(); if (intersect && t >= ray.TMin && t <= ray.TMax) { if (computeGeo) { geo.Point = tPoint + t * tVec; geo.Normal = new Normal(geo.Point - Center); geo.Point = Transformation.ApplyTo(geo.Point); geo.Normal = new Normal(Transformation.ApplyInverseTransposeTo(geo.Normal)); } return(true); } return(false); }
public ShadingInfos GetShading(LocalGeo geo) { return(Properties); }
public Ray GenerateRay(LocalGeo geo, out RTColor color) { color = Color; return(new Ray(geo.Point, Direction.Normalize(), 1e-3f, float.MaxValue, true)); }