Esempio n. 1
0
        /// <summary>
        /// キューブマップにレンダリング
        /// </summary>
        public static void RenderingCubeMap(GraphicsContext context, Texture cubemap, Texture depth, Vector3 position, Action sceneDrawFunc)
        {
            GraphicsCore.FrameBuffer frameBuffer = new GraphicsCore.FrameBuffer()
            {
                color_buffer_ = new Texture[1] {
                    cubemap
                },
                depth_stencil_   = depth,
                is_array_buffer_ = true,
            };

            Camera backupCamera = GraphicsCore.CurrentDrawCamera;
            Camera camera       = new Camera();
            // 右手対応のためx反転している
            Matrix projection = Matrix.PerspectiveFovRH((float)System.Math.PI / 2.0f, 1.0f, 0.1f, 1000.0f) * Matrix.Scaling(-1, 1, 1);
            Matrix view       = Matrix.LookAtRH(position, Vector3.Zero, Vector3.UnitZ);

            camera.InitializeExternal(view, projection);
            GraphicsCore.CurrentDrawCamera = camera;
            GraphicsCore.SetRasterizerState(RenderState.RasterizerState.CullFront);

            // 各面をレンダリング
            for (int i = 0; i < 6; ++i)
            {
                Vector3 lookAt = new Vector3();
                Vector3 upVec  = new Vector3();
                switch (i)
                {
                case 0:
                    lookAt = new Vector3(1.0f, 0.0f, 0.0f);
                    upVec  = new Vector3(0.0f, 1.0f, 0.0f);
                    break;

                case 1:
                    lookAt = new Vector3(-1.0f, 0.0f, 0.0f);
                    upVec  = new Vector3(0.0f, 1.0f, 0.0f);
                    break;

                case 2:
                    lookAt = new Vector3(0.0f, 1.0f, 0.0f);
                    upVec  = new Vector3(0.0f, 0.0f, -1.0f);
                    break;

                case 3:
                    lookAt = new Vector3(0.0f, -1.0f, 0.0f);
                    upVec  = new Vector3(0.0f, 0.0f, 1.0f);
                    break;

                case 4:
                    lookAt = new Vector3(0.0f, 0.0f, 1.0f);
                    upVec  = new Vector3(0.0f, 1.0f, 0.0f);
                    break;

                case 5:
                    lookAt = new Vector3(0.0f, 0.0f, -1.0f);
                    upVec  = new Vector3(0.0f, 1.0f, 0.0f);
                    break;
                }

                frameBuffer.array_buffer_index_ = i;
                view = Matrix.LookAtRH(position, position + lookAt, upVec);
                camera.SetViewMatrix(ref view);
                camera.Update();

                // TODO:要対応
                //GraphicsCore.BeginRender(frameBuffer);
                //sceneDrawFunc();
                //GraphicsCore.EndRender();
            }
            GraphicsCore.CurrentDrawCamera = backupCamera;
            GraphicsCore.SetRasterizerState(RenderState.RasterizerState.CullBack);
        }
Esempio n. 2
0
        /// <summary>
        /// 描画
        /// </summary>
        public void Draw()
        {
            var context = GraphicsCore.ImmediateContext;

            UpdateDraw();

            {
                // GBuffer
                using (new ksGpuProfilePoint(context, "Render GBuffer")) {
                    MyRenderer.CurrentDrawCamera = MyRenderer.Camera3D;
                    RenderGBuffer();
                }

                var framebuffer = new MyRenderer.FrameBuffer();
                var edgeBuffer  = hdrResolveBuffer_;
                // アウトライン検出
                using (new ksGpuProfilePoint(context, "Outline")) {
                    framebuffer.color_buffer_ = new Texture[] { hdrResolveBuffer_ };
                    context.SetRenderTargets(framebuffer.color_buffer_, framebuffer.depth_stencil_);
                    prim_.GetMaterial().SetShader("Outline");
                    prim_.GetMaterial().SetShaderViewPS(0, gbuffers_[0]);
                    prim_.GetMaterial().SetShaderViewPS(1, gbuffers_[1]);
                    prim_.GetMaterial().BlendState = RenderState.BlendState.None;
                    prim_.Draw(context);

                    //framebuffer.color_buffer_ = new Texture[] { gbuffers_[1] };
                    //ksRenderer.BeginRender(framebuffer);
                    //fxaaPrim_.GetMaterial().SetShaderViewPS(0, hdrResolveBuffer_);
                    //fxaaPrim_.Draw();
                    //ksRenderer.EndRender();
                    //edgeBuffer = gbuffers_[1];
                }

                // vertexIDによるスプライト描画
                using (new ksGpuProfilePoint(context, "LineSprite")) {
                    framebuffer.color_buffer_ = new Texture[] { gbuffers_[0] };
                    context.SetRenderTargets(framebuffer.color_buffer_, framebuffer.depth_stencil_);
                    if (test)
                    {
                        MyRenderer.D3D11ImmediateContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding());
                        lineSpriteMaterial_.SetShaderViewVS(0, edgeBuffer);
                        lineSpriteMaterial_.SetShaderViewPS(0, lineTexture_);
                        lineSpriteMaterial_.DepthState = RenderState.DepthState.None;
                        lineSpriteMaterial_.BlendState = RenderState.BlendState.Normal;
                        lineSpriteMaterial_.Setup(context);
                        Matrix ident = Matrix.Identity;
                        ShaderManager.SetUniformParams(ref ident);
                        MyRenderer.SetRasterizerState(RenderState.RasterizerState.CullNone);
                        int instance = hdrResolveBuffer_.Width * hdrResolveBuffer_.Height;
                        MyRenderer.D3D11ImmediateContext.DrawInstanced(6, instance, 0, 0);
                    }
                    else
                    {
                        prim_.GetMaterial().SetShader("Direct");
                        prim_.GetMaterial().SetShaderViewPS(0, hdrResolveBuffer_);
                        prim_.GetMaterial().BlendState = RenderState.BlendState.Normal;
                        prim_.Draw(context);
                    }
                }


                // 最終レンダリング
                MyRenderer.BeginRender();
                {
                    // ライティング結果
                    using (new ksGpuProfilePoint(context, "FXAA")) {
                        fxaaPrim_.GetMaterial().SetShaderViewPS(0, gbuffers_[0]);
                        fxaaPrim_.GetMaterial().BlendState = RenderState.BlendState.None;
                        fxaaPrim_.Draw(context);
                    }
                }
            }
        }