private Vector EstimateColorWithPhotonmapping(int x, int y, Random rand, Photonmap photonmap) { Ray primaryRay = data.Camera.GetPrimaryRay(x, y); float cosAtCamera = Vector.Dot(primaryRay.Direction, this.data.Camera.Forward); Vector pathWeight = new Vector(1, 1, 1) * cosAtCamera; var eyePoint = this.intersectionFinder.GetIntersectionPoint(primaryRay); Vector pixelColor = new Vector(0, 0, 0); if (eyePoint != null) { if (eyePoint.IsLocatedOnLightSource) { return(eyePoint.Emission); } pathWeight = Vector.Mult(pathWeight, DiffuseBrdf.Evaluate(eyePoint)); //Direct Lighting var lightPoint = data.LightSource.GetRandomPointOnLightSource(rand); if (IsVisible(eyePoint.Position, lightPoint.Position)) { pixelColor += Vector.Mult(pathWeight, lightPoint.Color * GeometryTerm(eyePoint, lightPoint) / lightPoint.PdfA); } //Final Gathering Vector newDirection = DiffuseBrdf.SampleDirection(eyePoint.Normal, rand); pathWeight = pathWeight * Vector.Dot(eyePoint.Normal, newDirection) / DiffuseBrdf.PdfW(eyePoint.Normal, newDirection); var finalGatherPoint = this.intersectionFinder.GetIntersectionPoint(new Ray(eyePoint.Position, newDirection)); if (finalGatherPoint != null) { //100000 3000 1000 float searchRadius = 0.00634257728f * 2;//0.0383904837f;//0.065260686f; var photons = photonmap.SearchPhotons(finalGatherPoint, searchRadius); float kernelFunction = 1.0f / (searchRadius * searchRadius * (float)Math.PI); foreach (var photon in photons) { pixelColor += Vector.Mult(pathWeight, Vector.Mult(DiffuseBrdf.Evaluate(finalGatherPoint), photon.PathWeight) * kernelFunction); } } } return(pixelColor); }
private Vector GetPixelColorFromPhotonmap(int x, int y, Photonmap photonmap) { Ray primaryRay = data.Camera.GetPrimaryRay(x, y); float cosAtCamera = Vector.Dot(primaryRay.Direction, this.data.Camera.Forward); Vector pathWeight = new Vector(1, 1, 1) * cosAtCamera; var eyePoint = this.intersectionFinder.GetIntersectionPoint(primaryRay); Vector pixelColor = new Vector(0, 0, 0); if (eyePoint != null) { //100000 3000 1000 float searchRadius = 0.00634257728f * 2;//0.0383904837f;//0.065260686f; var photons = photonmap.SearchPhotons(eyePoint, searchRadius); float kernelFunction = 1.0f / (searchRadius * searchRadius * (float)Math.PI); foreach (var photon in photons) { pixelColor += Vector.Mult(pathWeight, Vector.Mult(DiffuseBrdf.Evaluate(eyePoint), photon.PathWeight) * kernelFunction); } } return(pixelColor); }