Exemple #1
0
 public PathTracerSkyShader(PathTracer pathTracer)
 {
     m_PathTracer = pathTracer;
 }
Exemple #2
0
        private void renderResultBox_MouseClick(object sender, MouseEventArgs e)
        {
            #if DEBUG
            if (this.pixelDebugCheckBox.Checked)
            {
                if (MessageBox.Show("开启单像素调试后点击画布将对单个像素渲染,这会清空之前的渲染结果,是否继续?", "警告", MessageBoxButtons.YesNo) ==
                    DialogResult.Yes)
                {
                    int  traceTimes = string.IsNullOrEmpty(this.bounceInputBox.Text) ? 0 : int.Parse(this.bounceInputBox.Text);
                    int  numSamples = string.IsNullOrEmpty(this.numSampleInputBox.Text) ? 0 : int.Parse(this.numSampleInputBox.Text);
                    var  sampleType = (SamplerType)this.samplerTypeCombo.SelectedIndex;
                    uint width      = string.IsNullOrEmpty(this.widthInputBox.Text) ? 0 : uint.Parse(this.widthInputBox.Text);
                    uint height     = string.IsNullOrEmpty(this.heightInputBox.Text) ? 0 : uint.Parse(this.heightInputBox.Text);
                    if (traceTimes <= 0)
                    {
                        MessageBox.Show("不允许反弹次数小于等于0!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (numSamples <= 0)
                    {
                        MessageBox.Show("不允许采样次数小于等于0!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (width <= 0 || height <= 0)
                    {
                        MessageBox.Show("请输入宽高合法的宽高!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    int w = ((PictureBox)sender).Width;
                    int h = ((PictureBox)sender).Height;

                    Log.Info($"点击了坐标:({w - 1 - e.Location.X},{h - 1 - e.Location.Y}),开始单像素渲染");

                    int x = (int)(((float)(w - 1 - e.Location.X)) / w * width);
                    int y = (int)(((float)(h - 1 - e.Location.Y)) / h * height);

                    Log.Info($"渲染目标像素:({x},{y})");

                    var          pt     = new ASL.PathTracer.PathTracer(m_Scene);
                    RenderConfig config = new RenderConfig()
                    {
                        traceTimes  = traceTimes,
                        samplerType = sampleType,
                        numSamples  = numSamples,
                        numSets     = 83,
                        width       = width,
                        height      = height,
                    };
                    m_Result = pt.RenderDebugSinglePixel(x, y, config);

                    if (m_Result != null)
                    {
                        Log.CompleteInfo("渲染完成");

                        //this.renderResultBox.BackgroundImage = result.SaveToImage();
                    }
                    else
                    {
                        Log.Err("渲染失败!");
                    }
                }
            }
            #endif
        }
Exemple #3
0
        public bool Execute(RenderJobCallBackDelegate progressCallBackAction = null)
        {
            if (string.IsNullOrEmpty(scenePath))
            {
                return(false);
            }
            if (File.Exists(scenePath) == false)
            {
                return(false);
            }
            if (string.IsNullOrEmpty(outputPath))
            {
                return(false);
            }
            FileInfo outputFileInfo = new FileInfo(outputPath);

            if (outputFileInfo.Directory == null)
            {
                return(false);
            }
            if (bounceTimes <= 0)
            {
                return(false);
            }
            if (numSamples <= 0)
            {
                return(false);
            }
            if (width <= 0 || height <= 0)
            {
                return(false);
            }
            var          scene  = Scene.Create(scenePath);
            var          pt     = new PathTracer(scene);
            RenderConfig config = new RenderConfig()
            {
                traceTimes  = bounceTimes,
                samplerType = samplerType,
                numSamples  = numSamples,
                numSets     = 83,
                width       = (uint)width,
                height      = (uint)height,
            };
            var tex = pt.Render(config, progressCallBackAction);

            if (outputFileInfo.Directory.Exists)
            {
                outputFileInfo.Directory.Create();
            }
            if (saveHDR)
            {
                tex.Save(Path.Combine(outputFileInfo.FullName, ".hdr"));
                //tex.SaveToHDR(Path.Combine(outputFileInfo.FullName, ".hdr"));
            }
            else
            {
                //var bitmap = tex.TransferToBMP(null, 0.45f, tonemapping ? exposure : -1.0f);
                //FileStream stream = new FileStream(outputFileInfo.FullName, FileMode.Create, FileAccess.Write);
                //bitmap.Save(stream, ImageFormat.Bmp);
                //stream.Close();
                //bitmap.Dispose();
                tex.Save(outputFileInfo.FullName);
            }

            return(true);
        }
Exemple #4
0
        //private void fastPreviewButton_Click(object sender, EventArgs e)
        //{
        //    if (m_Scene == null)
        //        return;
        //    uint width = string.IsNullOrEmpty(this.widthInputBox.Text) ? 0 : uint.Parse(this.widthInputBox.Text);
        //    uint height = string.IsNullOrEmpty(this.heightInputBox.Text) ? 0 : uint.Parse(this.heightInputBox.Text);
        //    if (width <= 0 || height <= 0)
        //    {
        //        MessageBox.Show("请输入宽高合法的宽高!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //        return;
        //    }
        //    Log.Info("开始快速预览");

        //    Stopwatch stopWatch = new Stopwatch();
        //    stopWatch.Start();
        //    this.progressBar.Value = 0;
        //    this.progressBar.Maximum = 100;
        //    m_Result = m_Scene.FastRender(width, height, this.ProgressCallBack);
        //    stopWatch.Stop();

        //    if (m_Result != null)
        //    {
        //        Log.CompleteInfo($"渲染完成,总计用时:{stopWatch.ElapsedMilliseconds}");

        //        if (m_Bitmap != null)
        //        {
        //            m_Bitmap.Dispose();
        //            m_Bitmap = null;
        //        }

        //        m_Bitmap = m_Result.TransferToBMP(m_Bitmap, 0.45f);
        //        this.renderResultBox.BackgroundImage = m_Bitmap;

        //        this.progressBar.Value = 0;
        //    }
        //    else
        //        Log.Err("渲染预览!");
        //}

        private void renderButton_Click(object sender, EventArgs e)
        {
            if (m_Scene == null)
            {
                return;
            }
            int  traceTimes    = string.IsNullOrEmpty(this.bounceInputBox.Text)?0: int.Parse(this.bounceInputBox.Text);
            int  numSamples    = string.IsNullOrEmpty(this.numSampleInputBox.Text) ? 0 : int.Parse(this.numSampleInputBox.Text);
            var  sampleType    = (SamplerType)this.samplerTypeCombo.SelectedIndex;
            var  renderChannel = (RenderChannel)this.renderChannelCombo.SelectedIndex;
            uint width         = string.IsNullOrEmpty(this.widthInputBox.Text) ? 0 : uint.Parse(this.widthInputBox.Text);
            uint height        = string.IsNullOrEmpty(this.heightInputBox.Text) ? 0 : uint.Parse(this.heightInputBox.Text);

            float exposure = -1.0f;

            if (this.tonemappingCheckBox.Checked && !string.IsNullOrEmpty(this.exposureInputBox.Text))
            {
                exposure = float.Parse(this.exposureInputBox.Text);
            }

            //if (renderChannel == RenderChannel.Full && traceTimes <= 0)
            //{
            //    MessageBox.Show("不允许反弹次数小于等于0!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}
            if (traceTimes < 0)
            {
                traceTimes = 0;
            }

            //if (renderChannel == RenderChannel.Full && numSamples <= 0)
            //{
            //    MessageBox.Show("不允许采样次数小于等于0!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}
            if (numSamples <= 0)
            {
                numSamples = 1;
            }

            if (width <= 0 || height <= 0)
            {
                MessageBox.Show("请输入宽高合法的宽高!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Log.Info("开始渲染");

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            this.progressBar.Value   = 0;
            this.progressBar.Maximum = 100;
            var pt = new ASL.PathTracer.PathTracer(m_Scene);
            //var pt = new ASL.PathTracer.VolumeTextureRenderer(m_Scene);
            ///var pt = new ASL.PathTracer.PRTRenderer(m_Scene);
            RenderConfig config = new RenderConfig()
            {
                traceTimes  = traceTimes,
                samplerType = sampleType,
                numSamples  = numSamples,
                numSets     = 83,
                width       = width,
                height      = height,
            };

            m_Result = pt.Render(config, this.ProgressCallBack);
            stopWatch.Stop();

            if (m_Result != null)
            {
                Log.CompleteInfo($"渲染完成,总计用时:{stopWatch.ElapsedMilliseconds}");

                if (m_Result is Texture)
                {
                    if (m_Bitmap != null)
                    {
                        m_Bitmap.Dispose();
                        m_Bitmap = null;
                    }

                    var tex = m_Result as Texture;
                    m_Bitmap = tex.TransferToBMP(m_Bitmap, 0.45f, exposure);
                    this.renderResultBox.BackgroundImage = m_Bitmap;
                    if (this.tonemappingCheckBox.Checked)
                    {
                        this.retonemappingButton.Enabled = true;
                    }
                }
                else
                {
                    this.renderResultBox.BackgroundImage = null;
                    this.retonemappingButton.Enabled     = false;
                }

                this.progressBar.Value = 0;
            }
            else
            {
                Log.Err("渲染失败!");
            }
        }