public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            byte[] vertexShaderBytecode = File.ReadAllBytes("Triangles.VertexShader.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] basicVertexLayoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(basicVertexLayoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes("Triangles.PixelShader.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            var vertexBufferDesc = D3D11BufferDesc.From(triangleVertices, D3D11BindOptions.VertexBuffer);

            this.vertexBuffer = this.deviceResources.D3DDevice.CreateBuffer(vertexBufferDesc, triangleVertices, 0, 0);

            var indexBufferDesc = D3D11BufferDesc.From(triangleIndices, D3D11BindOptions.IndexBuffer);

            this.indexBuffer = this.deviceResources.D3DDevice.CreateBuffer(indexBufferDesc, triangleIndices, 0, 0);
        }
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "NORMAL",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes("PixelShader.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            pixelShaderBytecode   = File.ReadAllBytes("PixelShaderSolid.cso");
            this.pixelShaderSolid = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            var vertexBufferDesc = D3D11BufferDesc.From(MainGameComponent.Vertices, D3D11BindOptions.VertexBuffer);

            this.vertexBuffer = this.deviceResources.D3DDevice.CreateBuffer(vertexBufferDesc, MainGameComponent.Vertices, 0, 0);

            var indexBufferDesc = D3D11BufferDesc.From(MainGameComponent.Indices, D3D11BindOptions.IndexBuffer);

            this.indexBuffer = this.deviceResources.D3DDevice.CreateBuffer(indexBufferDesc, MainGameComponent.Indices, 0, 0);

            var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer);

            this.constantBuffer = this.deviceResources.D3DDevice.CreateBuffer(constantBufferDesc);

            this.worldMatrix = XMMatrix.Identity;

            XMVector eye = new XMVector(0.0f, 4.0f, -10.0f, 0.0f);
            XMVector at  = new XMVector(0.0f, 1.0f, 0.0f, 0.0f);
            XMVector up  = new XMVector(0.0f, 1.0f, 0.0f, 0.0f);

            this.viewMatrix = XMMatrix.LookAtLH(eye, at, up);
        }
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            var d3dDevice = this.deviceResources.D3DDevice;

            // Create the shaders
            byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso");
            this.g_pVertexShader       = d3dDevice.CreateVertexShader(vertexShaderBytecode, null);
            this.g_pHullShaderInteger  = d3dDevice.CreateHullShader(File.ReadAllBytes("HullShaderInteger.cso"), null);
            this.g_pHullShaderFracEven = d3dDevice.CreateHullShader(File.ReadAllBytes("HullShaderFracEven.cso"), null);
            this.g_pHullShaderFracOdd  = d3dDevice.CreateHullShader(File.ReadAllBytes("HullShaderFracOdd.cso"), null);
            this.g_pDomainShader       = d3dDevice.CreateDomainShader(File.ReadAllBytes("DomainShader.cso"), null);
            this.g_pPixelShader        = d3dDevice.CreatePixelShader(File.ReadAllBytes("PixelShader.cso"), null);
            this.g_pSolidColorPS       = d3dDevice.CreatePixelShader(File.ReadAllBytes("SolidColorPS.cso"), null);

            // Create our vertex input layout - this matches the BEZIER_CONTROL_POINT structure
            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.g_pPatchLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode);

            // Create constant buffers
            this.g_pcbPerFrame = d3dDevice.CreateBuffer(new D3D11BufferDesc(ConstantBufferConstants.Size, D3D11BindOptions.ConstantBuffer));

            // Create solid and wireframe rasterizer state objects
            D3D11RasterizerDesc rasterDesc = D3D11RasterizerDesc.Default;

            rasterDesc.CullMode           = D3D11CullMode.None;
            rasterDesc.IsDepthClipEnabled = true;

            rasterDesc.FillMode          = D3D11FillMode.Solid;
            this.g_pRasterizerStateSolid = d3dDevice.CreateRasterizerState(rasterDesc);

            rasterDesc.FillMode = D3D11FillMode.WireFrame;
            this.g_pRasterizerStateWireframe = d3dDevice.CreateRasterizerState(rasterDesc);

            D3D11BufferDesc vbdesc = D3D11BufferDesc.From(MobiusStrip.Points, D3D11BindOptions.VertexBuffer);

            this.g_pControlPointVB = d3dDevice.CreateBuffer(vbdesc, MobiusStrip.Points, 0, 0);

            XMFloat3 vecEye = new XMFloat3(1.0f, 1.5f, -3.5f);
            XMFloat3 vecAt  = new XMFloat3(0.0f, 0.0f, 0.0f);
            XMFloat3 vecUp  = new XMFloat3(0.0f, 1.0f, 0.0f);

            this.ViewMatrix = XMMatrix.LookAtLH(vecEye, vecAt, vecUp);
            this.EyePt      = vecEye;
        }
        protected override void CreateDeviceDependentResources()
        {
            base.CreateDeviceDependentResources();

            byte[] vertexShaderBytecode = File.ReadAllBytes(Lesson3Game.ShadersDirectory + "Cubes.VertexShader.cso");
            this.vertexShader = this.DeviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] basicVertexLayoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "COLOR",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.DeviceResources.D3DDevice.CreateInputLayout(basicVertexLayoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes(Lesson3Game.ShadersDirectory + "Cubes.PixelShader.cso");
            this.pixelShader = this.DeviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            var vertexBufferDesc = D3D11BufferDesc.From(cubeVertices, D3D11BindOptions.VertexBuffer);

            this.vertexBuffer = this.DeviceResources.D3DDevice.CreateBuffer(vertexBufferDesc, cubeVertices, 0, 0);

            var indexBufferDesc = D3D11BufferDesc.From(cubeIndices, D3D11BindOptions.IndexBuffer);

            this.indexBuffer = this.DeviceResources.D3DDevice.CreateBuffer(indexBufferDesc, cubeIndices, 0, 0);

            var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer);

            this.constantBuffer = this.DeviceResources.D3DDevice.CreateBuffer(constantBufferDesc);

            this.constantBufferData.View = new Float4X4(
                -1.00000000f, 0.00000000f, 0.00000000f, 0.00000000f,
                0.00000000f, 0.89442718f, 0.44721359f, 0.00000000f,
                0.00000000f, 0.44721359f, -0.89442718f, -2.23606800f,
                0.00000000f, 0.00000000f, 0.00000000f, 1.00000000f
                );
        }
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes("PixelShader.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            var vertexBufferDesc = new D3D11BufferDesc(MaxVertices * 12, D3D11BindOptions.VertexBuffer);

            this.vertexBuffer = this.deviceResources.D3DDevice.CreateBuffer(vertexBufferDesc);

            var indexBufferDesc = new D3D11BufferDesc(MaxIndices * 2, D3D11BindOptions.IndexBuffer);

            this.indexBuffer = this.deviceResources.D3DDevice.CreateBuffer(indexBufferDesc);

            var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer);

            this.constantBuffer = this.deviceResources.D3DDevice.CreateBuffer(constantBufferDesc);

            this.worldMatrix = XMMatrix.Identity;

            XMVector vecAt  = this.cameraOrigins[(int)this.CollisionGroup];
            XMVector vecEye = new(vecAt.X, vecAt.Y + 20.0f, (this.CollisionGroup == CollisionGroup.Frustum) ? (vecAt.Z + 20.0f) : (vecAt.Z - 20.0f), 0.0f);
            XMVector vecUp  = new(0.0f, 1.0f, 0.0f, 0.0f);

            this.viewMatrix = XMMatrix.LookAtLH(vecEye, vecAt, vecUp);
        }
        private void CreateInputLayout(byte[] bytecode, D3D11InputElementDesc[] layoutDesc, out D3D11InputLayout layout)
        {
            if (layoutDesc == null)
            {
                // If no input layout is specified, use the BasicVertex layout.
                D3D11InputElementDesc[] basicVertexLayoutDesc = new D3D11InputElementDesc[]
                {
                    new D3D11InputElementDesc
                    {
                        SemanticName         = "POSITION",
                        SemanticIndex        = 0,
                        Format               = DxgiFormat.R32G32B32Float,
                        InputSlot            = 0,
                        AlignedByteOffset    = 0,
                        InputSlotClass       = D3D11InputClassification.PerVertexData,
                        InstanceDataStepRate = 0
                    },
                    new D3D11InputElementDesc
                    {
                        SemanticName         = "NORMAL",
                        SemanticIndex        = 0,
                        Format               = DxgiFormat.R32G32B32Float,
                        InputSlot            = 0,
                        AlignedByteOffset    = 12,
                        InputSlotClass       = D3D11InputClassification.PerVertexData,
                        InstanceDataStepRate = 0
                    },
                    new D3D11InputElementDesc
                    {
                        SemanticName         = "TEXCOORD",
                        SemanticIndex        = 0,
                        Format               = DxgiFormat.R32G32Float,
                        InputSlot            = 0,
                        AlignedByteOffset    = 24,
                        InputSlotClass       = D3D11InputClassification.PerVertexData,
                        InstanceDataStepRate = 0
                    }
                };

                layout = this.d3dDevice.CreateInputLayout(basicVertexLayoutDesc, bytecode);
            }
            else
            {
                layout = this.d3dDevice.CreateInputLayout(layoutDesc, bytecode);
            }
        }
Example #7
0
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            // Create the shaders
            byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            byte[] pixelShaderBytecode = File.ReadAllBytes("PixelShader.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            // Create a layout for the object data
            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "NORMAL",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "TEXCOORD",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 24,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode);

            // Create state objects
            D3D11SamplerDesc samplerDesc = new(
                D3D11Filter.MinMagMipLinear,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                0.0f,
                1,
                D3D11ComparisonFunction.Always,
                new float[] { 0.0f, 0.0f, 0.0f, 0.0f },
                0.0f,
                float.MaxValue);

            this.samplerLinear = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc);

            // Create constant buffers
            this.perObjectConstantBuffer = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(PerObjectConstantBuffer.Size, D3D11BindOptions.ConstantBuffer));

            this.perFrameConstantBuffer = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(PerFrameConstantBuffer.Size, D3D11BindOptions.ConstantBuffer));

            // Create other render resources here
        }
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            byte[] vertexShaderBytecode = File.ReadAllBytes("SceneVS.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32A32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "COLOR",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32A32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0xffffffff,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.vertexLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes("ScenePS.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            // Set up vertex buffer
            float fRight = -10.0f;
            float fTop   = -10.0f;
            float fLeft  = 10.0f;
            float fLowH  = -5.0f;

            // Fill the vertex buffer
            var vertices = new SceneVertex[12];

            vertices[0].Pos = new XMFloat4(fLeft, fLowH, 50.0f, 1.0f);
            vertices[1].Pos = new XMFloat4(fLeft, fTop, 50.0f, 1.0f);
            vertices[2].Pos = new XMFloat4(fRight, fLowH, 50.0f, 1.0f);
            vertices[3].Pos = new XMFloat4(fRight, fTop, 50.0f, 1.0f);

            vertices[0].Color = new XMFloat4(1.0f, 0.0f, 0.0f, 0.5f);
            vertices[1].Color = new XMFloat4(1.0f, 0.0f, 0.0f, 0.5f);
            vertices[2].Color = new XMFloat4(1.0f, 0.0f, 0.0f, 0.5f);
            vertices[3].Color = new XMFloat4(1.0f, 0.0f, 0.0f, 0.5f);

            vertices[4].Pos = new XMFloat4(fLeft, fLowH, 60.0f, 1.0f);
            vertices[5].Pos = new XMFloat4(fLeft, fTop, 60.0f, 1.0f);
            vertices[6].Pos = new XMFloat4(fRight, fLowH, 40.0f, 1.0f);
            vertices[7].Pos = new XMFloat4(fRight, fTop, 40.0f, 1.0f);

            vertices[4].Color = new XMFloat4(0.0f, 1.0f, 0.0f, 0.5f);
            vertices[5].Color = new XMFloat4(0.0f, 1.0f, 0.0f, 0.5f);
            vertices[6].Color = new XMFloat4(0.0f, 1.0f, 0.0f, 0.5f);
            vertices[7].Color = new XMFloat4(0.0f, 1.0f, 0.0f, 0.5f);

            vertices[8].Pos  = new XMFloat4(fLeft, fLowH, 40.0f, 1.0f);
            vertices[9].Pos  = new XMFloat4(fLeft, fTop, 40.0f, 1.0f);
            vertices[10].Pos = new XMFloat4(fRight, fLowH, 60.0f, 1.0f);
            vertices[11].Pos = new XMFloat4(fRight, fTop, 60.0f, 1.0f);

            vertices[8].Color  = new XMFloat4(0.0f, 0.0f, 1.0f, 0.5f);
            vertices[9].Color  = new XMFloat4(0.0f, 0.0f, 1.0f, 0.5f);
            vertices[10].Color = new XMFloat4(0.0f, 0.0f, 1.0f, 0.5f);
            vertices[11].Color = new XMFloat4(0.0f, 0.0f, 1.0f, 0.5f);

            var vertexBufferDesc = D3D11BufferDesc.From(vertices, D3D11BindOptions.VertexBuffer, D3D11Usage.Immutable);

            this.vertexBuffer = this.deviceResources.D3DDevice.CreateBuffer(vertexBufferDesc, vertices, 0, 0);

            var constantBufferDesc = new D3D11BufferDesc(SceneVertexShaderConstantBufferData.Size, D3D11BindOptions.ConstantBuffer);

            this.vertexShaderConstantBuffer = this.deviceResources.D3DDevice.CreateBuffer(constantBufferDesc);
        }
Example #9
0
        protected override void CreateDeviceDependentResources()
        {
            base.CreateDeviceDependentResources();

            byte[] vertexShaderBytecode = File.ReadAllBytes(Lesson4Game.ShadersDirectory + "Textures.VertexShader.cso");
            this.vertexShader = this.DeviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] basicVertexLayoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "NORMAL",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "TEXCOORD",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 24,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.DeviceResources.D3DDevice.CreateInputLayout(basicVertexLayoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes(Lesson4Game.ShadersDirectory + "Textures.PixelShader.cso");
            this.pixelShader = this.DeviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            var vertexBufferDesc = D3D11BufferDesc.From(cubeVertices, D3D11BindOptions.VertexBuffer);

            this.vertexBuffer = this.DeviceResources.D3DDevice.CreateBuffer(vertexBufferDesc, cubeVertices, 0, 0);

            var indexBufferDesc = D3D11BufferDesc.From(cubeIndices, D3D11BindOptions.IndexBuffer);

            this.indexBuffer = this.DeviceResources.D3DDevice.CreateBuffer(indexBufferDesc, cubeIndices, 0, 0);

            var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer);

            this.constantBuffer = this.DeviceResources.D3DDevice.CreateBuffer(constantBufferDesc);

            this.constantBufferData.View = new Float4X4(
                -1.00000000f, 0.00000000f, 0.00000000f, 0.00000000f,
                0.00000000f, 0.89442718f, 0.44721359f, 0.00000000f,
                0.00000000f, 0.44721359f, -0.89442718f, -2.23606800f,
                0.00000000f, 0.00000000f, 0.00000000f, 1.00000000f
                );

            byte[] textureData = File.ReadAllBytes("../../texturedata.bin");

            D3D11Texture2DDesc textureDesc = new D3D11Texture2DDesc(DxgiFormat.R8G8B8A8UNorm, 256, 256, 1, 1);

            D3D11SubResourceData[] textureSubResData = new[]
            {
                new D3D11SubResourceData(textureData, 1024)
            };

            using (var texture = this.DeviceResources.D3DDevice.CreateTexture2D(textureDesc, textureSubResData))
            {
                D3D11ShaderResourceViewDesc textureViewDesc = new D3D11ShaderResourceViewDesc
                {
                    Format        = textureDesc.Format,
                    ViewDimension = D3D11SrvDimension.Texture2D,
                    Texture2D     = new D3D11Texture2DSrv
                    {
                        MipLevels       = textureDesc.MipLevels,
                        MostDetailedMip = 0
                    }
                };

                this.textureView = this.DeviceResources.D3DDevice.CreateShaderResourceView(texture, textureViewDesc);
            }

            D3D11SamplerDesc samplerDesc = new D3D11SamplerDesc(
                D3D11Filter.Anisotropic,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                0.0f,
                this.DeviceResources.D3DFeatureLevel > D3D11FeatureLevel.FeatureLevel91 ? D3D11Constants.DefaultMaxAnisotropy : D3D11Constants.FeatureLevel91DefaultMaxAnisotropy,
                D3D11ComparisonFunction.Never,
                new float[] { 0.0f, 0.0f, 0.0f, 0.0f },
                0.0f,
                float.MaxValue);

            this.sampler = this.DeviceResources.D3DDevice.CreateSamplerState(samplerDesc);
        }
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            //string fileName = Path.GetDirectoryName(this.OptFileName) + "\\" + Path.GetFileNameWithoutExtension(this.OptFileName) + "Exterior.opt";

            //OptFile opt;
            //if (File.Exists(fileName))
            //{
            //    opt = OptFile.FromFile(fileName);
            //}
            //else
            //{
            //    opt = OptFile.FromFile(this.OptFileName);
            //}

            OptFile opt = OptFile.FromFile(this.OptFileName);

            this.OptSize     = opt.Size * OptFile.ScaleFactor;
            this.OptSpanSize = opt.SpanSize.Scale(OptFile.ScaleFactor, OptFile.ScaleFactor, OptFile.ScaleFactor);

            Vector max = opt.MaxSize;
            Vector min = opt.MinSize;

            this.OptCenter = new Vector()
            {
                X = (max.X + min.X) / 2,
                Y = (max.Y + min.Y) / 2,
                Z = (max.Z + min.Z) / 2
            }.Scale(OptFile.ScaleFactor, OptFile.ScaleFactor, OptFile.ScaleFactor);

            this.CreateTextures(opt);
            this.CreateMeshes(opt);

            byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] basicVertexLayoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "NORMAL",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "TEXCOORD",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 24,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(basicVertexLayoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes("PixelShader.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer);

            this.constantBuffer = this.deviceResources.D3DDevice.CreateBuffer(constantBufferDesc);

            D3D11SamplerDesc samplerDesc = new D3D11SamplerDesc(
                D3D11Filter.Anisotropic,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                0.0f,
                this.deviceResources.D3DFeatureLevel > D3D11FeatureLevel.FeatureLevel91 ? D3D11Constants.DefaultMaxAnisotropy : D3D11Constants.FeatureLevel91DefaultMaxAnisotropy,
                D3D11ComparisonFunction.Never,
                new float[] { 0.0f, 0.0f, 0.0f, 0.0f },
                0.0f,
                float.MaxValue);

            this.sampler = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc);

            D3D11RasterizerDesc rasterizerDesc = D3D11RasterizerDesc.Default;

            rasterizerDesc.CullMode = D3D11CullMode.None;
            this.rasterizerState    = this.deviceResources.D3DDevice.CreateRasterizerState(rasterizerDesc);

            this.depthStencilState0 = this.deviceResources.D3DDevice.CreateDepthStencilState(D3D11DepthStencilDesc.Default);

            D3D11DepthStencilDesc depthStencilDesc = D3D11DepthStencilDesc.Default;

            depthStencilDesc.DepthWriteMask = D3D11DepthWriteMask.Zero;
            this.depthStencilState1         = this.deviceResources.D3DDevice.CreateDepthStencilState(depthStencilDesc);

            this.blendState0 = this.deviceResources.D3DDevice.CreateBlendState(D3D11BlendDesc.Default);

            D3D11BlendDesc blendDesc = D3D11BlendDesc.Default;

            D3D11RenderTargetBlendDesc[] blendDescRenderTargets = blendDesc.GetRenderTargets();
            blendDescRenderTargets[0].IsBlendEnabled        = true;
            blendDescRenderTargets[0].SourceBlend           = D3D11BlendValue.SourceAlpha;
            blendDescRenderTargets[0].DestinationBlend      = D3D11BlendValue.InverseSourceAlpha;
            blendDescRenderTargets[0].BlendOperation        = D3D11BlendOperation.Add;
            blendDescRenderTargets[0].SourceBlendAlpha      = D3D11BlendValue.One;
            blendDescRenderTargets[0].DestinationBlendAlpha = D3D11BlendValue.InverseSourceAlpha;
            blendDescRenderTargets[0].BlendOperationAlpha   = D3D11BlendOperation.Add;
            blendDescRenderTargets[0].RenderTargetWriteMask = D3D11ColorWriteEnables.All;
            blendDesc.SetRenderTargets(blendDescRenderTargets);
            this.blendState1 = this.deviceResources.D3DDevice.CreateBlendState(blendDesc);
        }
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            XMFloat3 vCenter = new XMFloat3(0.25767413f, -28.503521f, 111.00689f);
            XMMatrix m       = XMMatrix.Translation(-vCenter.X, -vCenter.Y, -vCenter.Z);

            m *= XMMatrix.RotationY(XMMath.PI);
            m *= XMMatrix.RotationX(XMMath.PIDivTwo);
            this.centerMesh = m;

            // Load the mesh
            this.mesh = SdkMeshFile.FromFile(
                this.deviceResources.D3DDevice,
                this.deviceResources.D3DContext,
                "Tiny\\Tiny.sdkmesh");

            // Create the shaders
            byte[] vertexShaderBytecode = File.ReadAllBytes("BasicHLSL11_VS.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "NORMAL",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "TEXCOORD",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 24,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes("BasicHLSL11_PS.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            // Create a sampler state
            D3D11SamplerDesc samplerDesc = new D3D11SamplerDesc(
                D3D11Filter.MinMagMipLinear,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                0.0f,
                1,
                D3D11ComparisonFunction.Always,
                new float[] { 0.0f, 0.0f, 0.0f, 0.0f },
                0.0f,
                float.MaxValue);

            this.sampler = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc);

            // Setup constant buffers
            this.constantBufferVSPerObject = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferVSPerObject.Size, D3D11BindOptions.ConstantBuffer));

            this.constantBufferPSPerObject = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferPSPerObject.Size, D3D11BindOptions.ConstantBuffer));

            this.constantBufferPSPerFrame = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferPSPerFrame.Size, D3D11BindOptions.ConstantBuffer));
        }
Example #12
0
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            var d3dDevice = this.deviceResources.D3DDevice;

            // Create the shaders
            byte[] renderParticlesVSBytecode = File.ReadAllBytes("ParticleDrawVS.cso");
            this.g_pRenderParticlesVS = d3dDevice.CreateVertexShader(renderParticlesVSBytecode, null);
            this.g_pRenderParticlesGS = d3dDevice.CreateGeometryShader(File.ReadAllBytes("ParticleDrawGS.cso"), null);
            this.g_pRenderParticlesPS = d3dDevice.CreatePixelShader(File.ReadAllBytes("ParticleDrawPS.cso"), null);
            this.g_pCalcCS            = d3dDevice.CreateComputeShader(File.ReadAllBytes("NBodyGravityCS.cso"), null);

            // Create our vertex input layout
            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "COLOR",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32A32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.g_pParticleVertexLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, renderParticlesVSBytecode);

            this.CreateParticleBuffer();
            this.CreateParticlePosVeloBuffers();

            // Setup constant buffer
            this.g_pcbGS = d3dDevice.CreateBuffer(new D3D11BufferDesc(ConstantBufferGS.Size, D3D11BindOptions.ConstantBuffer));
            this.g_pcbCS = d3dDevice.CreateBuffer(new D3D11BufferDesc(ConstantBufferCS.Size, D3D11BindOptions.ConstantBuffer));

            // Load the Particle Texture
            DdsDirectX.CreateTexture(
                "Particle.dds",
                this.deviceResources.D3DDevice,
                this.deviceResources.D3DContext,
                out this.g_pParticleTexRV);

            D3D11SamplerDesc SamplerDesc = D3D11SamplerDesc.Default;

            SamplerDesc.AddressU      = D3D11TextureAddressMode.Clamp;
            SamplerDesc.AddressV      = D3D11TextureAddressMode.Clamp;
            SamplerDesc.AddressW      = D3D11TextureAddressMode.Clamp;
            SamplerDesc.Filter        = D3D11Filter.MinMagMipLinear;
            this.g_pSampleStateLinear = d3dDevice.CreateSamplerState(SamplerDesc);

            D3D11BlendDesc BlendStateDesc = D3D11BlendDesc.Default;

            D3D11RenderTargetBlendDesc[] BlendStateDescRenderTargets = BlendStateDesc.GetRenderTargets();
            BlendStateDescRenderTargets[0].IsBlendEnabled        = true;
            BlendStateDescRenderTargets[0].BlendOperation        = D3D11BlendOperation.Add;
            BlendStateDescRenderTargets[0].SourceBlend           = D3D11BlendValue.SourceAlpha;
            BlendStateDescRenderTargets[0].DestinationBlend      = D3D11BlendValue.One;
            BlendStateDescRenderTargets[0].BlendOperationAlpha   = D3D11BlendOperation.Add;
            BlendStateDescRenderTargets[0].SourceBlendAlpha      = D3D11BlendValue.Zero;
            BlendStateDescRenderTargets[0].DestinationBlendAlpha = D3D11BlendValue.Zero;
            BlendStateDescRenderTargets[0].RenderTargetWriteMask = D3D11ColorWriteEnables.All;
            BlendStateDesc.SetRenderTargets(BlendStateDescRenderTargets);
            this.g_pBlendingStateParticle = d3dDevice.CreateBlendState(BlendStateDesc);

            D3D11DepthStencilDesc DepthStencilDesc = D3D11DepthStencilDesc.Default;

            DepthStencilDesc.IsDepthEnabled = false;
            DepthStencilDesc.DepthWriteMask = D3D11DepthWriteMask.Zero;
            this.g_pDepthStencilState       = d3dDevice.CreateDepthStencilState(DepthStencilDesc);

            XMFloat3 eye = new XMFloat3(-Spread * 2, Spread * 4, -Spread * 3);
            XMFloat3 at  = new XMFloat3(0.0f, 0.0f, 0.0f);
            XMFloat3 up  = new XMFloat3(0.0f, 1.0f, 0.0f);

            this.ViewMatrix = XMMatrix.LookAtLH(eye, at, up);
        }
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "TEXCOORD",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes("PixelShader.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            var vertexBufferDesc = D3D11BufferDesc.From(MainGameComponent.Vertices, D3D11BindOptions.VertexBuffer);

            this.vertexBuffer = this.deviceResources.D3DDevice.CreateBuffer(vertexBufferDesc, MainGameComponent.Vertices, 0, 0);

            var indexBufferDesc = D3D11BufferDesc.From(MainGameComponent.Indices, D3D11BindOptions.IndexBuffer);

            this.indexBuffer = this.deviceResources.D3DDevice.CreateBuffer(indexBufferDesc, MainGameComponent.Indices, 0, 0);

            this.constantBufferNeverChanges = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferNeverChangesData.Size, D3D11BindOptions.ConstantBuffer));

            this.constantBufferChangesOnResize = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferChangesOnResizeData.Size, D3D11BindOptions.ConstantBuffer));

            this.constantBufferChangesEveryFrame = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferChangesEveryFrameData.Size, D3D11BindOptions.ConstantBuffer));

            DdsDirectX.CreateTexture(
                "seafloor.dds",
                this.deviceResources.D3DDevice,
                this.deviceResources.D3DContext,
                out this.textureView);

            D3D11SamplerDesc samplerDesc = new D3D11SamplerDesc(
                D3D11Filter.MinMagMipLinear,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                0.0f,
                0,
                D3D11ComparisonFunction.Never,
                new float[] { 0.0f, 0.0f, 0.0f, 0.0f },
                0.0f,
                float.MaxValue);

            this.sampler = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc);

            this.worldMatrix = XMMatrix.Identity;

            XMVector eye = new XMVector(0.0f, 3.0f, -6.0f, 0.0f);
            XMVector at  = new XMVector(0.0f, 1.0f, 0.0f, 0.0f);
            XMVector up  = new XMVector(0.0f, 1.0f, 0.0f, 0.0f);

            this.viewMatrix = XMMatrix.LookAtLH(eye, at, up);

            ConstantBufferNeverChangesData cbNeverChanges;

            cbNeverChanges.View = this.viewMatrix.Transpose();
            this.deviceResources.D3DContext.UpdateSubresource(this.constantBufferNeverChanges, 0, null, cbNeverChanges, 0, 0);
        }
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso");
            this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null);

            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "NORMAL",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "TEXCOORD",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 24,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, vertexShaderBytecode);

            byte[] pixelShaderBytecode = File.ReadAllBytes("PixelShader.cso");
            this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null);

            this.constantBufferPerObject = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferPerObject.Size, D3D11BindOptions.ConstantBuffer));

            this.constantBufferPerFrame = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferPerFrame.Size, D3D11BindOptions.ConstantBuffer));

            D3D11SamplerDesc samplerDesc = new D3D11SamplerDesc(
                D3D11Filter.MinMagMipLinear,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                D3D11TextureAddressMode.Wrap,
                0.0f,
                1,
                D3D11ComparisonFunction.Always,
                new float[] { 0.0f, 0.0f, 0.0f, 0.0f },
                0.0f,
                float.MaxValue);

            this.sampler = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc);

            DdsDirectX.CreateTexture(
                "seafloor.dds",
                this.deviceResources.D3DDevice,
                this.deviceResources.D3DContext,
                out this.textureView);

            this.mesh = SdkMeshFile.FromFile(
                this.deviceResources.D3DDevice,
                this.deviceResources.D3DContext,
                "ball.sdkmesh");

            XMVector eye = new XMVector(0.0f, 0.0f, -5.0f, 0.0f);
            XMVector at  = new XMVector(0.0f, 0.0f, -0.0f, 0.0f);
            XMVector up  = new XMVector(0.0f, 1.0f, 0.0f, 0.0f);

            this.ViewMatrix  = XMMatrix.LookAtLH(eye, at, up);
            this.WorldMatrix = XMMatrix.Identity;
        }
Example #15
0
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            byte[] renderSceneVertexShaderBytecode = File.ReadAllBytes("RenderSceneVertexShader.cso");
            this.g_pSceneVS = this.deviceResources.D3DDevice.CreateVertexShader(renderSceneVertexShaderBytecode, null);

            D3D11InputElementDesc[] layoutDesc = new D3D11InputElementDesc[]
            {
                new D3D11InputElementDesc
                {
                    SemanticName         = "POSITION",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 0,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "NORMAL",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32B32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 12,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                },
                new D3D11InputElementDesc
                {
                    SemanticName         = "TEXTURE",
                    SemanticIndex        = 0,
                    Format               = DxgiFormat.R32G32Float,
                    InputSlot            = 0,
                    AlignedByteOffset    = 24,
                    InputSlotClass       = D3D11InputClassification.PerVertexData,
                    InstanceDataStepRate = 0
                }
            };

            this.g_pSceneVertexLayout = this.deviceResources.D3DDevice.CreateInputLayout(layoutDesc, renderSceneVertexShaderBytecode);

            byte[] renderScenePixelShaderBytecode = File.ReadAllBytes("RenderScenePixelShader.cso");
            this.g_pScenePS = this.deviceResources.D3DDevice.CreatePixelShader(renderScenePixelShaderBytecode, null);

            byte[] renderSceneShadowMapVertexShaderBytecode = File.ReadAllBytes("RenderSceneShadowMapVertexShader.cso");
            this.g_pShadowMapVS = this.deviceResources.D3DDevice.CreateVertexShader(renderSceneShadowMapVertexShaderBytecode, null);

            this.g_SceneMesh = SdkMeshFile.FromFile(this.deviceResources.D3DDevice, this.deviceResources.D3DContext, @"ColumnScene\scene.sdkmesh");
            this.g_Poles     = SdkMeshFile.FromFile(this.deviceResources.D3DDevice, this.deviceResources.D3DContext, @"ColumnScene\poles.sdkmesh");

            this.g_pcbConstants = this.deviceResources.D3DDevice.CreateBuffer(
                new D3D11BufferDesc(ConstantBufferConstants.Size, D3D11BindOptions.ConstantBuffer));

            D3D11SamplerDesc samplerDesc = new D3D11SamplerDesc(
                D3D11Filter.ComparisonMinMagMipPoint,
                D3D11TextureAddressMode.Border,
                D3D11TextureAddressMode.Border,
                D3D11TextureAddressMode.Border,
                0.0f,
                1,
                D3D11ComparisonFunction.LessEqual,
                new float[] { 1.0f, 1.0f, 1.0f, 1.0f },
                0.0f,
                float.MaxValue);

            // PointCmp
            this.g_pSamplePointCmp = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc);

            // Point
            samplerDesc.Filter             = D3D11Filter.MinMagMipPoint;
            samplerDesc.ComparisonFunction = D3D11ComparisonFunction.Always;
            this.g_pSamplePoint            = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc);

            // Linear
            samplerDesc.Filter   = D3D11Filter.MinMagMipLinear;
            samplerDesc.AddressU = D3D11TextureAddressMode.Wrap;
            samplerDesc.AddressV = D3D11TextureAddressMode.Wrap;
            samplerDesc.AddressW = D3D11TextureAddressMode.Wrap;
            this.g_pSampleLinear = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc);

            // Create a blend state to disable alpha blending
            D3D11BlendDesc blendDesc = D3D11BlendDesc.Default;

            blendDesc.IsIndependentBlendEnabled = false;
            D3D11RenderTargetBlendDesc[] blendDescRenderTargets = blendDesc.GetRenderTargets();
            blendDescRenderTargets[0].IsBlendEnabled = false;

            blendDescRenderTargets[0].RenderTargetWriteMask = D3D11ColorWriteEnables.All;
            blendDesc.SetRenderTargets(blendDescRenderTargets);
            this.g_pBlendStateNoBlend = this.deviceResources.D3DDevice.CreateBlendState(blendDesc);

            blendDescRenderTargets[0].RenderTargetWriteMask = D3D11ColorWriteEnables.None;
            blendDesc.SetRenderTargets(blendDescRenderTargets);
            this.g_pBlendStateColorWritesOff = this.deviceResources.D3DDevice.CreateBlendState(blendDesc);

            // textures / rts
            D3D11Texture2DDesc TDesc = new D3D11Texture2DDesc(
                DxgiFormat.R16Typeless,
                (uint)g_fShadowMapWidth,
                (uint)g_fShadowMapHeight,
                1,
                1,
                D3D11BindOptions.DepthStencil | D3D11BindOptions.ShaderResource);

            this.g_pShadowMapDepthStencilTexture = this.deviceResources.D3DDevice.CreateTexture2D(TDesc);

            D3D11ShaderResourceViewDesc SRVDesc = new D3D11ShaderResourceViewDesc
            {
                Format        = DxgiFormat.R16UNorm,
                ViewDimension = D3D11SrvDimension.Texture2D,
                Texture2D     = new D3D11Texture2DSrv
                {
                    MipLevels       = 1,
                    MostDetailedMip = 0
                }
            };

            this.g_pDepthTextureSRV = this.deviceResources.D3DDevice.CreateShaderResourceView(this.g_pShadowMapDepthStencilTexture, SRVDesc);

            D3D11DepthStencilViewDesc DSVDesc = new D3D11DepthStencilViewDesc
            {
                Format        = DxgiFormat.D16UNorm,
                ViewDimension = D3D11DsvDimension.Texture2D,
                Options       = D3D11DepthStencilViewOptions.None,
                Texture2D     = new D3D11Texture2DDsv
                {
                    MipSlice = 0
                }
            };

            this.g_pDepthStencilTextureDSV = this.deviceResources.D3DDevice.CreateDepthStencilView(this.g_pShadowMapDepthStencilTexture, DSVDesc);

            XMFloat3 vecEye = new XMFloat3(0.95f, 5.83f, -14.48f);
            XMFloat3 vecAt  = new XMFloat3(0.90f, 5.44f, -13.56f);
            XMFloat3 vecUp  = new XMFloat3(0.0f, 1.0f, 0.0f);

            this.ViewMatrix  = XMMatrix.LookAtLH(vecEye, vecAt, vecUp);
            this.WorldMatrix = XMMatrix.Identity;

            XMFloat3 vecEyeL = new XMFloat3(0, 0, 0);
            XMFloat3 vecAtL  = new XMFloat3(0, -0.5f, 1);
            XMFloat3 vecUUpL = new XMFloat3(0.0f, 1.0f, 0.0f);

            this.LightViewMatrix  = XMMatrix.LookAtLH(vecEyeL, vecAtL, vecUUpL);
            this.LightWorldMatrix = XMMatrix.Identity;
        }