public override void Splat(SampleBuffer sampleBuffer) { var waveLengthWeight = 1f/(SpectralSamplingHelper.SpectralSamples); lambdas[lambdaSample]=(HeroWavelength); wls[lambdaSample] = (waveRadiance)* waveLengthWeight; lambdaSample++; if (lambdaSample >= SpectralSamplingHelper.SpectralSamples) { var lb = lambdas.ToList(); lb.Sort(); lambdas = lb.ToArray(); var spd = new IrregularSPD(lambdas, wls, SpectralSamplingHelper.SpectralSamples, SpectralSamplingHelper.SpectralResolution, SPDResamplingMethod.Linear); //var spd = new RegularSPD(wls, SampledSpectrum.sampledLambdaStart,SampledSpectrum.sampledLambdaEnd, WaveLengthSampler.SpectralSamples); var pix = //ColorFactory.ToRgb(spd); spd.ToRgb(); sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref pix); lambdaSample = 0; } this.InitPath(pathIntegrator); }
public override void Splat(SampleBuffer sampleBuffer) { var waveLengthWeight = 1f/ (SpectralSamplingHelper.SpectralSamples); lambdas[lambdaSample] = (HeroWavelength); wls[lambdaSample] = (waveRadiance / waveLengthWeight); rs += waveRadiance; lambdaSample++; if (lambdaSample >= SpectralSamplingHelper.SpectralSamples) { RgbSpectrum pix = RgbSpectrum.ZeroSpectrum(); if (rs > 0f) { #if RandomWavelength var lb = lambdas.ToList(); lb.Sort(); lambdas = lb.ToArray(); #endif var spd = new IrregularSPD(lambdas, wls, SpectralSamplingHelper.SpectralSamples, SpectralSamplingHelper.SpectralResolution, SPDResamplingMethod.Linear); //var spd = new RegularSPD(wls, SampledSpectrum.sampledLambdaStart, SampledSpectrum.sampledLambdaEnd,SpectralSamplingHelper.SpectralSamples); spd.Normalize(); pix = //ColorFactory.ToRgb(spd); spd.ToRgb(); } sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref pix); rs = 0; lambdaSample = 0; } this.InitPath(pathIntegrator); }
private void Splat(SampleBuffer smb, float x, float y, ref RgbSpectrum rad) { if (x < 0 || y < 0) return; if (x > 1280 || y > 720) return; smb.SplatSample(x, y, ref rad); }
public override void Splat(SampleBuffer sampleBuffer) { if (!this.Radiance.IsBlack()) { var rgb = new RgbSpectrum();//= this.Radiance.ToXyz(); this.Radiance.TransformToRgb(out rgb); sampleBuffer.SplatSample((float)this.Sample.imageX, (float)this.Sample.imageY, ref rgb); } InitPath(this.Buffer); }
public override void Splat(SampleBuffer sampleBuffer) { #if VERBOSE this.pathIntegrator.splattedCount++; #endif if (State == RayTracerPathState.OnlyShadow || State == RayTracerPathState.Eye || depth >= scene.MaxPathDepth) { if (Radiance.IsBlack() && Throughput.Average < 0.99f) { Radiance += Throughput * hitInfo.Color; } sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref this.Radiance); } this.InitPath(pathIntegrator); }
public virtual void Splat(SampleBuffer<IColorType> sampleBuffer) { Radiance = new RgbColor(Processor.samplers.PrimarySpaceSampler.GetSample()); sampleBuffer.SplatSample(imageSample.X, imageSample.Y, ref Radiance); }
public override void Splat(SampleBuffer sampleBuffer) { //Check tentative prob //Add contribution //Change state // Change sample state in init by ChangedState var yImportance = sampler.EvalImportance(ref Throughput, pathWeight); float sampleWeight = yImportance; if (yImportance<=0f) goto @init; var yContribution = Radiance / yImportance; bool accept; float a = 0f; if (!sampler.ImportanceReady) { sampler.Add_B(ref yContribution); sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref Radiance); this.InitPath(this.pathIntegrator); return; } if (yImportance > 0f) { if ((SamplerState != MCMCSamplerState.SmallStep || xImportance <= 0f || mutate)) { SwitchToSmallStep(yImportance, pathWeight, ref yContribution); goto init; //Print(string.Format("{0} changed state to {1}", this.SamplerID, this.SamplerState)); } else if (SamplerState == MCMCSamplerState.SmallStep) { a = Math.Min(1f, (yImportance/xImportance)); //contrib = (contrib / sampler.Importance) / sampler.MaxMutations; sampleWeight = a; this.mutationsCount++; if (sampler.NextFloat() < a) { xImportance = yImportance; this.xContribution = yContribution; //this.TentativeSample = new Sample(this.Sample); Push(); accept = true; //this.pathWeight = a; } else { if (!this.Pop()) { //Print("Chain restart - stack empty - mutations " + mutationsCount); //sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref contrib, 1f-a); this.Sample = new Sample(this.TentativeSample); rejectCount++; this.pathWeight = this.TentativeWeight; } //Splat = false; //return; } /* * */ //var newSample = sampler.GetNextSample(this.Sample, I, oldI, 1.0f, ref contrib, out outC, out newW, false); } } else if (xImportance >= 0f && this.SamplerState == MCMCSamplerState.SmallStep) { if (!this.Pop()) { if (this.TentativeSample != null) { //Print("Chain restart - stack empty - mutations " + mutationsCount); //sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref contrib, 1f-a); this.Sample = new Sample(this.TentativeSample); rejectCount++; this.pathWeight = this.TentativeWeight; } else { this.SamplerState = MCMCSamplerState.LargeStep; } } } if (!xContribution.IsBlack()) { //sampleWeight *= 1f/pathWeight; //contrib *= (1f/sampler.MaxMutations); //contrib *= new RgbSpectrum((float)this.sampler.B[0],(float)this.sampler.B[1],(float)this.sampler.B[2]); var contribution = xContribution; /* if (accept) { contribution *= sampleWeight*sampler.Importance; } else { contribution *= (1f - sampleWeight) * sampler.Importance; } */ sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref contribution); } if ((mutationsCount >= sampler.MaxMutations) & (sampler.NextFloat() > (1f - sampler.LargeStepProb)))//time > mutationsCount || { this.SamplerState = MCMCSamplerState.LargeStep; this.time = 0; //Print(string.Format("{0} changed state to {1}", this.SamplerID, this.SamplerState)); //Print("Chain restart - max mutations"); } @init: this.InitPath(this.pathIntegrator); }
public override void Splat(SampleBuffer sampleBuffer) { var thr = new RgbSpectrum(1f); for (int i = 0; i < currentVertex; i++) { switch (vertices[i].Event) { //case BsdfEvent.Absorb: case BsdfEvent.Light: case BsdfEvent.Environment: Radiance += thr*vertices[i].ThroughtPut; goto absorb; default: if (!vertices[i].ThroughtPut.IsBlack()) thr *= vertices[i].ThroughtPut*vertices[currentVertex].RRProbability; //else thr *= vertices[i].ThroughtPut * vertices[currentVertex].RRProbability; break; } } @absorb: if (!this.Radiance.IsBlack()) sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref this.Radiance); InitPath(this.pathIntegrator); }
public override void Splat(SampleBuffer sampleBuffer) { //Check tentative prob //Add contribution //Change state // Change sample state in init by ChangedState var yImportance = sampler.EvalImportance(ref Throughput, pathWeight); float sampleWeight = 1f; var yContribution = Radiance; var contrib = yContribution; if (!sampler.ImportanceReady) { sampler.Add_B(ref yContribution); sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref Radiance); this.InitPath(this.pathIntegrator); return; } if (yImportance > 0f) { if (sampler.SamplerState == MCMCSamplerState.SmallStep) { var a = Math.Min(1f, (Throughput.y() / xThroughput.y())); if (sampler.NextFloat() < a) { xImportance = yImportance; this.xContribution = yContribution; sampleWeight = a; contrib = yContribution; } else { contrib = xContribution; sampleWeight = 1f - a; } } else { if (xImportance <= 0f && xContribution.IsBlack()) { xImportance = yImportance; this.xContribution = yContribution; xThroughput = Throughput; contrib = yContribution; } } } RgbSpectrum c = contrib * sampleWeight * (sampler.Importance.y() / sampler.MaxMutations) * sampler.LargeStepProb; ; //var c = Radiance*sampleWeight*sampler.Br; sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref c); this.InitPath(this.pathIntegrator); }
public override void Splat(SampleBuffer sampleBuffer) { sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref this.Radiance); }
public override void Splat(SampleBuffer sampleBuffer) { if (!mutate) { if (!Radiance.IsBlack()) { XRadiance = Radiance; xPathDensity = pathDensity; } sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref this.Radiance); this.InitPath(pathIntegrator); } else { if (!Radiance.IsBlack()) { var Tyx = pathDensity; var Txy = xPathDensity; var FY = Radiance.y(); var FX = XRadiance.y(); Radiance /= FY; var Axy = Math.Min(1, (FY*Txy)/(FX*Tyx)); if (Sample.GetLazyValue() < Axy) { xPathDensity = pathDensity; XRadiance = Radiance; } else { RestorePath(); } } else { RestorePath(); } var rad = this.XRadiance * (1f / MaxMutations); sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref rad); this.InitPath(pathIntegrator); } }
public override void Splat(SampleBuffer sampleBuffer) { sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref this.Radiance); InitPath(this.pathIntegrator); }
public override sealed void Splat(SampleBuffer sampleBuffer) { if (vertices[Depth].Event == BsdfEvent.Environment || vertices[Depth].Event == BsdfEvent.Light || vertices[Depth-1].Event == BsdfEvent.Environment || vertices[Depth-1].Event == BsdfEvent.Light) { if (this.Radiance == null) { this.Radiance = ColorManager.Instance.Zero(); } else { this.Radiance.ToZero(); } if (this.Throughput == null) { this.Throughput = ColorManager.Instance.Unit(); } else { this.Throughput.ToUnit(); ; } for (int i = 1; i < Depth+1; i++) { switch (vertices[i].Event) { case BsdfEvent.Environment: Radiance.Add(Throughput.Mul(ColorManager.Instance.Convert(this.SampleEnvironment(ref vertices[i].Wo)))); goto eval; case BsdfEvent.Light: float lpdf; var lt = vertices[i].Light; var le = lt.Emit(ref vertices[i].Wo, out lpdf); Radiance.Add(Throughput.Mul(le)); goto eval; case BsdfEvent.None: case BsdfEvent.Absorb: break; default: Throughput.Mul(vertices[i].Color).Mul(vertices[i].RadiancePdf/vertices[i].Pdf); Throughput.Mul(vertices[i].RrPdf); break; } if (vertices[i].Event == BsdfEvent.None) { break; } } @eval: if (!this.Radiance.IsBlack()) { var rgb = new RgbSpectrum(); //= this.Radiance.ToXyz(); this.Radiance.TransformToRgb(out rgb); sampleBuffer.SplatSample((float)this.Sample.imageX, (float)this.Sample.imageY, ref rgb); } } else { //Tracer.TraceLine("Absorbtion [{0}] [{1}]", vertices[Depth-1].Event, vertices[Depth].Event); //PathState = PurePathTracerPathState.ShadowRaysOnly; } InitPath(this.Buffer); }
public override void Splat(SampleBuffer sampleBuffer) { //Check tentative prob //Add contribution //Change state // Change sample state in init by ChangedState if (!sampler.ImportanceReady) { sampler.Add_B(ref Radiance); sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref Radiance); this.InitPath(this.pathIntegrator); return; } var yImportance = sampler.EvalImportance(ref Radiance, pathWeight); if (yImportance <= 0f || Radiance.IsBlack()) { if (SamplerState == MCMCSamplerState.SmallStep) { mutationsCount++; } goto @init; } float sampleWeight = 1f; float a; var yContribution = Radiance / Radiance.y(); var contrib = yContribution; switch (SamplerState) { case MCMCSamplerState.Initialized: case MCMCSamplerState.LargeStep: if (xImportance <= 0f || mutate) { SwitchToSmallStep(yImportance, pathWeight, ref yContribution); goto init; //Print(string.Format("{0} changed state to {1}", this.SamplerID, this.SamplerState)); } break; } if (yImportance > 0f) { if (SamplerState == MCMCSamplerState.SmallStep) { a = Math.Min(1f, (yImportance / xImportance)); //contrib = (contrib / sampler.Importance) / sampler.MaxMutations; sampleWeight = a; this.mutationsCount++; if (sampler.NextFloat() < a) { xImportance = yImportance; this.xContribution = yContribution; contrib = yContribution*a; //this.TentativeSample = new Sample(this.Sample); Push(); //this.pathWeight = a; } else { contrib = yContribution*(1f - a); if (!this.Pop()) { //Print("Chain restart - stack empty - mutations " + mutationsCount); //sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref contrib, 1f-a); this.Sample = new Sample(this.TentativeSample); rejectCount++; this.pathWeight = this.TentativeWeight; } //Splat = false; //return; } //var newSample = sampler.GetNextSample(this.Sample, I, oldI, 1.0f, ref contrib, out outC, out newW, false); } RgbSpectrum c = contrib * (sampler.Importance/ sampler.MaxMutations) * sampler.LargeStepProb; //var c = Radiance*sampleWeight*sampler.Br; sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref c); } @init: if (rejectCount >= sampler.MaxMutations) { this.SamplerState = MCMCSamplerState.LargeStep; } if ((mutationsCount >= sampler.MaxMutations) || (sampler.NextFloat() > (1f - sampler.LargeStepProb)))//time > mutationsCount || { this.SamplerState = MCMCSamplerState.LargeStep; this.time = 0; //Print(string.Format("{0} changed state to {1}", this.SamplerID, this.SamplerState)); //Print("Chain restart - max mutations"); } this.InitPath(this.pathIntegrator); }
public override void Splat(SampleBuffer sampleBuffer) { var pssSampler = (PsMltSampler)this.pathIntegrator.Sampler; if (pssSampler.BurnInPhase) { if (!Radiance.IsBlack()) { pssSampler.AddContribution(ref Radiance); pssSampler.Accept(this.Sample); oldContribution = Radiance; oldx = Sample.imageX; oldy = Sample.imageY; } sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref this.Radiance); InitPath(this.pathIntegrator); return; } this.Sample.MutationsCount++; if (!Radiance.IsBlack()) { if (oldContribution.IsBlack())//this.Sample.LargeStep || { pssSampler.Accept(this.Sample); pssSampler.AddContribution(ref Radiance); oldContribution = Radiance; oldx = Sample.imageX; oldy = Sample.imageY; sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref this.Radiance); } else { var x = oldContribution.y(); var y = Radiance.y(); var a = Math.Min(1f, y / x); if (a > pssSampler.NextFloat()) { oldContribution = Radiance; oldx = Sample.imageX; oldy = Sample.imageY; pssSampler.Accept(this.Sample); largeStep = false; } else { pssSampler.Reject(this.Sample); } var b = pssSampler.B / (pssSampler.MaxMutations);//* pssSampler.B.y() var yContrib = (b) * a * (oldContribution / oldContribution.y()); var xContrib = (b) * (1f - a) * (Radiance / Radiance.y()); sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref xContrib); sampleBuffer.SplatSample(this.oldx, this.oldy, ref yContrib); } } else { pssSampler.Reject(Sample); } InitPath(this.pathIntegrator); }
public override void Splat(SampleBuffer sampleBuffer) { switch (SamplerState) { case PssmltSamplerState.LargeMutation: case PssmltSamplerState.Initialize: sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref Radiance); if (!Radiance.IsBlack()) { this.XContribution = Radiance; this.XSample = new Sample(Sample); this.SamplerState = PssmltSamplerState.SmallMutation; this.mutationsCount = 0; } break; case PssmltSamplerState.SmallMutation: if (!Radiance.IsBlack()) { var yContrib = Radiance; var yImportance = PssMltEngineController.Importance(ref yContrib); var xImportance = PssMltEngineController.Importance(ref XContribution); //if (!xImportance.NearEqual(yImportance)) //{ // Debugger.Break(); //} var a = Math.Min(1, (yImportance) / (xImportance)); var b_x = contributionMap[XSample].Radiance /Math.Max(1, contributionMap[XSample].Weight); var b_y = contributionMap[this.Sample].Radiance / (Math.Max(1, contributionMap[Sample].Weight)); var xPixelContrib = ((1.0 - a) / (PssMltEngineController.MaxMutations)) * (XContribution / (xImportance / b_x)); var yPixelContrib = (a / PssMltEngineController.MaxMutations) * (yContrib / (yImportance / b_y)); sampleBuffer.SplatSample(XSample.imageX, XSample.imageY, ref xPixelContrib); sampleBuffer.SplatSample(Sample.imageX, Sample.imageY, ref yPixelContrib); contributionMap[XSample].Radiance += xPixelContrib; contributionMap[Sample].Radiance += yPixelContrib; //contributionMap[XSample].Weight += 1.0f; //contributionMap[Sample] .Weight += 1.0f; if (contributionMap.Rndf() < a) { this.XSample = new Sample(Sample); this.XContribution = yContrib; } } break; case PssmltSamplerState.WarmUp: this.contributionMap[this.Sample].Radiance += Radiance; this.contributionMap[this.Sample].Weight += 1.0f; sampleBuffer.SplatSample(this.Sample.imageX, this.Sample.imageY, ref Radiance); break; } this.InitPath(pathIntegrator); }