本文整理汇总了C#中RayDen.Library.Core.Primitives.RgbSpectrum.Filter方法的典型用法代码示例。如果您正苦于以下问题:C# RgbSpectrum.Filter方法的具体用法?C# RgbSpectrum.Filter怎么用?C# RgbSpectrum.Filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RayDen.Library.Core.Primitives.RgbSpectrum
的用法示例。
在下文中一共展示了RgbSpectrum.Filter方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Advance
//.........这里部分代码省略.........
RgbSpectrum lightTroughtput = Throughput*(RgbSpectrum) bsdf.TexData.Diffuse;
LightSampler.EvaluateShadow(bsdf, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), ref ls);
for (int index = 0; index < ls.Length; index++)
{
if (ls[index].Pdf <= 0f)
continue;
secRays[tracedShadowRayCount].Throughput = ls[index].Spectrum.GetType() == typeof(RgbSpectrumInfo) ? (RgbSpectrum) (RgbSpectrumInfo)ls[index].Spectrum : (RgbSpectrum)ls[index].Spectrum;
secRays[tracedShadowRayCount].Pdf = ls[index].Pdf;
secRays[tracedShadowRayCount].ShadowRay = ls[index].LightRay;
Vector lwi = secRays[tracedShadowRayCount].ShadowRay.Dir;
BsdfEvent devent;
float pdfw, ipdfw;
var fs = (RgbSpectrum)bsdf.Evaluate(ref lwi, out devent, out pdfw, out ipdfw);
if (pdfw < MathLab.Epsilon)
continue;
secRays[tracedShadowRayCount].Throughput *= lightTroughtput * ((fs
* Vector.AbsDot(ref bsdf.HitPoint.ShadingNormal, ref lwi)));
if (!secRays[tracedShadowRayCount].Throughput.IsBlack())
{
#if DEBUG
RayDen.Library.Core.Components.Assert.IsNotNaN(secRays[tracedShadowRayCount].Pdf);
#endif
secRays[tracedShadowRayCount].Pdf *= lightStrategyPdf * pdfw;
secRays[tracedShadowRayCount].Pdf *= scene.ShadowRayCount;
tracedShadowRayCount++;
}
}
}
float fPdf, frPdf;
Vector wi;
RgbSpectrum f;
prevEvent = bsdfEvent;
f =
bsdf.Sample(out wi, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), out fPdf,
out frPdf, out bsdfEvent);
//if (prevEvent.Has(BsdfEvent.Transmit))
//{
// Throughput *= MathLab.Exp(-rayHit.Distance)*0.1f;
//}
if (prevEvent.Has(BsdfEvent.Transmit) && bsdfEvent.Has(BsdfEvent.Transmit))
{
Throughput *= MathLab.Exp(-rayHit.Distance)*0.2f;
}
if ((fPdf <= 0.0f) || f.IsBlack())
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
Throughput *= (f * (RgbSpectrum)bsdf.HitPoint.Color) / fPdf;//* (RgbSpectrum)bsdf.HitPoint.Color
if (depth > scene.MaxPathDepth)
{
float prob = Math.Max(Throughput.Filter(), scene.RussianRuletteImportanceCap);
if (prob >= Sample.GetLazyValue())
{
Throughput /= prob;
}
else
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.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
}
示例2: Advance
//.........这里部分代码省略.........
continue;
secRays[tracedShadowRayCount].Throughput = ls[index].Spectrum.GetType() == typeof(RgbSpectrumInfo) ? (RgbSpectrum) (RgbSpectrumInfo)ls[index].Spectrum : (RgbSpectrum)ls[index].Spectrum;
secRays[tracedShadowRayCount].Pdf = ls[index].Pdf;
secRays[tracedShadowRayCount].ShadowRay = ls[index].LightRay;
Vector lwi = secRays[tracedShadowRayCount].ShadowRay.Dir;
RgbSpectrum fs;
hitInfo.MMaterial.f(ref secRays[tracedShadowRayCount].ShadowRay.Dir, ref wo, ref hitInfo.ShadingNormal, ref Throughput, out fs, types: BrdfType.Diffuse);
secRays[tracedShadowRayCount].Throughput *= lightTroughtput *
Vector.AbsDot(ref hitInfo.Normal, ref lwi) *
fs;
if (!secRays[tracedShadowRayCount].Throughput.IsBlack())
{
#if DEBUG
RayDen.Library.Core.Components.Assert.IsNotNaN(secRays[tracedShadowRayCount].Pdf);
#endif
secRays[tracedShadowRayCount].Pdf /= lightStrategyPdf;
LightSample = ls[index];
tracedShadowRayCount++;
}
}
}
float fPdf = 0f;
var wi = new Vector();
RgbSpectrum f;
hitInfo.TextureData.Throughput = Throughput;
f = bsdf.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 = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
CurrentVertices.Add(new PathVertex()
{
BsdfPdf = fPdf,
Throughput = Throughput,
GeoNormal = hitInfo.Normal,
HitPoint = hitPoint,
HitType = PathVertexType.Geometry,
IncomingDirection = wi,
Material = bsdf,
OutgoingDirection = wo,
RayDistance = rayHit.Distance,
SampleU = rayHit.U,
SampleV = rayHit.V,
ShadingNormal = hitInfo.ShadingNormal,
TexCoords = hitInfo.TexCoords,
rrWeight = 1f,
});
pathWeight *= fPdf;
Throughput *= (f * hitInfo.Color) / fPdf;
if (depth > scene.MaxPathDepth)
{
float prob = Math.Max(Throughput.Filter(), scene.RussianRuletteImportanceCap);
if (prob >= Sample.GetLazyValue())
{
CurrentVertices[CurrentVertices.Count - 1].rrWeight = 1f/prob;
Throughput /= prob;
pathWeight *= prob;
}
else
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.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
}
示例3: Advance
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;
}
//.........这里部分代码省略.........
示例4: Advance
//.........这里部分代码省略.........
Vector wo = -PathRay.Dir;
tracedShadowRayCount = 0;
if (hitInfo.MMaterial.IsDiffuse())
{
float lightStrategyPdf = 1f;// scene.ShadowRayCount / (float)scene.Lights.Length;
RgbSpectrum lightTroughtput = Throughput * hitInfo.Color;
for (int i = 0; i < scene.ShadowRayCount; ++i)
{
int currentLightIndex = scene.SampleLights(Sample.GetLazyValue(depth * 0));
var light = scene.Lights[currentLightIndex];
var ls = new LightSample();
light.EvaluateShadow(ref hitPoint, ref hitInfo.ShadingNormal, Sample.GetLazyValue(depth * 1), Sample.GetLazyValue(depth * 2), Sample.GetLazyValue(depth * 3), ref ls);
if (ls.Pdf <= 0f)
{
continue;
}
secRays[tracedShadowRayCount].color = (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, ref Throughput, out fs, types: BrdfType.Diffuse);
secRays[tracedShadowRayCount].color *= lightTroughtput *
Vector.AbsDot(ref hitInfo.ShadingNormal, ref lwi) *
fs;
if (!secRays[tracedShadowRayCount].color.IsBlack())
{
secRays[tracedShadowRayCount].pdf *= lightStrategyPdf;
tracedShadowRayCount++;
}
}
}
float fPdf;
Vector wi;
RgbSpectrum f = hitInfo.MMaterial.Sample_f(ref wo, out wi, ref hitInfo.Normal, ref hitInfo.ShadingNormal, ref Throughput,
Sample.GetLazyValue(depth * 4), Sample.GetLazyValue(depth * 5),
Sample.GetLazyValue(depth * 6), ref hitInfo.TextureData,
out fPdf, out specularBounce);
if ((fPdf <= 0.0f) || f.IsBlack())
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
pathWeight *= fPdf;
Throughput *= f / fPdf;
if (!mutate)
mutate = Throughput.Filter() > Sample.GetLazyValue(depth*7);
if (depth > scene.MaxPathDepth)
{
float prob = Math.Max(Throughput.Filter(), scene.RussianRuletteImportanceCap);
if (prob >= Sample.GetLazyValue(depth * 8))
{
Throughput /= prob;
pathWeight *= prob;
}
else
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.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
}
示例5: Advance
//.........这里部分代码省略.........
}
currentTriangleIndex = (int)rayHit.Index;
if (hitInfo == null)
{
Debugger.Break();
}
Vector wo = -PathRay.Dir;
var hitPoint = PathRay.Point(rayHit.Distance);
//If Hit light)
if (hitInfo.IsLight)
{
//if (specularBounce || depth == 1)
{
var lt = scene.GetLightByIndex(currentTriangleIndex);
if (lt != null)
{
var le = (RgbSpectrum)(lt.Le(ref wo));
Throughput *= le;
AddEyeRay(ref hitPoint, ref wo, ref Throughput, 1f);
PathState = PathTracerPathState.ShadowRaysOnly;
return;
}
}
}
var bsdf = hitInfo.MMaterial;
if (bsdf.IsDiffuse())
{
float lightStrategyPdf = 1f;
//scene.ShadowRaysPerSample/(float)scene.Lights.Length;
var lightTroughtput = Throughput*hitInfo.Color;
AddEyeRay(ref hitPoint, ref wo, ref lightTroughtput, lightStrategyPdf );
}
float fPdf = 0f;
var wi = new Vector();
RgbSpectrum f;
f = bsdf.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)*hitInfo.Color;
if ((fPdf <= 0.0f) || f.IsBlack())
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
pathWeight *= fPdf;
Throughput *= f / 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 = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.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
}
示例6: Advance
//.........这里部分代码省略.........
var bsdf = hitInfo.MMaterial;
if (!hitInfo.TextureData.Alpha.IsBlack())
{
Throughput *= (RgbSpectrum.UnitSpectrum() - (RgbSpectrum)hitInfo.TextureData.Alpha);
PathRay = new RayData(hitPoint, -wo);
return;
}
if (bsdf.IsDiffuse())
{
float lightStrategyPdf = LightSampler.StrategyPdf;
//scene.ShadowRaysPerSample/(float)scene.Lights.Length;
RgbSpectrum lightTroughtput = Throughput * hitInfo.Color;
LightSampler.EvaluateShadow(ref hitPoint, ref hitInfo.Normal, Sample.GetLazyValue(),
Sample.GetLazyValue(), Sample.GetLazyValue(), ref ls);
for (int index = 0; index < ls.Length; index++)
{
if (ls[index].Pdf <= 0f)
continue;
secRays[tracedShadowRayCount].Throughput = ls[index].Spectrum.GetType() == typeof(RgbSpectrumInfo) ? (RgbSpectrum)(RgbSpectrumInfo)ls[index].Spectrum : (RgbSpectrum)ls[index].Spectrum;
secRays[tracedShadowRayCount].Pdf = ls[index].Pdf;
secRays[tracedShadowRayCount].ShadowRay = ls[index].LightRay;
Vector lwi = secRays[tracedShadowRayCount].ShadowRay.Dir;
RgbSpectrum fs;
hitInfo.MMaterial.f(ref secRays[tracedShadowRayCount].ShadowRay.Dir, ref wo, ref hitInfo.ShadingNormal, ref Throughput, out fs, types: BrdfType.Diffuse);
secRays[tracedShadowRayCount].Throughput *= lightTroughtput *
Vector.AbsDot(ref hitInfo.Normal, ref lwi) *
fs;
if (!secRays[tracedShadowRayCount].Throughput.IsBlack())
{
#if DEBUG
RayDen.Library.Core.Components.Assert.IsNotNaN(secRays[tracedShadowRayCount].Pdf);
#endif
secRays[tracedShadowRayCount].Pdf /= lightStrategyPdf;
tracedShadowRayCount++;
}
}
}
float fPdf = 0f;
var wi = new Vector();
RgbSpectrum f;
hitInfo.TextureData.Throughput = Throughput;
f = bsdf.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 = PathTracerPathState.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 = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.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
}
示例7: Advance
public override void Advance(RayBuffer rayBuffer, SampleBuffer consumer)
{
int currentTriangleIndex = 0;
#if VERBOSE
try {
#endif
base.Advance(rayBuffer, consumer);
var rayHit = rayBuffer.rayHits[RayIndex];
depth++;
var missed = rayHit.Index == 0xffffffffu;
var wo = -PathRay.Dir;
if (missed || depth > scene.MaxPathDepth)
{
if (specularBounce && missed)
{
Radiance += this.scene.SampleEnvironment(ref wo) * 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 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);
tracedShadowRayCount = 0;
float fPdf;
Vector wi;
var 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())
{
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
{
Splat(consumer);
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
#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);
//.........这里部分代码省略.........
示例8: AdvanceNewPath
//.........这里部分代码省略.........
{
Debugger.Break();
}
//If Hit light)
if (hitInfo.IsLight)
{
//if (bsdfEvent.Has(BsdfEvent.Specular) || depth == 1)
{
var lt = scene.GetLightByIndex(currentTriangleIndex);
if (lt != null)
{
float pdf;
var le = hitInfo.Color * lt.Emittance(ref wo, out pdf);
//Radiance += Throughput * le;
if (!le.IsBlack())
mutate = true;
Radiance.MAdd(ref Throughput, ref le);
}
}
Splat(consumer);
return;
}
var hitPoint = PathRay.Point(rayHit.Distance);
vertex.HitPoint = hitPoint;
tracedShadowRayCount = 0;
if (!hitInfo.TextureData.Alpha.IsBlack())
{
Throughput *= (RgbSpectrum.UnitSpectrum() - (RgbSpectrum)hitInfo.TextureData.Alpha);
PathRay = new RayData(hitPoint, -wo);
return;
}
float fPdf;
Vector wi;
RgbSpectrum f;
hitInfo.TextureData.Throughput = Throughput;
prevEvent = bsdfEvent;
f = bsdf.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 bsdfEvent);
//if (prevEvent.Has(BsdfEvent.Transmit) && bsdfEvent.Has(BsdfEvent.Transmit))
//{
// Throughput *= MathLab.Exp(-rayHit.Distance) * 0.2f;
//}
vertex.BsdfSample = f;
vertex.BsdfWeight = fPdf;
vertex.Event = bsdfEvent;
vertex.Wo = wo;
vertex.Wi = wi;
vertex.ShadeNormal = hitInfo.ShadingNormal;
if ((fPdf <= 0.0f) || f.IsBlack())
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
Throughput *= (f * hitInfo.Color) / fPdf;
pathDensity *= fPdf;
if (depth > scene.MaxPathDepth)
{
float prob = Math.Max(Throughput.Filter(), scene.RussianRuletteImportanceCap);
if (prob >= Sample.GetLazyValue())
{
Throughput /= prob;
pathDensity *= prob;
}
else
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.NextVertex;
}
示例9: Advance
//.........这里部分代码省略.........
Vector wo = -PathRay.Dir;
float fPdf;
Vector wi;
float u0 = Sample.GetLazyValue(), u1 = Sample.GetLazyValue(), u2 = Sample.GetLazyValue();
RgbSpectrum f = hitInfo.Material.Sample_f(ref wo, out wi, ref hitInfo.Normal, ref hitInfo.ShadingNormal,
u0, u1, u2,
out fPdf, out specularBounce) * hitInfo.Color;
vertices[currentVertice] = new GeometryPathElement()
{
HitInfo = hitInfo,
HitPoint = hitPoint,
BsdfSample = new BsdfSample()
{
SampleData = new[] { u0, u1, u2 },
Wi = wi,
Pdf = fPdf,
Spectrum = f.ToArray(),
SpecularBounce = specularBounce
}
};
if (hitInfo.Material.IsDiffuse())
{
float lightStrategyPdf = scene.ShadowRayCount / (float)scene.Lights.Length;
RgbSpectrum lightTroughtput = Throughput * hitInfo.Color;
for (int i = 0; i < scene.ShadowRayCount; ++i)
{
int currentLightIndex = scene.SampleLights(Sample.GetLazyValue());
var light = scene.Lights[currentLightIndex];
var ls = new LightSample();
light.EvaluateShadow(ref hitPoint, ref hitInfo.ShadingNormal, Sample.GetLazyValue(), Sample.GetLazyValue(), Sample.GetLazyValue(), out ls);
if (ls.Pdf <= 0f)
{
continue;
}
connections[tracedShadowRayCount].Throughput = new RgbSpectrum(ls.Spectrum);
connections[tracedShadowRayCount].Pdf = ls.Pdf;
connections[tracedShadowRayCount].Ray = ls.LightRay;
Vector lwi = connections[tracedShadowRayCount].Ray.Dir;
connections[tracedShadowRayCount].Throughput *= lightTroughtput *
Vector.AbsDot(ref hitInfo.ShadingNormal, ref lwi) *
hitInfo.Material.f(
ref connections[tracedShadowRayCount].Ray.Dir,
ref wo, ref hitInfo.ShadingNormal);
if (!connections[tracedShadowRayCount].Throughput.IsBlack())
{
connections[tracedShadowRayCount].Pdf *= lightStrategyPdf;
tracedShadowRayCount++;
}
}
}
if ((fPdf <= 0.0f) || f.IsBlack())
{
PathState = GenericPathSamplerState.Connection;
return;
}
pathWeight *= fPdf;
Throughput *= f / fPdf;
if (depth > scene.MaxPathDepth)
{
float prob = Math.Max(Throughput.Filter(), scene.RussianRuletteImportanceCap);
if (prob >= Sample.GetLazyValue())
{
Throughput /= prob;
pathWeight *= prob;
}
else
{
PathState = GenericPathSamplerState.Connection;
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
this.PathState = GenericPathSamplerState.Sampling;
#if VERBOSE
}
catch (Exception ex)
{
Console.WriteLine("Advance path exception");
Console.WriteLine("Error triangle {0}", currentTriangleIndex);
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
#endif
}
示例10: Advance
//.........这里部分代码省略.........
}
if (rs > 0)
{
for (int index = 0; index < secRays.Length; index++)
{
secRays[index].Pdf /= (1f+rs);
}
}
}
float fPdf = 0f;
var wi = new Vector();
RgbSpectrum f;
if (depth > 1)
{
f = bsdf.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);
}
else
{
int samplesCount = 4;
var bsdfData = new Tuple<Vector, float, RgbSpectrum>[samplesCount];
var totalF = new RgbSpectrum();
float totalPdf =0;
for (int i = 0; i < samplesCount; i++)
{
Vector Wi;
float pdf;
var Fr = bsdf.Sample_f(ref wo, out Wi, ref hitInfo.Normal, ref hitInfo.ShadingNormal, ref Throughput,
Sample.GetLazyValue(), Sample.GetLazyValue(),
Sample.GetLazyValue(), ref hitInfo.TextureData,
out pdf, out specularBounce);
totalF += Fr;
totalPdf += pdf;
bsdfData[i] = new Tuple<Vector, float, RgbSpectrum>(Wi, pdf, Fr);
}
var bsdfSamples = bsdfData.OrderBy(i => i.Item2).ToArray();
fPdf = bsdfSamples[0].Item2;
wi = bsdfSamples[0].Item1;
f = totalF/4f;
}
if ((fPdf <= 0.0f) || f.IsBlack())
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.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 = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.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
}
示例11: Advance
//.........这里部分代码省略.........
var hitPoint = PathRay.Point(rayHit.Distance);
tracedShadowRayCount = 0;
var bsdf = hitInfo.MMaterial;
if (bsdf.IsDiffuse())
{
float lightStrategyPdf = LightSampler.StrategyPdf;
//scene.ShadowRaysPerSample/(float)scene.Lights.Length;
RgbSpectrum lightTroughtput = Throughput * hitInfo.Color;
LightSampler.EvaluateShadow(ref hitPoint, ref hitInfo.Normal, Sample.GetLazyValue(depth * 5),
Sample.GetLazyValue(depth * 6), Sample.GetLazyValue(depth * 7), ref ls);
for (int index = 0; index < ls.Length; index++)
{
if (ls[index].Pdf <= 0f)
continue;
secRays[tracedShadowRayCount].Throughput = (RgbSpectrum)(RgbSpectrumInfo)(ls[index].Spectrum);
secRays[tracedShadowRayCount].Pdf = ls[index].Pdf;
secRays[tracedShadowRayCount].ShadowRay = ls[index].LightRay;
Vector lwi = secRays[tracedShadowRayCount].ShadowRay.Dir;
RgbSpectrum fs;
hitInfo.MMaterial.f(ref secRays[tracedShadowRayCount].ShadowRay.Dir, ref wo, ref hitInfo.ShadingNormal, ref Throughput, out fs);
secRays[tracedShadowRayCount].Throughput *= lightTroughtput *
Vector.AbsDot(ref hitInfo.Normal, ref lwi) *
fs;
if (!secRays[tracedShadowRayCount].Throughput.IsBlack())
{
#if DEBUG
RayDen.Library.Core.Components.Assert.IsNotNaN(secRays[tracedShadowRayCount].Pdf);
#endif
secRays[tracedShadowRayCount].Pdf /= lightStrategyPdf;
tracedShadowRayCount++;
}
}
}
float fPdf;
Vector wi;
RgbSpectrum f = hitInfo.MMaterial.Sample_f(ref wo, out wi, ref hitInfo.Normal, ref hitInfo.ShadingNormal, ref Throughput,
Sample.GetLazyValue(depth * 1), Sample.GetLazyValue(depth * 2),
Sample.GetLazyValue(depth * 3), ref hitInfo.TextureData,
out fPdf, out specularBounce);
if ((fPdf <= 0.0f) || f.IsBlack())
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
Throughput *= (f * hitInfo.Color) / fPdf;
if (depth > scene.MaxPathDepth)
{
float prob = Math.Max(Throughput.Filter(), scene.RussianRuletteImportanceCap);
if (prob >= Sample.GetLazyValue(depth * 4))
{
Throughput /= prob;
}
else
{
if (tracedShadowRayCount > 0)
PathState = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.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
}
示例12: Advance
//.........这里部分代码省略.........
Vector lwi = secRays[tracedShadowRayCount].ShadowRay.Dir;
RgbSpectrum fs;
hitInfo.MMaterial.f(ref secRays[tracedShadowRayCount].ShadowRay.Dir, ref wo, ref hitInfo.ShadingNormal, ref lightTroughtput, out fs, BrdfType.Diffuse);
secRays[tracedShadowRayCount].Throughput *= lightTroughtput *
Vector.AbsDot(ref hitInfo.Normal, ref lwi) *
fs;
if (!secRays[tracedShadowRayCount].Throughput.IsBlack())
{
secRays[tracedShadowRayCount].Pdf /= lightStrategyPdf;
tracedShadowRayCount++;
}
}
#endif
for (int index = 0; index < currentLightVertex; index++)
{
if (lightVertices[index].Throughput.IsBlack())
continue;
var lwi = lightVertices[index].Wi;
RgbSpectrum fs;
hitInfo.MMaterial.f(ref lwi, ref wo, ref hitInfo.ShadingNormal, ref Throughput, out fs, types: BrdfType.Diffuse);
var dir = lightVertices[index].HitPoint - hitPoint;
var dirLength = dir.Length;
dir.NormalizeSelf();
secRays[tracedShadowRayCount].Throughput = Throughput*lightVertices[index].Throughput
*fs
*lightVertices[index].BsdfSample
//* Vector.AbsDot(ref hitInfo.Normal, ref lwi)
*Geometry.G(ref hitPoint, ref lightVertices[index].HitPoint,ref hitInfo.Normal,ref lightVertices[index].Normal);
secRays[tracedShadowRayCount].Pdf = (pathWeight*lightVertices[index].dAWeight)
;
// * Geometry.G(ref hitPoint, ref lightVertices[index].HitPoint, ref hitInfo.Normal, ref lightVertices[index].Normal);
//1f/(depth+index) * (pathWeight*lightVertices[index].dAWeight);
secRays[tracedShadowRayCount].ShadowRay = new RayData(ref hitPoint, ref dir, 1e-4f, dirLength-1e-4f);
tracedShadowRayCount++;
}
}
float fPdf = 0f;
var wi = new Vector();
RgbSpectrum f;
f = bsdf.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 = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
pathWeight *= fPdf;
Throughput *= (f) / 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 = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.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
}
示例13: Advance
//.........这里部分代码省略.........
}
@errro:
var hitPoint = PathRay.Point(rayHit.Distance);
tracedShadowRayCount = 0;
if (_hitInfo.MMaterial.IsDiffuse())
{
float lightStrategyPdf = scene.ShadowRayCount / (float)scene.Lights.Length;
RgbSpectrum lightTroughtput = Throughput * _hitInfo.Color;
for (int i = 0; i < scene.ShadowRaysPerSample; ++i)
{
int currentLightIndex = scene.SampleLights(Sample.GetLazyValue());
var light = scene.Lights[currentLightIndex];
var ls = new LightSample();
light.EvaluateShadow(ref hitPoint, ref _hitInfo.ShadingNormal, Sample.GetLazyValue(),
Sample.GetLazyValue(), Sample.GetLazyValue(), ref ls);
if (ls.Pdf <= 0f)
{
continue;
}
secRays[tracedShadowRayCount].color = ls.Spectrum.GetType() == typeof(RgbSpectrumInfo) ? (RgbSpectrum)(RgbSpectrumInfo)ls.Spectrum : (RgbSpectrum)ls.Spectrum;
secRays[tracedShadowRayCount].pdf = ls.Pdf;
secRays[tracedShadowRayCount].shadowRay = ls.LightRay;
RgbSpectrum fs;
_hitInfo.MMaterial.f(
ref secRays[tracedShadowRayCount].shadowRay.Dir,
ref wo, ref _hitInfo.ShadingNormal, ref Throughput, out fs);
Vector lwi = secRays[tracedShadowRayCount].shadowRay.Dir;
secRays[tracedShadowRayCount].color *= lightTroughtput *
Vector.AbsDot(ref _hitInfo.ShadingNormal, ref lwi) *
fs;
if (!secRays[tracedShadowRayCount].color.IsBlack())
{
secRays[tracedShadowRayCount].pdf *= lightStrategyPdf;
tracedShadowRayCount++;
}
}
}
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 = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
pathWeight *= fPdf;
Throughput *= f / 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 = PathTracerPathState.ShadowRaysOnly;
else
{
Splat(consumer);
}
return;
}
}
PathRay.Org = hitPoint;
PathRay.Dir = wi.Normalize();
PathState = PathTracerPathState.NextVertex;
#if VERBOSE
}
catch (Exception ex)
{
RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.Message);
RayDen.Library.Components.SystemComponents.Tracer.TraceLine(ex.StackTrace);
throw;
}
#endif
}