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); }
public static IrregularSPD CreateIrregular(float[] wl, float[] samples) { var lambda = wl; var val = samples; var spd = new IrregularSPD(lambda, val, lambda.Length, 300f / lambda.Length); //spd.Normalize(); return spd; }
public static IrregularSPD CreateIrregular(float[] wl) { var nSamples = wl.Length / 2; var lambda = new float[nSamples]; var val = new float[nSamples]; for (int index = 0; index < lambda.Length; index++) { lambda[index] = wl[index * 2]; val[index] = wl[index * 2 + 1]; } var spd = new IrregularSPD(lambda, val, lambda.Length, 300f / lambda.Length); spd.Normalize(); return spd; }
protected virtual RgbSpectrum SamplePath1(int x, int y) { float lambda; Tuple<float, float>[] c = new Tuple<float, float>[MaxSpectralSamples]; float dLambda = (SampledSpectrum.sampledLambdaEnd - SampledSpectrum.sampledLambdaStart) / ((float)MaxSpectralSamples + 1f); for (int l = 0; l < MaxSpectralSamples; l++) { lambda = SampleWavelength(rnd.NextFloat()); RayData cameraRay; Scene.GenerateCameraRay(x, y, out cameraRay); var pix = EvalRadiance(ref cameraRay, lambda, 0); totalSamples++; c[l] = new Tuple<float, float>(lambda, pix); //lambda += dLambda; } c = c.OrderBy(item => item.Item1).ToArray(); var lms = c.Select(p => p.Item1).ToArray(); var vals = c.Select(p => p.Item2).ToArray(); var spd = new IrregularSPD(lms, vals, MaxSpectralSamples, dLambda); //RegularSPD spd = new RegularSPD(vals, SampledSpectrum.sampledLambdaStart, SampledSpectrum.sampledLambdaEnd, MaxSpectralSamples); var pixV = spd.ToRgb(); return pixV; }
public override void RenderPass() { var sb = film.GetFreeSampleBuffer(); var sw = Stopwatch.StartNew(); var samplesPerPass = Scene.w * Scene.h; float dLambda = (SampledSpectrum.sampledLambdaEnd - SampledSpectrum.sampledLambdaStart) / ((float)MaxSpectralSamples + 1f); for (int y = 0; y < Scene.h; ++y) { int pj = 0; for (int x = 0; x < Scene.w; ++x, ++pj) { var cluster = new WavelengthCluster(SampledSpectrum.sampledLambdaStart, dLambda, MaxSpectralSamples); //var c = new WlCluster(MaxSpectralSamples); //for (int l = 0; l < MaxSpectralSamples / SamplesPerCluster; l++) { float[] lambdas = Enumerable.Range(0, MaxSpectralSamples).Select(i => SampleWavelength(rnd.NextFloat())).OrderBy(i=>i).ToArray(); RayData cameraRay; Scene.GenerateCameraRay(x, y, out cameraRay); cluster = EvalRadiance(ref cameraRay, cluster, 0); totalSamples += MaxSpectralSamples; } //cluster.Sort(); IrregularSPD spd = new IrregularSPD(cluster.Lambdas, cluster.Values, MaxSpectralSamples, dLambda); //RegularSPD spd = new RegularSPD(vals, SampledSpectrum.sampledLambdaStart, SampledSpectrum.sampledLambdaEnd, MaxSpectralSamples); var pixV = spd.ToRgb(); sb.SplatSample(x, (Scene.h - y - 1), ref pixV); if (sb.IsFull()) { film.SplatSampleBuffer(true, sb); sb = film.GetFreeSampleBuffer(); } } } pass++; sw.Stop(); stats = string.Format("MSamples per sec {1:F5}; Total Samples {0}; Samples per pixel {2}; {3}", totalSamples, 0.000001 * (samplesPerPass / sw.Elapsed.TotalSeconds), pass, film.GetStats()); }