private void CreateCSBuffers() { var d3dDevice = this.deviceResources.D3DDevice; // constant buffers used to pass parameters to CS int[] lut = new int[insidePointIndex.Length + outsidePointIndex.Length]; Buffer.BlockCopy(insidePointIndex, 0, lut, 0, insidePointIndex.Length * sizeof(int)); Buffer.BlockCopy(outsidePointIndex, 0, lut, insidePointIndex.Length * sizeof(int), outsidePointIndex.Length * sizeof(int)); this.s_pLookupTableCSCB = d3dDevice.CreateBuffer( D3D11BufferDesc.From(lut, D3D11BindOptions.ConstantBuffer, D3D11Usage.Immutable), lut, (uint)lut.Length * sizeof(int), 0); this.s_pEdgeFactorCSCB = d3dDevice.CreateBuffer( new D3D11BufferDesc(EdgeFactorConstantBuffer.Size, D3D11BindOptions.ConstantBuffer, D3D11Usage.Default)); this.s_pCSCB = d3dDevice.CreateBuffer( new D3D11BufferDesc(sizeof(int) * 4, D3D11BindOptions.ConstantBuffer, D3D11Usage.Default)); // read back buffer this.s_pCSReadBackBuf = d3dDevice.CreateBuffer( new D3D11BufferDesc(sizeof(int) * 2, D3D11BindOptions.None, D3D11Usage.Staging, D3D11CpuAccessOptions.Read)); }
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; }
static D3D11Buffer CreateRawBuffer <T>(D3D11Device pDevice, T[] pInitData) where T : struct { var desc = D3D11BufferDesc.From(pInitData, D3D11BindOptions.UnorderedAccess | D3D11BindOptions.ShaderResource | D3D11BindOptions.IndexBuffer | D3D11BindOptions.VertexBuffer); desc.MiscOptions = D3D11ResourceMiscOptions.BufferAllowRawViews; return(pDevice.CreateBuffer(desc, pInitData, 0, 0)); }
static D3D11Buffer CreateStructuredBuffer <T>(D3D11Device pDevice, T[] pInitData) where T : struct { var desc = D3D11BufferDesc.From(pInitData, D3D11BindOptions.UnorderedAccess | D3D11BindOptions.ShaderResource); desc.MiscOptions = D3D11ResourceMiscOptions.BufferStructured; desc.StructureByteStride = (uint)Marshal.SizeOf(typeof(T)); return(pDevice.CreateBuffer(desc, pInitData, 0, 0)); }
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 ); }
private void CreateParticleBuffer() { var d3dDevice = this.deviceResources.D3DDevice; ParticleVertex[] pVertices = new ParticleVertex[MaxParticles]; for (int i = 0; i < pVertices.Length; i++) { pVertices[i].Color = new XMFloat4(1, 1, 0.2f, 1); } D3D11BufferDesc vbdesc = D3D11BufferDesc.From(pVertices, D3D11BindOptions.VertexBuffer); this.g_pParticleBuffer = d3dDevice.CreateBuffer(vbdesc, pVertices, 0, 0); }
public void CreateDeviceDependentResources(DeviceResources resources, Mesh3D mesh) { var vertices = mesh.Vertices.ToArray(); var vertexBufferDesc = D3D11BufferDesc.From(vertices, D3D11BindOptions.VertexBuffer); this.vertexBuffer = resources.D3DDevice.CreateBuffer(vertexBufferDesc, vertices, 0, 0); var indices = mesh.Indices.ToArray(); var indexBufferDesc = D3D11BufferDesc.From(indices, D3D11BindOptions.IndexBuffer); this.indexBuffer = resources.D3DDevice.CreateBuffer(indexBufferDesc, indices, 0, 0); this.IndicesCount = (uint)indices.Length; this.Texture = mesh.Texture; this.HasAlpha = mesh.HasAlpha; }
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); }
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); }
private void CreateTangentVertexBuffer(TangentVertex[] vertexData, out D3D11Buffer vertexBuffer) { D3D11BufferDesc vertexBufferDesc = D3D11BufferDesc.From(vertexData, D3D11BindOptions.VertexBuffer); vertexBuffer = this.d3dDevice.CreateBuffer(vertexBufferDesc, vertexData, 0, 0); }
private void CreateIndexBuffer(ushort[] indexData, out D3D11Buffer indexBuffer) { D3D11BufferDesc indexBufferDesc = D3D11BufferDesc.From(indexData, D3D11BindOptions.IndexBuffer); indexBuffer = this.d3dDevice.CreateBuffer(indexBufferDesc, indexData, 0, 0); }
private void CreateParticlePosVeloBuffers() { var d3dDevice = this.deviceResources.D3DDevice; // Initialize the data in the buffers Particle[] pData1 = new Particle[MaxParticles]; Random rand = this.Random ?? new Random(0); if (this.DiskGalaxyFormationType == 0) { // Disk Galaxy Formation float fCenterSpread = Spread * 0.50f; LoadParticles( rand, pData1, 0, new XMFloat3(fCenterSpread, 0, 0), new XMFloat4(0, 0, -20, 1 / 10000.0f / 10000.0f), Spread, pData1.Length / 2); LoadParticles( rand, pData1, pData1.Length / 2, new XMFloat3(-fCenterSpread, 0, 0), new XMFloat4(0, 0, 20, 1 / 10000.0f / 10000.0f), Spread, pData1.Length - pData1.Length / 2); } else { // Disk Galaxy Formation with impacting third cluster LoadParticles( rand, pData1, 0, new XMFloat3(Spread, 0, 0), new XMFloat4(0, 0, -8, 1 / 10000.0f / 10000.0f), Spread, pData1.Length / 3); LoadParticles( rand, pData1, pData1.Length / 3, new XMFloat3(-Spread, 0, 0), new XMFloat4(0, 0, 8, 1 / 10000.0f / 10000.0f), Spread, pData1.Length / 3); LoadParticles( rand, pData1, 2 * pData1.Length / 3, new XMFloat3(0, 0, Spread * 15.0f), new XMFloat4(0, 0, -60, 1 / 10000.0f / 10000.0f), Spread, pData1.Length - 2 * pData1.Length / 3); } D3D11BufferDesc desc = D3D11BufferDesc.From(pData1, D3D11BindOptions.UnorderedAccess | D3D11BindOptions.ShaderResource); desc.MiscOptions = D3D11ResourceMiscOptions.BufferStructured; desc.StructureByteStride = Particle.Size; this.g_pParticlePosVelo0 = d3dDevice.CreateBuffer(desc, pData1, 0, 0); this.g_pParticlePosVelo1 = d3dDevice.CreateBuffer(desc, pData1, 0, 0); D3D11ShaderResourceViewDesc DescRV = new D3D11ShaderResourceViewDesc( this.g_pParticlePosVelo0, DxgiFormat.Unknown, 0, desc.ByteWidth / desc.StructureByteStride); this.g_pParticlePosVeloRV0 = d3dDevice.CreateShaderResourceView(this.g_pParticlePosVelo0, DescRV); this.g_pParticlePosVeloRV1 = d3dDevice.CreateShaderResourceView(this.g_pParticlePosVelo1, DescRV); D3D11UnorderedAccessViewDesc DescUAV = new D3D11UnorderedAccessViewDesc( this.g_pParticlePosVelo0, DxgiFormat.Unknown, 0, desc.ByteWidth / desc.StructureByteStride); this.g_pParticlePosVeloUAV0 = d3dDevice.CreateUnorderedAccessView(this.g_pParticlePosVelo0, DescUAV); this.g_pParticlePosVeloUAV1 = d3dDevice.CreateUnorderedAccessView(this.g_pParticlePosVelo1, DescUAV); }
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; var d3dDevice = this.deviceResources.D3DDevice; this.tessellator.CreateDeviceDependentResources(this.deviceResources); XMFloat4[] initData; // Parse the .obj file. Both triangle faces and quad faces are supported. // Only v and f tags are processed, other tags like vn, vt etc are ignored. { var initFile = ObjFile.FromFile("BaseMesh.obj"); var data = new List <XMFloat4>(); var v = new List <XMFloat4>(); for (int i = 0; i < initFile.Vertices.Count; i++) { ObjVector4 objPosition = initFile.Vertices[i].Position; XMFloat4 pos = new XMFloat4( objPosition.X, objPosition.Y, objPosition.Z, 1.0f); v.Add(pos); } foreach (ObjFace face in initFile.Faces) { if (face.Vertices.Count < 3) { continue; } data.Add(v[face.Vertices[0].Vertex - 1]); data.Add(v[face.Vertices[1].Vertex - 1]); data.Add(v[face.Vertices[2].Vertex - 1]); if (face.Vertices.Count >= 4) { data.Add(v[face.Vertices[2].Vertex - 1]); data.Add(v[face.Vertices[3].Vertex - 1]); data.Add(v[face.Vertices[0].Vertex - 1]); } } initData = data.ToArray(); } this.g_pBaseVB = d3dDevice.CreateBuffer( D3D11BufferDesc.From(initData, D3D11BindOptions.ShaderResource | D3D11BindOptions.VertexBuffer), initData, 0, 0); this.tessellator.SetBaseMesh((uint)initData.Length, this.g_pBaseVB); this.g_pVS = d3dDevice.CreateVertexShader(File.ReadAllBytes("RenderVertexShader.cso"), null); { byte[] shaderBytecode = File.ReadAllBytes("RenderBaseVertexShader.cso"); this.g_pBaseVS = d3dDevice.CreateVertexShader(shaderBytecode, null); D3D11InputElementDesc[] layoutDesc = new[] { new D3D11InputElementDesc( "POSITION", 0, DxgiFormat.R32G32B32A32Float, 0, 0, D3D11InputClassification.PerVertexData, 0) }; this.g_pBaseVBLayout = d3dDevice.CreateInputLayout(layoutDesc, shaderBytecode); } this.g_pPS = d3dDevice.CreatePixelShader(File.ReadAllBytes("RenderPixelShader.cso"), null); // Setup constant buffer this.g_pVSCB = d3dDevice.CreateBuffer(new D3D11BufferDesc { BindOptions = D3D11BindOptions.ConstantBuffer, ByteWidth = 4 * 16 }); // Rasterizer state this.g_pRasWireFrame = d3dDevice.CreateRasterizerState(new D3D11RasterizerDesc { CullMode = D3D11CullMode.None, FillMode = D3D11FillMode.WireFrame }); }