Пример #1
0
 public void accumulate(ShadingCache cache)
 {
     cacheHits += cache.hits;
     cacheMisses += cache.misses;
     cacheSumDepth += cache.sumDepth;
     cacheNumCaches += cache.numCaches;
 }
Пример #2
0
 public BucketThread(int threadID, MultipassRenderer renderer)
 {
     this.threadID       = threadID;
     istate              = new IntersectionState();
     cache               = renderer.shadingCache ? new ShadingCache() : null;
     this.renderer       = renderer;
     thread              = new Thread(new ThreadStart(run));
     thread.IsBackground = true;
     this.renderer       = renderer;
 }
Пример #3
0
 public ShadingState getRadiance(float rx, float ry, float time, int i, int d, Ray r, IntersectionState istate, ShadingCache cache)
 {
     istate.time = time;
     scene.trace(r, istate);
     if (istate.hit()) {
         ShadingState state = ShadingState.createState(istate, rx, ry, time, r, i, d, this);
         state.getInstance().prepareShadingState(state);
         IShader shader = getShader(state);
         if (shader == null) {
             state.setResult(Color.BLACK);
             return state;
         }
         if (cache != null) {
             Color c = cache.lookup(state, shader);
             if (c != null) {
                 state.setResult(c);
                 return state;
             }
         }
         state.setResult(shader.GetRadiance(state));
         if (cache != null)
             cache.add(state, shader, state.getResult());
         checkNanInf(state.getResult());
         return state;
     } else
         return null;
 }
Пример #4
0
 public BucketThread(int threadID,  MultipassRenderer renderer)
 {
     this.threadID = threadID;
     istate = new IntersectionState();
     cache = renderer.shadingCache ? new ShadingCache() : null;
     this.renderer = renderer;
     thread = new Thread(new ThreadStart(run));
     thread.IsBackground = true;
     this.renderer = renderer;
 }
Пример #5
0
        private void renderBucket(IDisplay display, int bx, int by, int threadID, IntersectionState istate, ShadingCache cache)
        {
            // pixel sized extents
            int x0 = bx * bucketSize;
            int y0 = by * bucketSize;
            int bw = Math.Min(bucketSize, imageWidth - x0);
            int bh = Math.Min(bucketSize, imageHeight - y0);

            // prepare bucket
            display.imagePrepare(x0, y0, bw, bh, threadID);

            Color[] bucketRGB = new Color[bw * bh];
            float[] bucketAlpha = new float[bw * bh];

            for (int y = 0, i = 0, cy = imageHeight - 1 - y0; y < bh; y++, cy--) {
                for (int x = 0, cx = x0; x < bw; x++, i++, cx++) {
                    // sample pixel
                    Color c = Color.black();
                    float a = 0;
                    int instance = ((cx & ((1 << QMC.MAX_SIGMA_ORDER) - 1)) << QMC.MAX_SIGMA_ORDER) + QMC.sigma(cy & ((1 << QMC.MAX_SIGMA_ORDER) - 1), QMC.MAX_SIGMA_ORDER);
                    double jitterX = QMC.halton(0, instance);
                    double jitterY = QMC.halton(1, instance);
                    double jitterT = QMC.halton(2, instance);
                    double jitterU = QMC.halton(3, instance);
                    double jitterV = QMC.halton(4, instance);
                    for (int s = 0; s < numSamples; s++) {
                        float rx = cx + 0.5f + (float) warpCubic(QMC.mod1(jitterX + s * invNumSamples));
                        float ry = cy + 0.5f + (float) warpCubic(QMC.mod1(jitterY + QMC.halton(0, s)));
                        double time = QMC.mod1(jitterT + QMC.halton(1, s));
                        double lensU = QMC.mod1(jitterU + QMC.halton(2, s));
                        double lensV = QMC.mod1(jitterV + QMC.halton(3, s));
                        ShadingState state = scene.getRadiance(istate, rx, ry, lensU, lensV, time, instance + s, 5, cache);
                        if (state != null) {
                            c.add(state.getResult());
                            a++;
                        }
                    }
                    bucketRGB[i] = c.mul(invNumSamples);
                    bucketAlpha[i] = a * invNumSamples;
                    if (cache != null)
                        cache.reset();
                }
            }
            // update pixels
            display.imageUpdate(x0, y0, bw, bh, bucketRGB, bucketAlpha);
        }
Пример #6
0
        private void renderBucket(IDisplay display, int bx, int by, int threadID, IntersectionState istate, ShadingCache cache)
        {
            // pixel sized extents
            int x0 = bx * bucketSize;
            int y0 = by * bucketSize;
            int bw = Math.Min(bucketSize, imageWidth - x0);
            int bh = Math.Min(bucketSize, imageHeight - y0);

            // prepare bucket
            display.imagePrepare(x0, y0, bw, bh, threadID);

            Color[] bucketRGB   = new Color[bw * bh];
            float[] bucketAlpha = new float[bw * bh];

            for (int y = 0, i = 0, cy = imageHeight - 1 - y0; y < bh; y++, cy--)
            {
                for (int x = 0, cx = x0; x < bw; x++, i++, cx++)
                {
                    // sample pixel
                    Color  c        = Color.black();
                    float  a        = 0;
                    int    instance = ((cx & ((1 << QMC.MAX_SIGMA_ORDER) - 1)) << QMC.MAX_SIGMA_ORDER) + QMC.sigma(cy & ((1 << QMC.MAX_SIGMA_ORDER) - 1), QMC.MAX_SIGMA_ORDER);
                    double jitterX  = QMC.halton(0, instance);
                    double jitterY  = QMC.halton(1, instance);
                    double jitterT  = QMC.halton(2, instance);
                    double jitterU  = QMC.halton(3, instance);
                    double jitterV  = QMC.halton(4, instance);
                    for (int s = 0; s < numSamples; s++)
                    {
                        float        rx    = cx + 0.5f + (float)warpCubic(QMC.mod1(jitterX + s * invNumSamples));
                        float        ry    = cy + 0.5f + (float)warpCubic(QMC.mod1(jitterY + QMC.halton(0, s)));
                        double       time  = QMC.mod1(jitterT + QMC.halton(1, s));
                        double       lensU = QMC.mod1(jitterU + QMC.halton(2, s));
                        double       lensV = QMC.mod1(jitterV + QMC.halton(3, s));
                        ShadingState state = scene.getRadiance(istate, rx, ry, lensU, lensV, time, instance + s, 5, cache);
                        if (state != null)
                        {
                            c.add(state.getResult());
                            a++;
                        }
                    }
                    bucketRGB[i]   = c.mul(invNumSamples);
                    bucketAlpha[i] = a * invNumSamples;
                    if (cache != null)
                    {
                        cache.reset();
                    }
                }
            }
            // update pixels
            display.imageUpdate(x0, y0, bw, bh, bucketRGB, bucketAlpha);
        }