コード例 #1
0
        public void ReleaseDeviceDependentResources()
        {
            D3D11Utils.DisposeAndNull(ref this.g_pShadowMapDepthStencilTexture);
            D3D11Utils.DisposeAndNull(ref this.g_pDepthTextureSRV);
            D3D11Utils.DisposeAndNull(ref this.g_pDepthStencilTextureDSV);

            D3D11Utils.DisposeAndNull(ref this.g_pSamplePoint);
            D3D11Utils.DisposeAndNull(ref this.g_pSampleLinear);
            D3D11Utils.DisposeAndNull(ref this.g_pSamplePointCmp);
            D3D11Utils.DisposeAndNull(ref this.g_pBlendStateNoBlend);
            D3D11Utils.DisposeAndNull(ref this.g_pBlendStateColorWritesOff);

            D3D11Utils.DisposeAndNull(ref this.g_pcbConstants);

            this.g_SceneMesh?.Release();
            this.g_SceneMesh = null;

            this.g_Poles?.Release();
            this.g_Poles = null;

            D3D11Utils.DisposeAndNull(ref this.g_pSceneVS);
            D3D11Utils.DisposeAndNull(ref this.g_pSceneVertexLayout);
            D3D11Utils.DisposeAndNull(ref this.g_pScenePS);
            D3D11Utils.DisposeAndNull(ref this.g_pShadowMapVS);
        }
コード例 #2
0
        public void ReleaseDeviceDependentResources()
        {
            this.meshPowerPlant?.Release();
            this.meshPowerPlant = null;

            this.meshTestScene?.Release();
            this.meshTestScene = null;

            this.cascadedShadow.DestroyAndDeallocateShadowResources();
        }
コード例 #3
0
        public void ReleaseDeviceDependentResources()
        {
            this.mesh?.Release();
            this.mesh = null;

            D3D11Utils.DisposeAndNull(ref this.vertexShader);
            D3D11Utils.DisposeAndNull(ref this.inputLayout);
            D3D11Utils.DisposeAndNull(ref this.pixelShader);
            D3D11Utils.DisposeAndNull(ref this.sampler);
            D3D11Utils.DisposeAndNull(ref this.constantBufferVSPerObject);
            D3D11Utils.DisposeAndNull(ref this.constantBufferPSPerObject);
            D3D11Utils.DisposeAndNull(ref this.constantBufferPSPerFrame);
        }
コード例 #4
0
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            var d3dDevice  = this.deviceResources.D3DDevice;
            var d3dContext = this.deviceResources.D3DContext;

            this.meshPowerPlant = SdkMeshFile.FromFile(d3dDevice, d3dContext, "powerplant\\powerplant.sdkmesh");
            this.meshTestScene  = SdkMeshFile.FromFile(d3dDevice, d3dContext, "ShadowColumns\\testscene.sdkmesh");
            this.SceneSelection = SceneSelection.PowerPlantScene;

            this.cascadedShadow.Init(
                d3dDevice,
                d3dContext);

            this.InitScene();
        }
コード例 #5
0
        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));
        }
コード例 #6
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;
        }
コード例 #7
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;
        }