public override void InitPath(IPathProcessor buffer) { base.InitPath(buffer); maxDepth = Buffer.Scene.MaxPathDepth; RussianRuletteImportanceCap = Buffer.Scene.RussianRuletteImportanceCap; this.Radiance = ColorManager.Instance.Zero(); this.Throughput = ColorManager.Instance.Unit(); this.PathState = PurePathTracerPathState.EyeVertex; //if (this.secRays == null) this.secRays = new PurePathTracerPath.ShadowRayInfo[scene.ShadowRayCount]; this.Sample = Buffer.Sampler.GetSample(this.Sample); IRay ray; Buffer.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out ray); this.PathRay = (RayData)ray; this.RayIndex = -1; //this.pathWeight = 1.0f; this.tracedShadowRayCount = 0; this.Depth = 0; this.specularBounce = true; }
public override void InitPath(IPathProcessor buffer) { base.InitPath(buffer); this.scene = pathIntegrator.Scene; this.Radiance = new RgbSpectrum(0f); this.Throughput = new RgbSpectrum(1f); this.PathState = PurePathTracerPathState.EyeVertex; if (this.secRays == null) this.secRays = new ShadowRayInfo[scene.ShadowRayCount]; this.Sample = pathIntegrator.Sampler.GetSample(this.Sample); IRay ray; pathIntegrator.Scene.Camera.GetRay(Sample.imageX, Sample.imageY, out ray); this.PathRay = (RayData)ray; this.RayIndex = -1; this.pathWeight = 1.0f; this.tracedShadowRayCount = 0; this.depth = 0; this.specularBounce = true; }
public override void Advance(RayBuffer rayBuffer, SampleBuffer consumer) { int currentTriangleIndex = 0; #if VERBOSE try { #endif base.Advance(rayBuffer, consumer); RayHit rayHit = rayBuffer.rayHits[RayIndex]; Depth++; bool missed = rayHit.Index == 0xffffffffu; var wo = -PathRay.Dir; if (missed || Depth > maxDepth) { if (specularBounce && missed) { Radiance.Add(Throughput.Mul(ColorManager.Instance.Convert(this.SampleEnvironment(ref wo)))); } Splat(consumer); return; } HitManager.Instance.EvalHit(ref PathRay, ref rayHit, ref hitInfo); currentTriangleIndex = (int)rayHit.Index; //If Hit light) if (hitInfo.PointType == ShadePointType.Light) { float lpdf; var lt = this.Buffer.SceneManager.GetLightById(hitInfo.ObjectId); var le = lt.Light.Emit(ref wo, out lpdf); Radiance.Add(Throughput.Mul(le)); Splat(consumer); return; } var hitPoint = PathRay.Point(rayHit.Distance); tracedShadowRayCount = 0; float fPdf; Vector wi; float f; BsdfEvent @event; hitInfo.Brdf.Sample_f(hitInfo, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), out wi, out f, out fPdf, out @event); if ((fPdf <= 0.0f) || f<=0f) { if (tracedShadowRayCount > 0) PathState = PurePathTracerPathState.ShadowRaysOnly; else { Splat(consumer); } return; } Throughput.Mul(hitInfo.GetColorInstance()).Mul(f / fPdf); if (Depth > maxDepth) { float prob = Math.Max(Throughput.Filter(), RussianRuletteImportanceCap); if (prob >= Sample.GetLazyValue()) { Throughput.Mul(1f / prob); } else { if (tracedShadowRayCount > 0) PathState = PurePathTracerPathState.ShadowRaysOnly; else { Splat(consumer); } return; } } PathRay.Org = hitPoint; PathRay.Dir = wi.Normalize(); PathState = PurePathTracerPathState.NextVertex; #if VERBOSE } catch (Exception ex) { RayDen.Library.Components.SystemComponents.Tracer.TraceLine("Advance path exception"); RayDen.Library.Components.SystemComponents.Tracer.TraceLine("Error triangle {0}", currentTriangleIndex); RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.Message); RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.StackTrace); } #endif }
public override void Advance(RayBuffer rayBuffer, SampleBuffer consumer) { int currentTriangleIndex = 0; #if VERBOSE try { #endif base.Advance(rayBuffer, consumer); RayHit rayHit = rayBuffer.rayHits[RayIndex]; depth++; bool missed = rayHit.Index == 0xffffffffu; if (missed || depth > scene.MaxPathDepth) { if (missed) { vertices[currentVertex].Event = BsdfEvent.Environment; vertices[currentVertex++].ThroughtPut = this.SampleEnvironment(PathRay.Dir); } Splat(consumer); return; } if (hitInfo == null) { hitInfo = SurfaceSampler.GetIntersection(ref PathRay, ref rayHit); } else { SurfaceSampler.GetIntersection(ref PathRay, ref rayHit, ref hitInfo); } currentTriangleIndex = (int)rayHit.Index; if (hitInfo.IsLight) { { var lt = scene.GetLightByIndex(currentTriangleIndex); //if (lt != null) { var le = (RgbSpectrum)(RgbSpectrumInfo)(lt.Le(ref PathRay.Dir)); vertices[currentVertex].Event = BsdfEvent.Light; vertices[currentVertex++].ThroughtPut = le; } } Splat(consumer); return; } var hitPoint = PathRay.Point(rayHit.Distance); vertices[currentVertex].HitPoint = hitPoint; Vector wo = -PathRay.Dir; tracedShadowRayCount = 0; float fPdf; Vector wi; BsdfEvent @evt; RgbSpectrum f = hitInfo.MMaterial.Sample_f(ref wo, out wi, ref hitInfo.Normal, ref hitInfo.ShadingNormal, ref Throughput, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), ref hitInfo.TextureData, out fPdf, out @evt); specularBounce = evt.Has(BsdfEvent.Specular); if ((fPdf <= 0.0f) || f.IsBlack()) { if (tracedShadowRayCount > 0) PathState = PurePathTracerPathState.ShadowRaysOnly; else { vertices[currentVertex].Event = BsdfEvent.Absorb; Splat(consumer); } return; } pathWeight *= fPdf; Throughput *= (f * hitInfo.Color) / fPdf; vertices[currentVertex].HitPoint = hitPoint; vertices[currentVertex].Wi = wi; vertices[currentVertex].Wo = wo; vertices[currentVertex].ShadeNormal = hitInfo.ShadingNormal; vertices[currentVertex].TriangleIndex = currentTriangleIndex; vertices[currentVertex].Bsdf = hitInfo.MMaterial; vertices[currentVertex].Event = @evt; vertices[currentVertex].BsdfSample = f; vertices[currentVertex].BsdfWeight = fPdf; vertices[currentVertex].ThroughtPut = (f * hitInfo.Color) / fPdf; if (depth > scene.MaxPathDepth) { float prob = Math.Max(Throughput.Filter(), scene.RussianRuletteImportanceCap); if (prob >= Sample.GetLazyValue()) { Throughput /= prob; vertices[currentVertex].ThroughtPut/=prob; vertices[currentVertex].RRProbability = 1f / prob; pathWeight *= prob; } else { if (tracedShadowRayCount > 0) PathState = PurePathTracerPathState.ShadowRaysOnly; else { vertices[currentVertex].Event = BsdfEvent.Absorb; Splat(consumer); } return; } } PathRay.Org = hitPoint; PathRay.Dir = wi.Normalize(); PathState = PurePathTracerPathState.NextVertex; currentVertex++; #if VERBOSE } catch (Exception ex) { RayDen.Library.Components.SystemComponents.Tracer.TraceLine("Advance path exception"); RayDen.Library.Components.SystemComponents.Tracer.TraceLine("Error triangle {0}", currentTriangleIndex); RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.Message); RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.StackTrace); } #endif }
public sealed override void Advance(RayBuffer rayBuffer, SampleBuffer consumer) { int currentTriangleIndex = 0; #if VERBOSE try { #endif base.Advance(rayBuffer, consumer); RayHit rayHit = rayBuffer.rayHits[RayIndex]; Depth++; bool missed = rayHit.Index == 0xffffffffu; var wo = -PathRay.Dir; vertices[Depth-1].Wo = wo; if (missed || Depth > maxDepth) { if (specularBounce && missed) { vertices[Depth-1].Event = BsdfEvent.Environment; } Splat(consumer); return; } HitManager.Instance.EvalHit(ref PathRay, ref rayHit, ref hitInfo); //If Hit light) if (hitInfo.PointType == ShadePointType.Light) { var lt = this.Buffer.SceneManager.GetLightById(hitInfo.ObjectId); vertices[Depth - 1].Event = BsdfEvent.Light; vertices[Depth - 1].Light = lt.Light; Splat(consumer); return; } var hitPoint = PathRay.Point(rayHit.Distance); tracedShadowRayCount = 0; float fPdf; Vector wi; float f; BsdfEvent @event; hitInfo.Brdf.Sample_f(hitInfo, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), out wi, out f, out fPdf, out @event); vertices[Depth - 1].Brdf = hitInfo.Brdf; vertices[Depth - 1].Event = @event; vertices[Depth - 1].Ng = hitInfo.GeoNormal; vertices[Depth - 1].Ns = hitInfo.ShadingNormal; vertices[Depth - 1].Pdf = fPdf; vertices[Depth - 1].RadiancePdf = f; vertices[Depth - 1].RrPdf = 1f; vertices[Depth - 1].Color = hitInfo.GetColorInstance(); if ((fPdf <= 0.0f) || f<=0f) { if (tracedShadowRayCount > 0) PathState = PurePathTracerPathState.ShadowRaysOnly; else { vertices[Depth - 1].Event = BsdfEvent.Absorb; Splat(consumer); } return; } throughput *= vertices[Depth - 1].RadiancePdf/fPdf; if (Depth > maxDepth) { float prob = Math.Max(throughput, RussianRuletteImportanceCap); if (prob >= Sample.GetLazyValue()) { vertices[Depth - 1].RrPdf *= (1f / prob); } else { if (tracedShadowRayCount > 0) PathState = PurePathTracerPathState.ShadowRaysOnly; else { vertices[Depth - 1].Event = BsdfEvent.Absorb; Splat(consumer); } return; } } vertices[Depth - 1].Wi = wi; vertices[Depth - 1].Point = hitPoint; PathRay.Org = hitPoint; PathRay.Dir = wi.Normalize(); PathState = PurePathTracerPathState.NextVertex; #if VERBOSE } catch (Exception ex) { RayDen.Library.Components.SystemComponents.Tracer.TraceLine("Advance path exception"); RayDen.Library.Components.SystemComponents.Tracer.TraceLine("Error triangle {0}", currentTriangleIndex); RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.Message); RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.StackTrace); } #endif }
public override void Advance(RayBuffer rayBuffer, SampleBuffer consumer) { int currentTriangleIndex = 0; #if VERBOSE try { #endif base.Advance(rayBuffer, consumer); RayHit rayHit = rayBuffer.rayHits[RayIndex]; depth++; bool missed = rayHit.Index == 0xffffffffu; if (missed || depth > scene.MaxPathDepth) { if (specularBounce && missed) { Radiance += this.SampleEnvironment(PathRay.Dir) * Throughput; } Splat(consumer); return; } // Something was hit if (hitInfo == null) { hitInfo = SurfaceSampler.GetIntersection(ref PathRay, ref rayHit); } else { SurfaceSampler.GetIntersection(ref PathRay, ref rayHit, ref hitInfo); } currentTriangleIndex = (int)rayHit.Index; if (hitInfo == null) { Debugger.Break(); } //If Hit light) if (hitInfo.IsLight) { { var lt = scene.GetLightByIndex(currentTriangleIndex); if (lt != null) { var le = (RgbSpectrum)(RgbSpectrumInfo)(lt.Le(ref PathRay.Dir)); Radiance += Throughput * le; } } Splat(consumer); return; } var hitPoint = PathRay.Point(rayHit.Distance); Vector wo = -PathRay.Dir; tracedShadowRayCount = 0; float fPdf; Vector wi; RgbSpectrum f = hitInfo.MMaterial.Sample_f(ref wo, out wi, ref hitInfo.Normal, ref hitInfo.ShadingNormal, ref Throughput, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), ref hitInfo.TextureData, out fPdf, out specularBounce); if ((fPdf <= 0.0f) || f.IsBlack()) { if (tracedShadowRayCount > 0) PathState = PurePathTracerPathState.ShadowRaysOnly; else { Splat(consumer); } return; } pathWeight *= fPdf; Throughput *= (f * hitInfo.Color) / fPdf; if (depth > scene.MaxPathDepth) { float prob = Math.Max(Throughput.Filter(), scene.RussianRuletteImportanceCap); if (prob >= Sample.GetLazyValue()) { Throughput /= prob; pathWeight *= prob; } else { if (tracedShadowRayCount > 0) PathState = PurePathTracerPathState.ShadowRaysOnly; else { Splat(consumer); } return; } } PathRay.Org = hitPoint; PathRay.Dir = wi.Normalize(); PathState = PurePathTracerPathState.NextVertex; #if VERBOSE } catch (Exception ex) { RayDen.Library.Components.SystemComponents.Tracer.TraceLine("Advance path exception"); RayDen.Library.Components.SystemComponents.Tracer.TraceLine("Error triangle {0}", currentTriangleIndex); RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.Message); RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.StackTrace); } #endif }