public void CreateDeviceDependentResources(DeviceResources resources) { this.deviceResources = resources; this.fragmentCountPS = this.deviceResources.D3DDevice.CreatePixelShader( File.ReadAllBytes("FragmentCountPS.cso"), null); this.createPrefixSumPass0CS = this.deviceResources.D3DDevice.CreateComputeShader( File.ReadAllBytes("CreatePrefixSumPass0CS.cso"), null); this.createPrefixSumPass1CS = this.deviceResources.D3DDevice.CreateComputeShader( File.ReadAllBytes("CreatePrefixSumPass1CS.cso"), null); this.fillDeepBufferPS = this.deviceResources.D3DDevice.CreatePixelShader( File.ReadAllBytes("FillDeepBufferPS.cso"), null); this.sortAndRenderCS = this.deviceResources.D3DDevice.CreateComputeShader( File.ReadAllBytes("SortAndRenderCS.cso"), null); var depthStencilDesc = new D3D11DepthStencilDesc { IsDepthEnabled = false, IsStencilEnabled = false }; this.depthStencilState = this.deviceResources.D3DDevice.CreateDepthStencilState(depthStencilDesc); this.computeShaderConstantBuffer = this.deviceResources.D3DDevice.CreateBuffer( new D3D11BufferDesc(OitComputeShaderConstantBufferData.Size, D3D11BindOptions.ConstantBuffer)); this.pixelShaderConstantBuffer = this.deviceResources.D3DDevice.CreateBuffer( new D3D11BufferDesc(OitPixelShaderConstantBufferData.Size, D3D11BindOptions.ConstantBuffer)); }
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; 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); }