Ejemplo n.º 1
0
        /// <summary>
        /// BRDFで使用するLUTを生成する(UE4方式)
        /// </summary>
        public static Texture CreateBRDFLookUpTable(GraphicsContext context, int w, int h)
        {
            var tex = new Texture(new Texture.InitDesc {
                bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                width    = w,
                height   = h,
                format   = SlimDX.DXGI.Format.R16G16_Float,
            });

            Lib.Rect rect = new Lib.Rect(new Vector3(-1.0f, 1.0f, 0.0f), new Vector3(1.0f, -1.0f, 0.0f));
            var      prim = new Prim("GenerateBRDF_LUT", (uint)Shader.VertexAttr.TEXCOORD0);

            prim.AddRect(ref rect);
            prim.GetMaterial().DepthState = RenderState.DepthState.None;

            GraphicsCore.FrameBuffer frameBuffer = new GraphicsCore.FrameBuffer();
            frameBuffer.color_buffer_ = new Texture[1] {
                tex
            };

            context.SetRenderTargets(frameBuffer.color_buffer_, null);
            prim.Draw(context);
            prim.Dispose();
            return(tex);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 public void BeginRender(GraphicsContext context)
 {
     GraphicsCore.CurrentDrawCamera = camera_;
     context.SetRenderTargets(frameBuffer_.color_buffer_, frameBuffer_.depth_stencil_);
     context.SetViewport(new SlimDX.Direct3D11.Viewport(0, 0, frameBuffer_.depth_stencil_.Width, frameBuffer_.depth_stencil_.Height));
     context.ClearDepthStencil(frameBuffer_.depth_stencil_, 1.0f);
     ShaderManager.UserShaderBindHandler += shadowMapDrawShaderFunc_;
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        public void Dispatch(GraphicsContext context, Texture depth, Camera camera)
        {
            float near = camera.Near;
            float far  = camera.Far;

            param_.g_ReprojectDepthScale = (far - near) / (-far * near);
            param_.g_ReprojectDepthBias  = far / (far * near);
            frameBuffer_.color_buffer_   = new Texture[1] {
                linearBuffer_
            };
            frameBuffer_.depth_stencil_ = null;
            context.SetRenderTargets(frameBuffer_.color_buffer_, frameBuffer_.depth_stencil_);
            RenderingUtil.DrawScreen(context, linearizeShader_, new Texture[] { depth });
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        public void EndRender(GraphicsContext context)
        {
            ShaderManager.UserShaderBindHandler -= shadowMapDrawShaderFunc_;

            // Generate SM
            blurFrameBuffer_.color_buffer_[0] = blurMap_[0];
            context.SetRenderTargets(blurFrameBuffer_.color_buffer_, blurFrameBuffer_.depth_stencil_);
            context.SetViewport(new SlimDX.Direct3D11.Viewport(0, 0, blurFrameBuffer_.color_buffer_[0].Width, blurFrameBuffer_.color_buffer_[0].Height));
            blurPrim_.GetMaterial().SetShader(shaderName_[(int)type_]);
            blurPrim_.GetMaterial().SetShaderViewPS(0, shadowMap_);
            blurPrim_.Draw(context);

            blurFrameBuffer_.color_buffer_[0] = blurMap_[1];
            context.SetRenderTargets(blurFrameBuffer_.color_buffer_, blurFrameBuffer_.depth_stencil_);
            blurPrim_.GetMaterial().SetShader("GaussianBlurV");
            blurPrim_.GetMaterial().SetShaderViewPS(0, blurMap_[0]);
            blurPrim_.Draw(context);

            blurFrameBuffer_.color_buffer_[0] = blurMap_[0];
            context.SetRenderTargets(blurFrameBuffer_.color_buffer_, blurFrameBuffer_.depth_stencil_);
            blurPrim_.GetMaterial().SetShader("GaussianBlurH");
            blurPrim_.GetMaterial().SetShaderViewPS(0, blurMap_[1]);
            blurPrim_.Draw(context);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 輝度算出
        /// </summary>
        public void CalcLuminance(GraphicsContext context, Texture colorTex)
        {
            // 1/4
            frameBuffer_.color_buffer_[0] = avgBuffer_[0];
            context.SetRenderTargets(frameBuffer_.color_buffer_, null);
            prim_.GetMaterial().SetShader(downSample4Lum_);
            prim_.GetMaterial().SetShaderViewPS(0, colorTex);
            prim_.Draw(context);

            // 1/4
            frameBuffer_.color_buffer_[0] = avgBuffer_[1];
            context.SetRenderTargets(frameBuffer_.color_buffer_, null);
            prim_.GetMaterial().SetShader(downSample4_);
            prim_.GetMaterial().SetShaderViewPS(0, avgBuffer_[0]);
            prim_.Draw(context);

            // 1/2
            frameBuffer_.color_buffer_[0] = avgBuffer_[2];
            context.SetRenderTargets(frameBuffer_.color_buffer_, null);
            prim_.GetMaterial().SetShader(downSample2_);
            prim_.GetMaterial().SetShaderViewPS(0, avgBuffer_[1]);
            prim_.Draw(context);

            // 1/2
            frameBuffer_.color_buffer_[0] = avgBuffer_[3];
            context.SetRenderTargets(frameBuffer_.color_buffer_, null);
            prim_.GetMaterial().SetShaderViewPS(0, avgBuffer_[2]);
            prim_.Draw(context);

            // 1/2
            frameBuffer_.color_buffer_[0] = avgBuffer_[4];
            context.SetRenderTargets(frameBuffer_.color_buffer_, null);
            prim_.GetMaterial().SetShaderViewPS(0, avgBuffer_[3]);
            prim_.Draw(context);

            // 1/2
            frameBuffer_.color_buffer_[0] = avgBuffer_[5];
            context.SetRenderTargets(frameBuffer_.color_buffer_, null);
            prim_.GetMaterial().SetShaderViewPS(0, avgBuffer_[4]);
            prim_.Draw(context);

            // 最終
            if (!initBuffer_)
            {
                context.ClearRenderTarget(luminanceAvg_, new Color4(0, 0, 0, 0));
                initBuffer_ = true;
            }
            lumResolveShader_.Bind();
            lumResolveShader_.Dispatch(1, 1, 1);
            lumResolveShader_.UnBind();
        }