示例#1
0
        /// <summary>
        ///
        /// </summary>
        void ConstructTexture(int w, int h)
        {
            var desc = new Texture.InitDesc()
            {
                bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                width    = w,
                height   = h,
                format   = SlimDX.DXGI.Format.R16_Float,
            };

            if (linearBuffer_ == null)
            {
                linearBuffer_     = new Texture();
                linearHalfBuffer_ = new Texture();
            }
            else
            {
                linearBuffer_.Dispose();
                linearHalfBuffer_.Dispose();
            }
            linearBuffer_.Initialize(desc);
            desc.width  /= 2;
            desc.height /= 2;
            linearHalfBuffer_.Initialize(desc);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        public ShadowMap(int width, int height, Type type = Type.VSM)
        {
            type_         = type;
            shaderName_   = new string[] { "ConstructVSM", "ConstructEVSM" };
            bufferFormat_ = new Format[] { Format.R16G16_Float, Format.R16G16B16A16_Float };

            shadowMap_ = new Texture(new Texture.InitDesc {
                width    = width,
                height   = height,
                format   = Format.R32_Typeless,
                bindFlag = TextureBuffer.BindFlag.IsDepthStencil,
            });

            blurMap_ = new Texture[2];
            for (int i = 0; i < blurMap_.Length; i++)
            {
                Texture.InitDesc desc = new Texture.InitDesc()
                {
                    width    = width / 2,
                    height   = height / 2,
                    format   = bufferFormat_[(int)type_],
                    bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                };
                blurMap_[i] = new Texture(desc);
            }

            frameBuffer_ = new GraphicsCore.FrameBuffer()
            {
                color_buffer_  = new Texture[0],
                depth_stencil_ = shadowMap_,
            };
            blurFrameBuffer_ = new GraphicsCore.FrameBuffer()
            {
                color_buffer_  = new Texture[1],
                depth_stencil_ = null,
            };

            Lib.Rect rect = new Lib.Rect(new Vector3(-1.0f, 1.0f, 0.0f), new Vector3(1.0f, -1.0f, 0.0f));
            blurPrim_ = new Prim(shaderName_[(int)type_], (uint)Shader.VertexAttr.TEXCOORD0);
            blurPrim_.AddRect(ref rect);
            blurPrim_.GetMaterial().DepthState = RenderState.DepthState.None;

            camera_ = new Camera();
            camera_.InitializeOrtho(new Vector3(0, 100, 0), new Vector3(0, 0, 0), new Vector3(0, 0, 1), 100, 100, 1, 100);

            shadowCastShader_        = ShaderManager.FindShader("DrawShadowMap", (uint)(Shader.VertexAttr.POSITION));
            shadowMapDrawShaderFunc_ = (o) => {
                return(shadowCastShader_);
            };
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="w"></param>
        /// <param name="h"></param>
        void AllocateTexture(int w, int h)
        {
            if (rayTraceBuffer_ != null)
            {
                rayTraceBuffer_.Dispose();
            }
            else
            {
                rayTraceBuffer_ = new Texture();
            }

            var desc = new Texture.InitDesc()
            {
                bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                width    = w / 2,
                height   = h / 2,
                format   = SlimDX.DXGI.Format.R16G16B16A16_Float,
            };

            rayTraceBuffer_.Initialize(desc);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        public ToneMap()
        {
            // サイズによってテクスチャを作り替える、ということをしたくないので
            // FullHD想定でテクスチャを作成しておく
            int w = 1920;
            int h = 1080;

            avgBuffer_ = new Texture[6];
            var desc = new Texture.InitDesc()
            {
                bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                width    = w / 4,
                height   = h / 4,
                format   = SlimDX.DXGI.Format.R16_Float,
            };

            avgBuffer_[0] = new Texture(desc);
            desc.width    = w / 16;
            desc.height   = h / 16;
            avgBuffer_[1] = new Texture(desc);
            desc.width    = w / 32;
            desc.height   = h / 32;
            avgBuffer_[2] = new Texture(desc);
            desc.width    = w / 64;
            desc.height   = h / 64;
            avgBuffer_[3] = new Texture(desc);
            desc.width    = w / 128;
            desc.height   = h / 128;
            avgBuffer_[4] = new Texture(desc);
            desc.width    = w / 256;
            desc.height   = h / 256;
            avgBuffer_[5] = new Texture(desc);
            frameBuffer_  = new GraphicsCore.FrameBuffer()
            {
                color_buffer_  = new Texture[1],
                depth_stencil_ = null,
            };

            var uavDesc_ = new Texture.InitDesc {
                bindFlag = TextureBuffer.BindFlag.IsUnorderedAccess | TextureBuffer.BindFlag.IsRenderTarget,
                width    = 1,
                height   = 1,
                format   = SlimDX.DXGI.Format.R32_Float,                // RWとして使うためには32bitにする必要がある
            };

            luminanceAvg_ = new Texture(uavDesc_);

            Lib.Rect rect = new Lib.Rect(new Vector3(-1.0f, 1.0f, 0.0f), new Vector3(1.0f, -1.0f, 0.0f));
            prim_ = new Prim("Downsample4x4CalcLuminance", (uint)Shader.VertexAttr.TEXCOORD0);
            prim_.AddRect(ref rect);
            prim_.GetMaterial().DepthState = RenderState.DepthState.None;

            downSample4Lum_ = ShaderManager.FindShader("Downsample4x4CalcLuminance", (uint)Shader.VertexAttr.TEXCOORD0);
            downSample4_    = ShaderManager.FindShader("Downsample4x4Luminance", (uint)Shader.VertexAttr.TEXCOORD0);
            downSample2_    = ShaderManager.FindShader("Downsample2x2Luminance", (uint)Shader.VertexAttr.TEXCOORD0);
            toneMap_        = ShaderManager.FindShader("ToneMap", (uint)Shader.VertexAttr.TEXCOORD0);
            resolveGamma_   = ShaderManager.FindShader("ResolveGamma", (uint)Shader.VertexAttr.TEXCOORD0);

            ComputeShader.InitDesc shaderDesc = new ComputeShader.InitDesc {
                file_name    = "asset/shader/ToneMap.fx",
                id           = 0,
                is_byte_code = false,
                main         = "FinalCalculateAverageLuminance",
            };
            lumResolveShader_ = new ComputeShader(shaderDesc);
            lumResolveShader_.SetUAVs(new Texture[] { luminanceAvg_ });
            lumResolveShader_.SetResources(new Texture[] { avgBuffer_[5] });
            initBuffer_ = false;

            KeyValue = 0.2f;
            Shader.SetConstantBufferUpdateFunc("CB_ToneMap", (s, i) => {
                dynamic cb = i;
                if (cb.g_keyValue != KeyValue)
                {
                    cb.g_keyValue = KeyValue;
                    return(true);
                }
                return(false);
            });
        }