示例#1
0
        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));
        }
        internal SdkMeshIndexBuffer(D3D11Device device, SdkMeshRawFile rawFile, SdkMeshRawMesh rawMesh)
        {
            int index = rawMesh.IndexBuffer;
            SdkMeshRawIndexBufferHeader header = rawFile.IndexBufferHeaders[index];

            byte[] bytes = rawFile.IndexBufferBytes[index];

            this.NumIndices = (int)header.NumIndices;
            this.SizeBytes  = (uint)header.SizeBytes;

            switch (header.IndexType)
            {
            case SdkMeshIndexType.IndexType16Bit:
                this.IndexFormat = DxgiFormat.R16UInt;
                break;

            case SdkMeshIndexType.IndexType32Bit:
                this.IndexFormat = DxgiFormat.R32UInt;
                break;

            default:
                this.IndexFormat = DxgiFormat.R16UInt;
                break;
            }

            var desc = new D3D11BufferDesc((uint)header.SizeBytes, D3D11BindOptions.IndexBuffer);
            var data = new D3D11SubResourceData(bytes, 0, 0);

            this.Buffer = device.CreateBuffer(desc, data);
        }
        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;

            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;
        }
        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);
        }
示例#6
0
        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));
        }
示例#7
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
                );
        }
示例#9
0
        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);
        }
示例#10
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("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);
        }
        internal SdkMeshVertexBuffer(D3D11Device device, SdkMeshRawFile rawFile, SdkMeshRawMesh rawMesh, int i)
        {
            int index = rawMesh.VertexBuffers[i];
            SdkMeshRawVertexBufferHeader header = rawFile.VertexBufferHeaders[index];

            byte[] bytes = rawFile.VertexBufferBytes[index];

            this.NumVertices = (int)header.NumVertices;
            this.SizeBytes   = (uint)header.SizeBytes;
            this.StrideBytes = (uint)header.StrideBytes;
            this.Decl        = header.Decl.ToArray();

            var desc = new D3D11BufferDesc((uint)header.SizeBytes, D3D11BindOptions.VertexBuffer);
            var data = new D3D11SubResourceData(bytes, 0, 0);

            this.Buffer = device.CreateBuffer(desc, data);
        }
示例#13
0
        public void CreateDeviceDependentResources(DeviceResources resources)
        {
            this.deviceResources = resources;

            var loader = new BasicLoader(this.deviceResources.D3DDevice);

            loader.LoadShader("Components.VertexShader.cso", null, out this.vertexShader, out this.inputLayout);

            var shapes = new BasicShapes(this.deviceResources.D3DDevice);

            shapes.CreateReferenceAxis(out this.vertexBuffer, out this.indexBuffer, out this.vertexCount, out this.indexCount);

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

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

            loader.LoadShader("Components.PixelShader.cso", out this.pixelShader);

            loader.LoadTexture("texturedata.bin", 256, 256, out this.texture, out this.textureView);

            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);

            this.camera = new BasicCamera();
        }
示例#14
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);
        }
示例#15
0
        static void CreateResources()
        {
            var d3dDevice = deviceResources.D3DDevice;

            // Create the Bitonic Sort Compute Shader
            g_pComputeShaderBitonic = d3dDevice.CreateComputeShader(File.ReadAllBytes("CSSortBitonic.cso"), null);

            // Create the Matrix Transpose Compute Shader
            g_pComputeShaderTranspose = d3dDevice.CreateComputeShader(File.ReadAllBytes("CSSortTranspose.cso"), null);

            // Create the Const Buffer
            var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer);

            g_pCB = d3dDevice.CreateBuffer(constantBufferDesc);

            // Create the Buffer of Elements
            // Create 2 buffers for switching between when performing the transpose
            var bufferDesc = new D3D11BufferDesc(
                NUM_ELEMENTS * sizeof(uint),
                D3D11BindOptions.UnorderedAccess | D3D11BindOptions.ShaderResource,
                D3D11Usage.Default,
                D3D11CpuAccessOptions.None,
                D3D11ResourceMiscOptions.BufferStructured,
                sizeof(uint));

            g_pBuffer1 = d3dDevice.CreateBuffer(bufferDesc);
            g_pBuffer2 = d3dDevice.CreateBuffer(bufferDesc);

            // Create the Shader Resource View for the Buffers
            // This is used for reading the buffer during the transpose
            var srvbufferDesc = new D3D11ShaderResourceViewDesc(D3D11SrvDimension.Buffer, DxgiFormat.Unknown)
            {
                Buffer = new D3D11BufferSrv {
                    ElementWidth = NUM_ELEMENTS
                }
            };

            g_pBuffer1SRV = d3dDevice.CreateShaderResourceView(g_pBuffer1, srvbufferDesc);
            g_pBuffer2SRV = d3dDevice.CreateShaderResourceView(g_pBuffer2, srvbufferDesc);

            // Create the Unordered Access View for the Buffers
            // This is used for writing the buffer during the sort and transpose
            var uavbufferDesc = new D3D11UnorderedAccessViewDesc(D3D11UavDimension.Buffer, DxgiFormat.Unknown)
            {
                Buffer = new D3D11BufferUav {
                    NumElements = NUM_ELEMENTS
                }
            };

            g_pBuffer1UAV = d3dDevice.CreateUnorderedAccessView(g_pBuffer1, uavbufferDesc);
            g_pBuffer2UAV = d3dDevice.CreateUnorderedAccessView(g_pBuffer2, uavbufferDesc);

            // Create the Readback Buffer
            // This is used to read the results back to the CPU
            var readbackBufferDesc = new D3D11BufferDesc(
                NUM_ELEMENTS * sizeof(uint),
                D3D11BindOptions.None,
                D3D11Usage.Staging,
                D3D11CpuAccessOptions.Read,
                D3D11ResourceMiscOptions.None,
                sizeof(uint));

            g_pReadBackBuffer = d3dDevice.CreateBuffer(readbackBufferDesc);
        }
        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);
        }
        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
            });
        }
        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);
        }
示例#19
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);
        }
示例#21
0
        private void CreateTangentVertexBuffer(TangentVertex[] vertexData, out D3D11Buffer vertexBuffer)
        {
            D3D11BufferDesc vertexBufferDesc = D3D11BufferDesc.From(vertexData, D3D11BindOptions.VertexBuffer);

            vertexBuffer = this.d3dDevice.CreateBuffer(vertexBufferDesc, vertexData, 0, 0);
        }
示例#22
0
        private void CreateIndexBuffer(ushort[] indexData, out D3D11Buffer indexBuffer)
        {
            D3D11BufferDesc indexBufferDesc = D3D11BufferDesc.From(indexData, D3D11BindOptions.IndexBuffer);

            indexBuffer = this.d3dDevice.CreateBuffer(indexBufferDesc, indexData, 0, 0);
        }