Example #1
0
        /// <summary>
        /// レンダーターゲット初期化
        /// </summary>
        void InitializeTarget()
        {
            // deferred用MRTバッファ
            gbufferDesc_ = new Texture.InitDesc[] {
                new Texture.InitDesc()
                {
                    bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                    width    = GraphicsCore.TargetWidth,
                    height   = GraphicsCore.TargetHeight,
                    format   = SlimDX.DXGI.Format.R16G16B16A16_Float,
                },
                new Texture.InitDesc()
                {
                    bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                    width    = GraphicsCore.TargetWidth,
                    height   = GraphicsCore.TargetHeight,
                    format   = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                },
                new Texture.InitDesc()
                {
                    bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                    width    = GraphicsCore.TargetWidth,
                    height   = GraphicsCore.TargetHeight,
                    format   = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                },
            };
            gbuffers_ = new Texture[gbufferDesc_.Length];
            for (int i = 0; i < gbuffers_.Length; i++)
            {
                gbuffers_[i] = new Texture(gbufferDesc_[i]);
            }
            deferredBuffer_ = new GraphicsCore.FrameBuffer();
            deferredBuffer_.color_buffer_  = gbuffers_;
            deferredBuffer_.depth_stencil_ = GraphicsCore.DefaultDepthBuffer;

            uavDesc_ = new Texture.InitDesc {
                bindFlag = TextureBuffer.BindFlag.IsRenderTarget | TextureBuffer.BindFlag.IsUnorderedAccess,
                width    = GraphicsCore.TargetWidth,
                height   = GraphicsCore.TargetHeight,
                format   = SlimDX.DXGI.Format.R16G16B16A16_Float,
            };
            uav_ = new Texture(uavDesc_);
            csMgr_.SetUAVs(new Texture[] { uav_ });
            var bufs = new IShaderView[] { gbuffers_[0], gbuffers_[1], gbuffers_[2], GraphicsCore.DefaultDepthBuffer, lightMgr_.LightBuffer, shadowMap_.Map };

            csMgr_.SetResources(bufs);

            hdrResolveDesc_ = new Texture.InitDesc()
            {
                bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                width    = GraphicsCore.TargetWidth,
                height   = GraphicsCore.TargetHeight,
                format   = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
            };
            hdrResolveBuffer_ = new Texture(hdrResolveDesc_);

            forwardBuffer_ = new GraphicsCore.FrameBuffer();
            forwardBuffer_.color_buffer_  = new Texture[] { uav_ };
            forwardBuffer_.depth_stencil_ = GraphicsCore.DefaultDepthBuffer;

            hdrResultBuffer_ = new GraphicsCore.FrameBuffer();
            hdrResultBuffer_.color_buffer_  = new Texture[] { hdrResolveBuffer_ };
            hdrResultBuffer_.depth_stencil_ = null;

            // キューブマップ
            int cubeSize = 128;

            globalCapture_ = new ReflectionCapture(cubeSize, new Vector3(0, 3, 0));
            localCapture_  = new List <ReflectionCapture>();
            giTextures_    = new Texture[3];
            if (System.IO.File.Exists("asset/gitex_r.dds"))
            {
                giTextures_[0] = new Texture("asset/gitex_r.dds");
                giTextures_[1] = new Texture("asset/gitex_g.dds");
                giTextures_[2] = new Texture("asset/gitex_b.dds");
                csMgr_.SetResources(6, giTextures_[0]);
                csMgr_.SetResources(7, giTextures_[1]);
                csMgr_.SetResources(8, giTextures_[2]);
                cubeMapRenderEnable_ = false;
            }

            // グリッド上で生成
            if (cubeMapRenderEnable_)
            {
                Vector3 bounds = cubeMapInfo_.boundingMax - cubeMapInfo_.boundingMin;
                for (int z = 0; z < cubeMapInfo_.numZ; z++)
                {
                    for (int y = 0; y < cubeMapInfo_.numY; y++)
                    {
                        for (int x = 0; x < cubeMapInfo_.numX; x++)
                        {
                            Vector3 add = new Vector3(bounds.X * ((float)x / (cubeMapInfo_.numX - 1)),
                                                      bounds.Y * ((float)y / (cubeMapInfo_.numY - 1)),
                                                      bounds.Z * ((float)z / (cubeMapInfo_.numZ - 1))
                                                      );
                            Vector3 pos = cubeMapInfo_.boundingMin + add;
                            localCapture_.Add(new ReflectionCapture(cubeSize, pos));
                        }
                    }
                }
            }

            // アンチなし用プリム
            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("Direct", (uint)Shader.VertexAttr.TEXCOORD0);
            prim_.AddRect(ref rect);
            prim_.GetMaterial().SetShaderViewPS(0, gbuffers_[0]);
            prim_.GetMaterial().DepthState = RenderState.DepthState.None;

            // FXAA
            fxaaPrim_ = new Prim("FXAA", (uint)Shader.VertexAttr.TEXCOORD0);
            fxaaPrim_.AddRect(ref rect);
            fxaaPrim_.GetMaterial().SetShaderViewPS(0, hdrResolveBuffer_);
            fxaaPrim_.GetMaterial().DepthState = RenderState.DepthState.None;

            // デバッグ表示用
            debugViewList_ = new Texture[] {
                hdrResolveBuffer_,
                gbuffers_[0],
                gbuffers_[1],
                gbuffers_[2],
                shadowMap_.Map,
                toneMap_.LuminanceAvgTexture,
            };
        }
Example #2
0
        /// <summary>
        /// レンダーターゲット初期化
        /// </summary>
        void InitializeTarget()
        {
            // deferred用MRTバッファ
            gbufferDesc_ = new Texture.InitDesc[] {
                new Texture.InitDesc()
                {
                    bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                    width    = MyRenderer.TargetWidth,
                    height   = MyRenderer.TargetHeight,
                    format   = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                },
                new Texture.InitDesc()
                {
                    bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                    width    = MyRenderer.TargetWidth,
                    height   = MyRenderer.TargetHeight,
                    format   = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
                },
            };
            gbuffers_ = new Texture[gbufferDesc_.Length];
            for (int i = 0; i < gbuffers_.Length; i++)
            {
                gbuffers_[i] = new Texture(gbufferDesc_[i]);
            }
            gBufferBinder_ = new MyRenderer.FrameBuffer();
            gBufferBinder_.color_buffer_  = gbuffers_;
            gBufferBinder_.depth_stencil_ = MyRenderer.DefaultDepthBuffer;

            hdrResolveDesc_ = new Texture.InitDesc()
            {
                bindFlag = TextureBuffer.BindFlag.IsRenderTarget,
                width    = MyRenderer.TargetWidth,
                height   = MyRenderer.TargetHeight,
                format   = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
            };
            hdrResolveBuffer_ = new Texture(hdrResolveDesc_);

            hdrResultBuffer_ = new MyRenderer.FrameBuffer();
            hdrResultBuffer_.color_buffer_  = new Texture[] { hdrResolveBuffer_ };
            hdrResultBuffer_.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));
            prim_ = new Prim("Outline", (uint)Shader.VertexAttr.TEXCOORD0);
            prim_.AddRect(ref rect);
            prim_.GetMaterial().SetShaderViewPS(0, gbuffers_[0]);
            prim_.GetMaterial().DepthState = RenderState.DepthState.None;

            // FXAA
            fxaaPrim_ = new Prim("FXAA", (uint)Shader.VertexAttr.TEXCOORD0);
            fxaaPrim_.AddRect(ref rect);
            fxaaPrim_.GetMaterial().SetShaderViewPS(0, hdrResolveBuffer_);
            fxaaPrim_.GetMaterial().DepthState = RenderState.DepthState.None;

            // ラインスプライト
            lineSpriteMaterial_ = new Material();
            lineSpriteMaterial_.SetShader("LineSprite", 0);
            lineTexture_ = new Texture("asset/texture/circle32x32_2.png");

            Lib.Shader.SetConstantBufferUpdateFunc("CB_LineSprite", (o, e) => {
                dynamic cb       = e;
                cb.g_screenScale = new Vector4(hdrResolveBuffer_.Width, hdrResolveBuffer_.Height, 1.0f / hdrResolveBuffer_.Width, 1.0f / hdrResolveBuffer_.Height);
                return(true);
            });

            // デバッグ表示用
            debugViewList_ = new Texture[] {
                hdrResolveBuffer_,
                gbuffers_[0],
                gbuffers_[1],
            };
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="max_num"></param>
        public LightManager(int max_num)
        {
            int size = structSize * max_num;

            count_ = max_num;

            lightList_ = new Light[max_num];
            stream_    = new DataStream(size, true, true);

            // 構造化バッファ生成
            StructuredBuffer.BufferDesc desc = new StructuredBuffer.BufferDesc {
                bindUAV  = true,
                stride   = structSize,
                size     = (int)size,
                initData = null,
            };
            buffer_ = new StructuredBuffer(desc);

#if true
            // ライトセットアップ(仮)
            Random    rand     = new Random(0);
            Vector3[] colorAry = new Vector3[] {
                new Vector3(1, 0, 0),
                new Vector3(0, 1, 0),
                new Vector3(0, 0, 1),
                new Vector3(1, 1, 1),
            };
            float scale   = 0.2f;
            float range_x = 150 * scale;
            float range_y = 70 * scale;
            float range_z = 65 * scale;
            for (int i = 0; i < count_; i++)
            {
                var   light = new Light();
                float x     = (float)(rand.NextDouble() - 0.5) * 2 * range_x;
                float y     = (float)(rand.NextDouble() - 0.0) * 2 * range_y;
                float z     = (float)(rand.NextDouble() - 0.5) * 2 * range_z;
                light.pos       = new Vector3(x, y, z);
                light.color     = colorAry[i % colorAry.Length];
                light.radius    = 5;
                light.intensity = 4.0f;
                SetLight(i, light);
            }
#else
            var light = new Light();
            light.pos       = new Vector3(0, 10, 0);
            light.color     = new Vector3(1, 1, 1);
            light.intensity = 80;

            SetLight(0, light);
#endif

            DirectionalLightDir = new Vector3(0.3f, -1.0f, 0.2f);
            DirectionalLightDir.Normalize();
            DirectionalLightIntensity = 2;

            //float primSize = 2.0f;
            float    primSize = 0.5f;
            Lib.Rect rect     = new Lib.Rect(new Vector3(-primSize, primSize, 0.0f), new Vector3(primSize, -primSize, 0.0f));
            debugPrim_ = new Prim("DebugDrawPointLights", (uint)Shader.VertexAttr.TEXCOORD0);
            debugPrim_.AddRect(ref rect);
            debugPrim_.GetMaterial().SetShaderViewVS(0, LightBuffer);
            debugPrim_.GetMaterial().SetShaderViewPS(0, LightBuffer);
            debugPrim_.GetMaterial().BlendState = RenderState.BlendState.Add;
            debugPrim_.GetMaterial().DepthState = RenderState.DepthState.TestOnly;
        }