public PathVertex CreatePathVertex(ref RayData ray, ref RayHit rayHit, Sample Sample) { PathVertex result = null; bool missed = rayHit.Index == 0xffffffffu; if (missed) { if (scene.EnvironmentMap == null) { result = new EnvironmentPathVertex() { IncomingDirection = -ray.Dir }; } else { result = new ImplicitLightVertex() { IncomingDirection = -ray.Dir, Light = scene.EnvironmentMap }; } return result; } var hitInfo = surfaceSampler.GetIntersection(ref ray, ref rayHit); var hitPoint = ray.Point(rayHit.Distance); var currentTriangleIndex = (int)rayHit.Index; if (hitInfo.IsLight) { var lt = scene.GetLightByIndex(currentTriangleIndex); result = new ImplicitLightVertex() { IncomingDirection = -ray.Dir, Light = lt, HitItemId = currentTriangleIndex, Point = hitPoint }; } else { Vector wo = -ray.Dir; float fPdf; Vector wi; bool specularBounce; float u0 = Sample.GetLazyValue(), u1 = Sample.GetLazyValue(), u2 = Sample.GetLazyValue(), u3 = Sample.GetLazyValue(); var bsdf = hitInfo.MMaterial; var throughput = RgbSpectrum.Unit; RgbSpectrum f = bsdf.Sample_f(ref wo, out wi, ref hitInfo.Normal, ref hitInfo.ShadingNormal, ref throughput, u0, u1, u2, ref hitInfo.TextureData, out fPdf, out specularBounce); result = new GeometryVertex() { BsdfSampleWeight = fPdf, GeometryNormal = hitInfo.Normal, ShadingNormal = hitInfo.ShadingNormal, HitItemId = currentTriangleIndex, IncomingDirection = wo, OutgoingDirection = wi, Point = hitPoint, Sample = f, u0 = u0, u1 = u1, u2 = u2, u3 = u3, SampledBsdf = bsdf }; } return result; }
public ExplicitLightVertex CreateLightVertex(Sample sample, GeometryVertex vertex) { int currentLightIndex = scene.SampleLights(sample.GetLazyValue()); var light = scene.Lights[currentLightIndex]; var ls = new LightSample(); light.EvaluateShadow(ref vertex.Point, ref vertex.GeometryNormal, sample.GetLazyValue(), sample.GetLazyValue(), sample.GetLazyValue(), ref ls); if (ls.Pdf <= 0f) { throw new Exception(); } /* secRays[tracedShadowRayCount].color = new RgbSpectrum(ls.Spectrum); secRays[tracedShadowRayCount].pdf = ls.Pdf; secRays[tracedShadowRayCount].shadowRay = ls.LightRay; Vector lwi = secRays[tracedShadowRayCount].shadowRay.Dir; RgbSpectrum fs; hitInfo.MMaterial.f( ref secRays[tracedShadowRayCount].shadowRay.Dir, ref wo, ref hitInfo.ShadingNormal, out fs, BrdfType.Diffuse); secRays[tracedShadowRayCount].color *= lightTroughtput * Vector.AbsDot(ref hitInfo.ShadingNormal, ref lwi) * fs; */ return new ExplicitLightVertex() { }; }