public override bool Hit(Ray ray, double tMin, double tMax, out ShadeRec shadeRec) { shadeRec = new ShadeRec(); shadeRec.IsHit = false; double t = (k - ray.Origin.Y) / ray.Direction.Y; if (t < tMin || t > tMax) { return(false); } double x = ray.Origin.X + t * ray.Direction.X; double z = ray.Origin.Z + t * ray.Direction.Z; if (x < x0 || x > x1 || z < z0 || z > z1) { return(false); } shadeRec.IsHit = true; shadeRec.U = (z - z0) / (z1 - z0); shadeRec.V = (x - x0) / (x1 - x0); shadeRec.HitT = t; shadeRec.HitObjGloMat = geoMat; shadeRec.HitPoint = ray.getPointAtRay(t); shadeRec.Normal = new Vector3D(0, 1, 0); return(true); }
public override bool Hit(Ray ray, double tMin, double tMax, out ShadeRec shadeRec) { ShadeRec rec1, rec2; shadeRec = new ShadeRec(); if (boundary.Hit(ray, -1e15, 1e15, out rec1)) { if (boundary.Hit(ray, rec1.HitT + 1e-4, 1e15, out rec2)) { if (rec1.HitT < tMin) { rec1.HitT = tMin; } if (rec2.HitT > tMax) { rec2.HitT = tMax; } if (rec1.HitT >= rec2.HitT) { return(false); } if (rec1.HitT < 0) { rec1.HitT = 0; } double distanceInsideBoundary = (rec2.HitT - rec1.HitT) * ray.Direction.Magnitude(); double hitDistance = -(1.0 / density) * Math.Log(Form2.random()); if (hitDistance < distanceInsideBoundary) { shadeRec.IsHit = true; shadeRec.HitT = rec1.HitT + hitDistance / ray.Direction.Magnitude(); shadeRec.HitPoint = ray.getPointAtRay(shadeRec.HitT); shadeRec.Normal = new Vector3D(Form2.random(), Form2.random(), Form2.random()); shadeRec.HitObjGloMat = phase_function; return(true); } } } return(false); }