public static Spectrum SpecularReflect(RayDifferential ray, BSDF bsdf, Intersection isect, IRenderer renderer, Scene scene, Sample sample) { Vector wo = -ray.Direction, wi = new Vector (); double pdf = 0.0; Point p = bsdf.dgShading.p; Normal n = bsdf.dgShading.n; Spectrum f = bsdf.SampleF (wo, ref wi, new BSDFSample (), ref pdf, BxDFType.BSDF_REFLECTION | BxDFType.BSDF_SPECULAR); Spectrum L = new Spectrum (); if (pdf > 0.0 && !f.IsBlack && Util.AbsDot (wi, n) != 0.0) { RayDifferential rd = new RayDifferential (p, wi, ray, isect.RayEpsilon); if (ray.HasDifferentials) { rd.HasDifferentials = true; rd.RxOrigin = p + isect.dg.dpdx; rd.RyOrigin = p + isect.dg.dpdy; Normal dndx = bsdf.dgShading.dndu * bsdf.dgShading.dudx + bsdf.dgShading.dndv * bsdf.dgShading.dvdx; Normal dndy = bsdf.dgShading.dndu * bsdf.dgShading.dudy + bsdf.dgShading.dndv * bsdf.dgShading.dvdy; Vector dwodx = -ray.RxDirection - wo, dwody = -ray.Direction - wo; double dDNdx = (dwodx ^ n) + (wo ^ dndx); double dDNdy = (dwody ^ n) + (wo ^ dndy); rd.RxDirection = wi - dwodx + 2 * new Vector ((wo ^ n) * dndx + dDNdx * n); rd.RyDirection = wi - dwody + 2 * new Vector ((wo ^ n) * dndy + dDNdy * n); } Spectrum Li = renderer.Li (scene, rd, sample); L = f * Li * Util.AbsDot (wi, n) / pdf; } return L; }
public SamplerRendererTask(Scene scene, IRenderer renderer, ICamera camera, ProgressReporter reporter, ISampler sampler, Sample sample, int tn, int tc) { Scene = scene; Camera = camera; Renderer = renderer; MainSampler = sampler; OrigSample = sample; TaskNumber = tn; TaskCount = tc; Reporter = reporter; }
public void Run() { ISampler sampler = MainSampler.GetSubSampler (TaskNumber, TaskCount); if (sampler == null) { return; } int maxSamples = sampler.MaximumSampleCount; Sample[] samples = OrigSample.Duplicate (maxSamples); RayDifferential[] rays = new RayDifferential[maxSamples]; Spectrum[] Ls = new Spectrum[maxSamples]; Spectrum[] Ts = new Spectrum[maxSamples]; Intersection[] isects = new Intersection[maxSamples]; for (int i = 0; i < maxSamples; ++i) { samples[i] = new Sample (); rays[i] = new RayDifferential (); Ls[i] = new Spectrum (); Ts[i] = new Spectrum (); isects[i] = new Intersection (); } int sampleCount; while ((sampleCount = sampler.GetMoreSamples (samples)) > 0) { for (int i = 0; i < sampleCount; ++i) { double rayWeight = Camera.GenerateRayDifferential (samples[i], ref rays[i]); rays[i].ScaleDifferentials (1.0 / Math.Sqrt (sampler.SamplesPerPixel)); if (rayWeight > 0.0) Ls[i] = rayWeight * Renderer.Li (Scene, rays[i], samples[i], ref isects[i], ref Ts[i]); else { Ls[i] = new Spectrum (); Ts[i] = new Spectrum (1.0); } // WARNINGS } if (sampler.ReportResults (samples, rays, Ls, isects, sampleCount)) { for (int i = 0; i < sampleCount; ++i) Camera.Film.AddSample (samples[i], Ls[i]); } } Camera.Film.UpdateDisplay (sampler.xPixelStart, sampler.yPixelStart, sampler.xPixelEnd + 1, sampler.yPixelEnd + 1); Reporter.Update (); }
public Sample[] Duplicate(int count) { Sample[] ret = new Sample[count]; for (int i = 0; i < count; ++i) { ret[i] = new Sample (); ret[i].n1D = new List<int> (n1D); ret[i].n2D = new List<int> (n2D); ret[i].AllocateSampleMemory (); } return ret; }
public override int GetMoreSamples(Sample[] sample) { if (yPos == yPixelEnd) return 0; if (SampleBuffer == null) SampleBuffer = new double[MonteCarlo.LowDiscrepancyPixelSampleDoublesNeeded (sample, nPixelSamples)]; MonteCarlo.LowDiscrepancyPixelSample (xPos, yPos, ShutterOpen, ShutterClose, nPixelSamples, sample, SampleBuffer); if (++xPos == xPixelEnd) { xPos = xPixelStart; ++yPos; } return nPixelSamples; }
public static Spectrum SpecularTransmit(RayDifferential ray, BSDF bsdf, Intersection isect, IRenderer renderer, Scene scene, Sample sample) { Vector wo = -ray.Direction, wi = new Vector (); double pdf = 0.0; Point p = bsdf.dgShading.p; Normal n = bsdf.dgShading.n; Spectrum f = bsdf.SampleF (wo, ref wi, new BSDFSample (), ref pdf, BxDFType.BSDF_TRANSMISSION | BxDFType.BSDF_SPECULAR); Spectrum L = new Spectrum (); if (pdf > 0.0 && !f.IsBlack && Util.AbsDot (wi, n) != 0.0) { RayDifferential rd = new RayDifferential (p, wi, ray, isect.RayEpsilon); if (ray.HasDifferentials) { rd.HasDifferentials = true; rd.RxOrigin = p + isect.dg.dpdx; rd.RyOrigin = p + isect.dg.dpdy; double eta = bsdf.Eta; Vector w = -wo; if ((wo ^ n) < 0.0) eta = 1.0 / eta; Normal dndx = bsdf.dgShading.dndu * bsdf.dgShading.dudx + bsdf.dgShading.dndv * bsdf.dgShading.dvdx; Normal dndy = bsdf.dgShading.dndu * bsdf.dgShading.dudy + bsdf.dgShading.dndv * bsdf.dgShading.dvdy; Vector dwodx = -ray.RxDirection - wo, dwody = -ray.RyDirection - wo; double dDNdx = (dwodx ^ n) + (wo ^ dndx); double dDNdy = (dwody ^ n) + (wo ^ dndy); double mu = eta * (w ^ n) - (wi ^ n); double dmudx = (eta - (eta * eta * (w ^ n)) / (wi ^ n)) * dDNdx; double dmudy = (eta - (eta * eta * (w ^ n)) / (wi ^ n)) * dDNdy; rd.RxDirection = wi + eta * dwodx - new Vector (mu * dndx + dmudx * n); rd.RyDirection = wi + eta * dwody - new Vector (mu * dndy + dmudy * n); } Spectrum Li = renderer.Li (scene, rd, sample); L = f * Li * Util.AbsDot (wi, n) / pdf; } return L; }
public override Spectrum Transmittance(Scene scene, IRenderer renderer, RayDifferential ray, Sample sample) { if (scene.VolumeRegion == null) return new Spectrum (1.0); double step, offset; if (sample != null) { step = StepSize; offset = sample.samples[sample.oneD + TauSampleOffset][0]; } else { step = 4.0 * StepSize; offset = Util.Random.NextDouble (); } /*Spectrum tau = scene.VolumeRegion.Tau (ray, step, offset); return (-tau).Exp;*/ return null; }
public abstract Spectrum Li(Scene scene, IRenderer renderer, RayDifferential ray, Intersection isect, Sample sample);
public abstract int GetMoreSamples(Sample[] sample);
public abstract Spectrum Transmittance(Scene scene, RayDifferential ray, Sample sample);
public Spectrum Li(Scene scene, RayDifferential ray, Sample sample, ref Intersection isect) { Spectrum T = new Spectrum (); return Li (scene, ray, sample, ref isect, ref T); }
public abstract Spectrum Li(Scene scene, RayDifferential ray, Sample sample, ref Intersection isect, ref Spectrum T);
public virtual bool ReportResults(Sample[] samples, RayDifferential[] rays, Spectrum[] Ls, Intersection[] isects, int count) { return true; }
public override Spectrum Li(Scene scene, IRenderer renderer, RayDifferential ray, Sample sample, ref Spectrum transmittance) { transmittance = new Spectrum (1.0); return new Spectrum (); }
public override void RequestSamples(ISampler sampler, Sample sample, Scene scene) { TauSampleOffset = sample.Add1D (1); ScatterSampleOffset = sample.Add1D (1); }
public static int LowDiscrepancyPixelSampleDoublesNeeded(Sample[] sample, int nPixelSamples) { int n = 5; // 2 lens + 2 pixel + time for (int i = 0; i < sample[0].n1D.Count; ++i) n += sample[0].n1D[i]; for (int i = 0; i < sample[0].n2D.Count; ++i) n += 2 * sample[0].n2D[i]; return nPixelSamples * n; }
public Spectrum Transmittance(Scene scene, IRenderer renderer, Sample sample) { return renderer.Transmittance (scene, new RayDifferential (Ray), sample); }
public BSDFSampleOffsets(int count, Sample sample) { nSamples = count; ComponentOffset = sample.Add1D (nSamples); DirOffset = sample.Add2D (nSamples); }
public static void LowDiscrepancyPixelSample(int xPos, int yPos, double shutterOpen, double shutterClose, int nPixelSamples, Sample[] samples, double[] buf) { int index = 5 * nPixelSamples; int ImageSamples = 0; int LensSamples = 2 * nPixelSamples; int TimeSamples = 4 * nPixelSamples; // Prepare temporary array pointers for low-discrepancy integrator samples int count1D = samples[0].n1D.Count; int count2D = samples[0].n2D.Count; List<int> n1D = count1D > 0 ? samples[0].n1D : null; List<int> n2D = count2D > 0 ? samples[0].n2D : null; double[][] oneDSamples = new double[count1D][]; double[][] twoDSamples = new double[count2D][]; for (int i = 0; i < count1D; ++i) { oneDSamples[i] = buf; index += n1D[i] * nPixelSamples; } for (int i = 0; i < count2D; ++i) { twoDSamples[i] = buf; index += 2 * n2D[i] * nPixelSamples; } // Generate low-discrepancy pixel samples LDShuffleScrambled2D (1, nPixelSamples, ref buf, ImageSamples); LDShuffleScrambled2D (1, nPixelSamples, ref buf, LensSamples); LDShuffleScrambled1D (1, nPixelSamples, ref buf, TimeSamples); for (int i = 0; i < count1D; ++i) LDShuffleScrambled1D (n1D[i], nPixelSamples, ref oneDSamples[i], 0); for (int i = 0; i < count2D; ++i) LDShuffleScrambled2D (n2D[i], nPixelSamples, ref twoDSamples[i], 0); // Initialize _samples_ with computed sample values for (int i = 0; i < nPixelSamples; ++i) { samples[i].ImageX = xPos + buf[ImageSamples + 2 * i]; samples[i].ImageY = yPos + buf[ImageSamples + 2 * i + 1]; samples[i].Time = Util.Lerp (buf[TimeSamples + i], shutterOpen, shutterClose); samples[i].LensU = buf[LensSamples + 2 * i]; samples[i].LensV = buf[LensSamples + 2 * i + 1]; // Copy integrator samples into _samples[i]_ for (int j = 0; j < count1D; ++j) { int startSamp = n1D[j] * i; for (int k = 0; k < n1D[j]; ++k) samples[i].samples[samples[i].oneD + j][k] = oneDSamples[j][startSamp + k]; } for (int j = 0; j < count2D; ++j) { int startSamp = 2 * n2D[j] * i; for (int k = 0; k < 2 * n2D[j]; ++k) samples[i].samples[samples[i].twoD + j][k] = twoDSamples[j][startSamp + k]; } } }
public abstract Spectrum Li(Scene scene, IRenderer renderer, RayDifferential ray, Sample sample, ref Spectrum transmittance);