Example #1
0
        private int progressiveRenderNext(IntersectionState istate)
        {
            int         TASK_SIZE = 16;
            SmallBucket first     = smallBucketQueue.Count > 0 ? smallBucketQueue.Dequeue() : null;

            if (first == null)
            {
                return(0);
            }
            int  ds      = first.size / TASK_SIZE;
            bool useMask = smallBucketQueue.Count != 0;
            int  mask    = 2 * first.size / TASK_SIZE - 1;
            int  pixels  = 0;

            for (int i = 0, y = first.y; i < TASK_SIZE && y < imageHeight; i++, y += ds)
            {
                for (int j = 0, x = first.x; j < TASK_SIZE && x < imageWidth; j++, x += ds)
                {
                    // check to see if this is a pixel from a higher level tile
                    if (useMask && (x & mask) == 0 && (y & mask) == 0)
                    {
                        continue;
                    }
                    int          instance = (x & (sigma.Length - 1)) * sigma.Length + sigma[y & (sigma.Length - 1)];
                    double       time     = QMC.halton(1, instance);
                    double       lensU    = QMC.halton(2, instance);
                    double       lensV    = QMC.halton(3, instance);
                    ShadingState state    = scene.getRadiance(istate, x, imageHeight - 1 - y, lensU, lensV, time, instance);
                    Color        c        = state != null?state.getResult() : Color.BLACK;

                    pixels++;
                    // fill region
                    display.imageFill(x, y, Math.Min(ds, imageWidth - x), Math.Min(ds, imageHeight - y), c);
                }
            }
            if (first.size >= 2 * TASK_SIZE)
            {
                // generate child buckets
                int size = (int)((uint)first.size >> 1);//>>>
                for (int i = 0; i < 2; i++)
                {
                    if (first.y + i * size < imageHeight)
                    {
                        for (int j = 0; j < 2; j++)
                        {
                            if (first.x + j * size < imageWidth)
                            {
                                SmallBucket b = new SmallBucket();
                                b.x         = first.x + j * size;
                                b.y         = first.y + i * size;
                                b.size      = size;
                                b.constrast = 1.0f / size;
                                smallBucketQueue.Enqueue(b);
                            }
                        }
                    }
                }
            }
            return(pixels);
        }
Example #2
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);
        }
Example #3
0
 public void add(ShadingState state)
 {
     if (n == 0)
     {
         c = Color.black();
     }
     if (state != null)
     {
         c.add(state.getResult());
         checkNanInf();
     }
     n++;
 }
Example #4
0
 public void add(ShadingState state)
 {
     if (n == 0)
     {
         c = Color.black();
     }
     if (state != null)
     {
         c.add(state.getResult());
         alpha += state.getInstance() == null ? 0 : 1;
     }
     n++;
 }
Example #5
0
        public void renderBucket(uint bx, uint by, IntersectionState istate)
        {
            // pixel sized extents
            int x0 = (int)(bx * 32);
            int y0 = (int)(by * 32);
            int bw = Math.Min(32, imageWidth - x0);
            int bh = Math.Min(32, imageHeight - y0);

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

            for (int y = 0, i = 0; y < bh; y++)
            {
                for (int x = 0; x < bw; x++, i++)
                {
                    ShadingState state = scene.getRadiance(istate, x0 + x, imageHeight - 1 - (y0 + y), 0.0, 0.0, 0.0, 0);
                    bucketRGB[i] = (state != null) ? state.getResult() : Color.BLACK;
                }
            }
            // update pixels
            display.imageUpdate(x0, y0, bw, bh, bucketRGB);
        }
Example #6
0
 public void set(ShadingState state)
 {
     if (state == null)
     {
         c = Color.BLACK;
     }
     else
     {
         c = state.getResult();
         checkNanInf();
         shader   = state.getShader();
         instance = state.getInstance();
         if (state.getNormal() != null)
         {
             nx = state.getNormal().x;
             ny = state.getNormal().y;
             nz = state.getNormal().z;
         }
     }
     n = 1;
 }
Example #7
0
            public void add(ShadingState state)
            {
                if (n == 0)
                    c = Color.black();
                if (state != null)
                {
                    c.add(state.getResult());
					alpha += state.getInstance() == null ? 0 : 1;
                }
                n++;
            }
Example #8
0
            public void set(ShadingState state)
            {
                if (state == null)
                    c = Color.BLACK;
                else
                {
                    c = state.getResult();
                    shader = state.getShader();
                    instance = state.getInstance();
                    if (state.getNormal() != null)
                    {
                        nx = state.getNormal().x;
                        ny = state.getNormal().y;
                        nz = state.getNormal().z;
                    }
					alpha = state.getInstance() == null ? 0 : 1;
                }
                n = 1;
            }
Example #9
0
 public void add(ShadingState state)
 {
     if (n == 0)
         c = Color.black();
     if (state != null)
     {
         c.add(state.getResult());
         checkNanInf();
     }
     n++;
 }