コード例 #1
0
ファイル: MCMCSampler.cs プロジェクト: HungryBear/rayden
        public Sample GetSample(Sample prevSample)
        {
            TotalSamples++;
            Sample sample = new Sample(this);
            sample.sampleData = new float[SampleDataOffset.SamplesPerVertex * sceneMaxPathDepth];
            //sample.modifyData = new int[SampleDataOffset.SamplesPerVertex * sceneMaxPathDepth];
            //MC.StratifiedSample1D(sample.sampleData, SampleDataOffset.SamplesPerVertex * sceneMaxPathDepth, rnd, false);
            //sample.sampleData 
            sample.InitSample(SampleDataOffset.SamplesPerVertex * sceneMaxPathDepth);


            sample.imageX = rnd.NextFloat()*screenWidth;
            sample.imageY = rnd.NextFloat()*screenHeight;
            //sample.imageY += screenStartLine;
            return sample;
            /*if ((pass >= MagicValue2))
            {
                // In order to improve ray coherency
                int stepX = currentSubSampleIndex % 4;
                int stepY = currentSubSampleIndex / 4;

                scrX = currentSampleScreenX;
                scrY = currentSampleScreenY;

                currentSubSampleIndex++;
                if (currentSubSampleIndex == (MagicValue1 / 2))
                {
                    currentSubSampleIndex = 0;
                    currentSampleScreenX++;
                    if (currentSampleScreenX >= screenWidth)
                    {
                        currentSampleScreenX = 0;
                        currentSampleScreenY++;

                        if (currentSampleScreenY >= screenHeight)
                        {
                            currentSampleScreenY = 0;
                            pass += 16;
                        }
                    }
                }

                float r1 = (stepX + ((float)rnd.NextDouble())) / 4f - 0.5f;
                float r2 = (stepY + ((float)rnd.NextDouble())) / 4f - 0.5f;
                sample.imageX = scrX + r1;
                sample.imageY = scrY + r2;
                //sample.Init(this,pass, valuesPerSample, false);
            }
            else if (pass >= MagicValue1)
            {
                scrX = currentSampleScreenX;
                scrY = currentSampleScreenY;

                currentSampleScreenX++;
                if (currentSampleScreenX >= screenWidth)
                {
                    currentSampleScreenX = 0;
                    currentSampleScreenY++;

                    if (currentSampleScreenY >= screenHeight)
                    {
                        currentSampleScreenY = 0;
                        pass++;
                    }
                }

                float r1 = ((float)rnd.NextDouble()) - .5f;
                float r2 = ((float)rnd.NextDouble()) - .5f;
                sample.imageX = scrX + r1;
                sample.imageY = scrY + r2;
                //sample.Init(this, pass,valuesPerSample, false);
            }
            else
            {
                // In order to update the screen faster for the first 16 passes
                for (; ; )
                {
                    int stepX = pass % 4;
                    int stepY = (pass / 4) % 4;

                    scrX = currentSampleScreenX * 4 + stepX;
                    scrY = currentSampleScreenY * 4 + stepY;

                    currentSampleScreenX++;
                    if (currentSampleScreenX * 4 >= screenWidth)
                    {
                        currentSampleScreenX = 0;
                        currentSampleScreenY++;

                        if (currentSampleScreenY * 4 >= screenHeight)
                        {
                            currentSampleScreenY = 0;
                            pass++;
                        }
                    }

                    // Check if we are inside the screen
                    if ((scrX < screenWidth) && (scrY < screenHeight))
                    {
                        // Ok, it is a valid sample
                        break;
                    }
                    else if (pass >= MagicValue1)
                    {
                        sample = this.GetSample(prevSample);
                        return sample;
                    }
                }

                float r1 = ((float)rnd.NextDouble()) - .5f;
                float r2 = ((float)rnd.NextDouble()) - .5f;

                sample.imageX = scrX + r1;
                sample.imageY = scrY + r2;
                //sample.Init(this, pass, valuesPerSample, false);
            }
            sample.imageY += screenStartLine;
            return sample;*/
        }
コード例 #2
0
ファイル: PSSMLTSampler.cs プロジェクト: HungryBear/rayden
        private Sample GetNewSample(bool regen)
        {
            TotalSamples++;
            Sample sample = new Sample(this);
            if (regen)
                sample.InitSample(10 * 10);
            int scrX, scrY;

            if (!lowLatency || (pass >= MagicValue2))
            {
                // In order to improve ray coherency
                int stepX = currentSubSampleIndex % SuperSamplingSize;
                int stepY = currentSubSampleIndex / SuperSamplingSize;

                scrX = currentSampleScreenX;
                scrY = currentSampleScreenY;

                currentSubSampleIndex++;
                if (currentSubSampleIndex == (SamplesPerPassX4))
                {
                    currentSubSampleIndex = 0;
                    currentSampleScreenX++;
                    if (currentSampleScreenX >= screenWidth)
                    {
                        currentSampleScreenX = 0;
                        currentSampleScreenY++;

                        if (currentSampleScreenY >= ScreenHeight)
                        {
                            currentSampleScreenY = _currentSampleScreenY;
                            pass += SamplesPerPassX4;
                        }
                    }
                }

                float r1 = (stepX + ((float)rnd.NextDouble())) / (float)SuperSamplingSize - 0.5f;
                float r2 = (stepY + ((float)rnd.NextDouble())) / (float)SuperSamplingSize - 0.5f;
                sample.imageX = scrX + r1;
                sample.imageY = scrY + r2;
                //sample.imageY += screenStartLine;

                //sample.Init(this,pass, valuesPerSample, false);
            }
            else if (pass >= PreviewPasses)
            {
                scrX = currentSampleScreenX;
                scrY = currentSampleScreenY;

                currentSampleScreenX++;
                if (currentSampleScreenX >= screenWidth)
                {
                    currentSampleScreenX = 0;
                    currentSampleScreenY++;

                    if (currentSampleScreenY >= ScreenHeight)
                    {
                        currentSampleScreenY = _currentSampleScreenY;
                        pass++;
                    }
                }

                float r1 = ((float)rnd.NextDouble()) - .5f;
                float r2 = ((float)rnd.NextDouble()) - .5f;
                sample.imageX = scrX + r1;
                sample.imageY = scrY + r2;
                //sample.imageY += screenStartLine;
                //sample.Init(this, pass,valuesPerSample, false);
            }
            else
            {
                // In order to update the screen faster for the first 16 passes
                for (; ; )
                {
                    int stepX = pass % SuperSamplingSize;
                    int stepY = (pass / SuperSamplingSize) % SuperSamplingSize;

                    scrX = currentSampleScreenX * SuperSamplingSize + stepX;
                    scrY = currentSampleScreenY * SuperSamplingSize + stepY;

                    currentSampleScreenX++;
                    if ((currentSampleScreenX * SuperSamplingSize) >= screenWidth)
                    {
                        currentSampleScreenX = 0;
                        currentSampleScreenY++;

                        if ((currentSampleScreenY * SuperSamplingSize) >= ScreenHeight)
                        {
                            currentSampleScreenY = _currentSampleScreenY;
                            pass++;
                        }
                    }

                    // Check if we are inside the screen
                    if ((scrX < screenWidth) && (scrY < ScreenHeight))
                    {
                        // Ok, it is a valid sample
                        break;
                    }
                    else if (pass >= PreviewPasses)
                    {
                        sample = this.GetNewSample(regen);
                        return sample;
                    }
                }
                /*
                float r1 = ((float)rnd.NextDouble()) - .5f;
                float r2 = ((float)rnd.NextDouble()) - .5f;

                sample.imageX = scrX + r1;
                sample.imageY = scrY + r2;*/
                //sample.imageY += screenStartLine;
                //sample.Init(this, pass, valuesPerSample, false);
            }
            return sample;
        }