public override (SurfaceInteraction, double) Sample() { // TODO: Implement Sphere sampling if (Outside) { var pObj = this.Radius * Samplers.UniformSampleSphere(); var n = new Vector3(pObj.x, pObj.y, pObj.z); var pdf = 1 / this.Area(); var dpdu = new Vector3(-pObj.y, pObj.x, 0); SurfaceInteraction si = new SurfaceInteraction(pObj, n, Vector3.ZeroVector, dpdu, this); return(ObjectToWorld.Apply(si), pdf); } else { var pObj = this.Radius * Samplers.UniformSampleSphere(); var n = new Vector3(pObj.x, pObj.y, pObj.z); var pdf = 1 / this.Area(); var dpdu = new Vector3(-pObj.y, pObj.x, 0); SurfaceInteraction si = new SurfaceInteraction(pObj, -n, Vector3.ZeroVector, dpdu, this); return(ObjectToWorld.Apply(si), pdf); } // TODO: Return surface interaction and pdf // A dummy return example //double dummyPdf = 1.0; //Vector3 dummyVector = new Vector3(0, 0, 0); //SurfaceInteraction dummySurfaceInteraction = new SurfaceInteraction(dummyVector, dummyVector, dummyVector, dummyVector, this); //return (dummySurfaceInteraction, dummyPdf); }
public override (Spectrum, Vector3, double) Sample_f(Vector3 wo) { Vector3 wi = Samplers.CosineSampleHemisphere(); if (wo.z < 0.0) { wi.z *= 1.0; } return(f(wo, wi), wi, Pdf(wo, wi)); }
public override (SurfaceInteraction, double) Sample() { var pObj = Samplers.UniformSampleSphere() * Radius; pObj *= Radius / pObj.Length(); // refine var n = pObj.Normalize(); var dpdu = new Vector3(-pObj.y, pObj.x, 0); var pdf = 1 / Area(); return(ObjectToWorld.Apply(new SurfaceInteraction(pObj, n, Vector3.ZeroVector, dpdu, this)), pdf); }
public override (Spectrum, Vector3, double) Sample_f(Vector3 wo) { var wi = Samplers.CosineSampleHemisphere(); if (wo.z < 0) { wi.z *= -1; } double pdf = Pdf(wo, wi); return(f(wo, wi), wi, pdf); }
public override (SurfaceInteraction, double) Sample() { (double x, double y) = Samplers.UniformSampleDisk(); var pObj = new Vector3(x * radius, y * radius, height); var n = new Vector3(0, 0, 1); var dpdu = new Vector3(-pObj.y, pObj.x, 0); double pdf = 1 / Area(); return(ObjectToWorld.Apply(new SurfaceInteraction(pObj, n, Vector3.ZeroVector, dpdu, this)), pdf); }
public override (SurfaceInteraction, double) Sample() { (double x, double y) = Samplers.UniformSampleSquare(); var pObj = new Vector3((x - 0.5) * width, (y - 0.5) * height, 0); var n = new Vector3(0, 0, 1); var dpdu = new Vector3(1, 0, 0); double pdf = 1 / Area(); return(ObjectToWorld.Apply(new SurfaceInteraction(pObj, n, Vector3.ZeroVector, dpdu, this)), pdf); }
public override (SurfaceInteraction, double) Sample() { Vector3 sample = Samplers.UniformSampleSphere(); Vector3 point = sample * Radius; Vector3 normal = sample; Vector3 dpdu = new Vector3(-normal.y, normal.x, 0.0); double pdf = 1.0 / Area(); SurfaceInteraction si = new SurfaceInteraction(point, normal, Vector3.ZeroVector, dpdu, this); return(ObjectToWorld.Apply(si), pdf); }
public override (SurfaceInteraction, double) Sample() { // TODO: Implement Sphere sampling //Vector3 pObj = Samplers.CosineSampleHemisphere() * Radius; Vector3 pObj = Samplers.UniformSampleSphere() * Radius; pObj = pObj * (Radius / pObj.Length()); // TODO: Return surface interaction and pdf var dpdu = new Vector3(-pObj.y, pObj.x, 0); double pdf = 1 / Area(); // a je kle inv 4 PI (1/Math.PI/4) return(ObjectToWorld.Apply(new SurfaceInteraction(pObj, ObjectToWorld.ApplyNormal(pObj), Vector3.ZeroVector, dpdu, this)), pdf); }
public override double Pdf(SurfaceInteraction _si, Vector3 wi) { SurfaceInteraction si = WorldToObject.Apply(_si); double dist2 = si.Point.LengthSquared(); if (dist2 <= Radius * Radius) { // Point inside sphere return(base.Pdf(_si, wi)); } // Point outside sphere double sinThetaMax = Radius / Math.Sqrt(dist2); double cosThetaMax = Utils.SinToCos(sinThetaMax); return(Samplers.UniformConePdf(cosThetaMax)); }
public override (SurfaceInteraction, double) Sample(SurfaceInteraction _si) { SurfaceInteraction si = WorldToObject.Apply(_si); double dc2 = si.Point.LengthSquared(); if (dc2 <= Radius * Radius) { // Point inside sphere return(base.Sample(_si)); } // Point outside sphere double dc = Math.Sqrt(dc2); double sinThetaMax = Radius / dc; double cosThetaMax = Utils.SinToCos(sinThetaMax); // Determine theta and phi for uniform cone sampling double cosTheta = (cosThetaMax - 1) * Samplers.ThreadSafeRandom.NextDouble() + 1; double sinTheta = Utils.CosToSin(cosTheta); double phi = Samplers.ThreadSafeRandom.NextDouble() * 2.0 * Math.PI; // Distance between reference point and sample point on sphere double ds = dc * cosTheta - Math.Sqrt(Math.Max(0, Radius * Radius - dc2 * sinTheta * sinTheta)); // Kosinusni zakon double cosAlpha = (dc2 + Radius * Radius - ds * ds) / (2 * dc * Radius); double sinAlpha = Utils.CosToSin(cosAlpha); // Construct coordinate system and use phi and theta as spherical coordinates to get point on sphere Vector3 wcZ = si.Point.Clone().Normalize(); (Vector3 wcX, Vector3 wcY) = Utils.CoordinateSystem(wcZ); Vector3 nObj = Utils.SphericalDirection(sinAlpha, cosAlpha, phi, wcX, wcY, wcZ); Vector3 pObj = nObj * Radius; // Surface interaction Vector3 dpdu = new Vector3(-nObj.y, nObj.x, 0.0); SurfaceInteraction siSample = new SurfaceInteraction(pObj, nObj, Vector3.ZeroVector, dpdu, this); // Uniform cone PDF double pdf = Samplers.UniformConePdf(cosThetaMax); return(ObjectToWorld.Apply(siSample), pdf); }
public override (SurfaceInteraction, double) Sample() { // TODO: Implement Sphere sampling var center = new Vector3(0, 0, 0); var point = center + Radius * Samplers.UniformSampleSphere(); var normal = point.Normalize(); if (innerOrientation) { normal = -normal; } point *= Radius / (center - point).Length(); var wo = point; var dpdu = Dpdu(point); var interaction = new SurfaceInteraction(point, normal, wo, dpdu, this); return(ObjectToWorld.Apply(interaction), Pdf(interaction, point)); }
public override double Pdf(Vector3 wo, Vector3 wi) { //return Samplers.UniformHemispherePdf(); return(Samplers.CosineHemispherePdf(wo, wi)); }