Ejemplo n.º 1
0
        public void LoadAssets()
        {
            //@TODO - temporary sampler
            StaticSamplerDescription pointClamp = new StaticSamplerDescription(ShaderVisibility.Pixel, 0, 0);

            pointClamp.Filter   = Filter.ComparisonMinLinearMagMipPoint;
            pointClamp.AddressU = TextureAddressMode.Clamp;
            pointClamp.AddressV = TextureAddressMode.Clamp;
            pointClamp.AddressW = TextureAddressMode.Clamp;

            StaticSamplerDescription[] staticSamArray = new[] { pointClamp };

            // create an empty root signature
            var rootSignatureDesc = new RootSignatureDescription(RootSignatureFlags.AllowInputAssemblerInputLayout,
                                                                 // root parameters
                                                                 new[]
            {
                new RootParameter(ShaderVisibility.Vertex,
                                  new DescriptorRange()
                {
                    RangeType          = DescriptorRangeType.ConstantBufferView,
                    BaseShaderRegister = 0,
                    OffsetInDescriptorsFromTableStart = 0,
                    DescriptorCount = 1
                }),
                new RootParameter(ShaderVisibility.Pixel,
                                  new DescriptorRange()
                {
                    RangeType          = DescriptorRangeType.ShaderResourceView,
                    BaseShaderRegister = 0,
                    OffsetInDescriptorsFromTableStart = 0,
                    DescriptorCount = 1
                })
            }
                                                                 , staticSamArray
                                                                 );

            m_RootSignature = Device.CreateRootSignature(rootSignatureDesc.Serialize());

            // create the pipeline state, which includes compiling and loading shader
            //H1VertexFactoryType vertexFactoryType = ShaderManager.GetVertexFactoryType("H1LocalVertexFactory");
            H1VertexFactoryType vertexFactoryType = ShaderManager.GetVertexFactoryType("H1GpuSkinVertexFactory");

#if DEBUG
            //var vertexShader = new ShaderBytecode(SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile("shader.hlsl", "VSMain", "vs_5_1", SharpDX.D3DCompiler.ShaderFlags.Debug));
            var vertexShader = H1Material.DefaultMaterial.MaterialResource.GetShader("H1BasePassVertexShader", vertexFactoryType).ShaderByteCode;
#else
            var vertexShader = H1Material.DefaultMaterial.MaterialResource.GetShader("H1BasePassVertexShader", vertexFactoryType).ShaderByteCode;
#endif

#if DEBUG
            //var pixelShader = new ShaderBytecode(SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile("shader.hlsl", "PSMain", "ps_5_1", SharpDX.D3DCompiler.ShaderFlags.Debug));
            var pixelShader = H1Material.DefaultMaterial.MaterialResource.GetShader("H1BasePassPixelShader", vertexFactoryType).ShaderByteCode;
#else
            var pixelShader = H1Material.DefaultMaterial.MaterialResource.GetShader("H1BasePassPixelShader", vertexFactoryType).ShaderByteCode;
#endif

            // set the seperate rasterizerstatedesc
            RasterizerStateDescription rasterizerStateDesc = RasterizerStateDescription.Default();
            //rasterizerStateDesc.FillMode = FillMode.Wireframe;
            //rasterizerStateDesc.CullMode = CullMode.None;
            rasterizerStateDesc.CullMode = CullMode.Front; //@TODO - what the f**k?!... need to solve this urgently~******
            rasterizerStateDesc.FillMode = FillMode.Solid;

            //H1StaticMeshLODResource resource = m_TempStaticMesh.StaticMeshData.GetLODResource(0);
            //H1StaticMeshLODResource resource = H1Global<H1World>.Instance.PersistentLevel.GetActor(0).GetActorComponent<H1StaticMeshComponent>().StaticMesh.StaticMeshData.GetLODResource(1);
            H1SkeletalMeshObjectGPUSkin skeletalMeshObject = H1Global <H1World> .Instance.PersistentLevel.GetActor(0).GetActorComponent <H1SkeletalMeshComponent>().SkeletalMeshObjectGPUSkin;

            // describe and create the graphics pipeline state object (PSO)
            var psoDesc = new GraphicsPipelineStateDescription()
            {
                //InputLayout = resource.LocalVertexFactory.VertexDeclaration.InputLayout,
                InputLayout        = ((Gen2Layer.H1InputLayout)skeletalMeshObject.GetSkeletalMeshObjectLODByIndex(0).GPUSkinVertexFactories.VertexFactories[0].VertexDeclaration.InputLayout).Description,
                RootSignature      = m_RootSignature,
                VertexShader       = vertexShader,
                PixelShader        = pixelShader,
                RasterizerState    = rasterizerStateDesc,
                BlendState         = BlendStateDescription.Default(),
                DepthStencilFormat = SharpDX.DXGI.Format.D32_Float,
                DepthStencilState  = DepthStencilStateDescription.Default(),
                //DepthStencilState = new DepthStencilStateDescription() { IsDepthEnabled = false, IsStencilEnabled = false },
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                Flags             = PipelineStateFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                StreamOutput      = new StreamOutputDescription()
            };

            psoDesc.RenderTargetFormats[0] = SharpDX.DXGI.Format.R8G8B8A8_UNorm;

            m_PipelineState = Device.CreateGraphicsPipelineState(psoDesc);

            // create the command list
            m_CommandList = new Direct3D12.H1CommandList(m_DeviceContext.Dx12Device, m_DeviceContext.MainCommandListPool);
            m_CommandList.Initialize();

            // create the vertex buffer
            float aspectRatio = m_Viewport.Width / m_Viewport.Height;

            m_ConstantBuffer = Device.CreateCommittedResource(new HeapProperties(HeapType.Upload), HeapFlags.None, ResourceDescription.Buffer(1024 * 64), ResourceStates.GenericRead);

            var cbvDesc = new ConstantBufferViewDescription
            {
                BufferLocation = m_ConstantBuffer.GPUVirtualAddress,
                SizeInBytes    = 256 * 256//(Utilities.SizeOf<TransformationCB>() + 255) & ~255
            };
            Device.CreateConstantBufferView(cbvDesc, m_ConstantBufferViewHeap.CPUDescriptorHandleForHeapStart);

            m_TransformationCBPointer = m_ConstantBuffer.Map(0);
            //Utilities.Write(m_TransformationCBPointer, ref m_TransformationCB);
            List <Matrix> dataToCopy = new List <Matrix>();
            dataToCopy.Add(m_TransformationCB.viewProjectionMatrix);
            foreach (Matrix mtx in m_TransformationCB.BoneMatrices)
            {
                dataToCopy.Add(mtx);
            }
            Utilities.Write(m_TransformationCBPointer, dataToCopy.ToArray(), 0, 101);
            m_ConstantBuffer.Unmap(0);

            // @TODO - temporary so need to delete
            String path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Assets\\");
            m_tempImageLoader = new H1ImageWrapper(path + "alduin.JPG");

            //CpuDescriptorHandle hDescriptor = m_srvDescriptorHeap.CPUDescriptorHandleForHeapStart;
            CpuDescriptorHandle hDescriptor = m_ConstantBufferViewHeap.CPUDescriptorHandleForHeapStart;
            hDescriptor += m_ConstantBufferDescriptorSize;
            //Int32 sizeInBytes = (Utilities.SizeOf<TransformationCB>() + 255) & ~255;
            //hDescriptor += sizeInBytes;

            ShaderResourceViewDescription srvDesc = new ShaderResourceViewDescription()
            {
                Shader4ComponentMapping = 5768, //@TODO - temporary!
                Format    = m_tempImageLoader.m_tempTextureObject.Resource.Description.Format,
                Dimension = ShaderResourceViewDimension.Texture2D
            };
            srvDesc.Texture2D.MostDetailedMip     = 0;
            srvDesc.Texture2D.MipLevels           = 1;// m_tempImageLoader.m_tempTextureObject.Resource.Description.MipLevels;
            srvDesc.Texture2D.ResourceMinLODClamp = 0.0f;

            Device.CreateShaderResourceView(m_tempImageLoader.m_tempTextureObject.Resource, srvDesc, hDescriptor);
        }
Ejemplo n.º 2
0
        public void SettingForPhysics()
        {
            //@TODO - temporary sampler
            StaticSamplerDescription pointClamp = new StaticSamplerDescription(ShaderVisibility.Pixel, 0, 0);

            pointClamp.Filter   = Filter.ComparisonMinLinearMagMipPoint;
            pointClamp.AddressU = TextureAddressMode.Clamp;
            pointClamp.AddressV = TextureAddressMode.Clamp;
            pointClamp.AddressW = TextureAddressMode.Clamp;

            StaticSamplerDescription[] staticSamArray = new[] { pointClamp };

            // create an empty root signature
            var rootSignatureDesc = new RootSignatureDescription(RootSignatureFlags.AllowInputAssemblerInputLayout,
                                                                 // root parameters
                                                                 new[]
            {
                new RootParameter(ShaderVisibility.Vertex,
                                  new DescriptorRange()
                {
                    RangeType          = DescriptorRangeType.ConstantBufferView,
                    BaseShaderRegister = 0,
                    OffsetInDescriptorsFromTableStart = 0,
                    DescriptorCount = 1
                }),
                new RootParameter(ShaderVisibility.Pixel,
                                  new DescriptorRange()
                {
                    RangeType          = DescriptorRangeType.ShaderResourceView,
                    BaseShaderRegister = 0,
                    OffsetInDescriptorsFromTableStart = 0,
                    DescriptorCount = 1
                })
            }
                                                                 , staticSamArray
                                                                 );

            m_RootSignature = Device.CreateRootSignature(rootSignatureDesc.Serialize());

            // create the pipeline state, which includes compiling and loading shader
            H1VertexFactoryType vertexFactoryType = ShaderManager.GetVertexFactoryType("H1LocalVertexFactory");

            //H1VertexFactoryType vertexFactoryType = ShaderManager.GetVertexFactoryType("H1GpuSkinVertexFactory");
#if DEBUG
            //var vertexShader = new ShaderBytecode(SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile("shader.hlsl", "VSMain", "vs_5_1", SharpDX.D3DCompiler.ShaderFlags.Debug));
            var vertexShader = H1Material.DefaultMaterial.MaterialResource.GetShader("H1BasePassVertexShader", vertexFactoryType).ShaderByteCode;
#else
            var vertexShader = H1Material.DefaultMaterial.MaterialResource.GetShader("H1BasePassVertexShader", vertexFactoryType).ShaderByteCode;
#endif

#if DEBUG
            //var pixelShader = new ShaderBytecode(SharpDX.D3DCompiler.ShaderBytecode.CompileFromFile("shader.hlsl", "PSMain", "ps_5_1", SharpDX.D3DCompiler.ShaderFlags.Debug));
            var pixelShader = H1Material.DefaultMaterial.MaterialResource.GetShader("H1BasePassPixelShader", vertexFactoryType).ShaderByteCode;
#else
            var pixelShader = H1Material.DefaultMaterial.MaterialResource.GetShader("H1BasePassPixelShader", vertexFactoryType).ShaderByteCode;
#endif

            // set the seperate rasterizerstatedesc
            RasterizerStateDescription rasterizerStateDesc = RasterizerStateDescription.Default();
            rasterizerStateDesc.FillMode = FillMode.Wireframe;
            rasterizerStateDesc.CullMode = CullMode.None;
            //rasterizerStateDesc.CullMode = CullMode.Front; //@TODO - what the f**k?!... need to solve this urgently~******
            //rasterizerStateDesc.FillMode = FillMode.Solid;

            Vector3 position = new Vector3();
            Vector3 size     = new Vector3(1, 1, 1);

            H1RenderUtils.H1DynamicMeshBuilder meshBuilder = H1Global <H1VisualDebugger> .Instance.GetNewDynamicMeshBuilder();

            {
                meshBuilder.AddLine(new Vector4(position + size * new Vector3(1, 0, 0), 1), new Vector4(position - size * new Vector3(1, 0, 0), 1), new Vector4(1));
                meshBuilder.AddLine(new Vector4(position + size * new Vector3(0, 1, 0), 1), new Vector4(position - size * new Vector3(0, 1, 0), 1), new Vector4(1));
                meshBuilder.AddLine(new Vector4(position + size * new Vector3(0, 0, 1), 1), new Vector4(position - size * new Vector3(0, 0, 1), 1), new Vector4(1));
            }

            // generate vertex & index buffers and vertex declaration
            meshBuilder.GenerateVertexIndexBuffersAndVertexDeclaration();

            // describe and create the graphics pipeline state object (PSO)
            var psoDesc = new GraphicsPipelineStateDescription()
            {
                InputLayout        = meshBuilder.VertexFactory.VertexDeclaration.InputLayout.Description,
                RootSignature      = m_RootSignature,
                VertexShader       = vertexShader,
                PixelShader        = pixelShader,
                RasterizerState    = rasterizerStateDesc,
                BlendState         = BlendStateDescription.Default(),
                DepthStencilFormat = SharpDX.DXGI.Format.D32_Float,
                DepthStencilState  = DepthStencilStateDescription.Default(),
                //DepthStencilState = new DepthStencilStateDescription() { IsDepthEnabled = false, IsStencilEnabled = false },
                SampleMask            = int.MaxValue,
                PrimitiveTopologyType = PrimitiveTopologyType.Triangle,
                RenderTargetCount     = 1,
                Flags             = PipelineStateFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                StreamOutput      = new StreamOutputDescription()
            };

            psoDesc.RenderTargetFormats[0] = SharpDX.DXGI.Format.R8G8B8A8_UNorm;

            m_PipelineState = Device.CreateGraphicsPipelineState(psoDesc);

            // create the command list
            m_CommandList = new Direct3D12.H1CommandList(m_DeviceContext.Dx12Device, m_DeviceContext.MainCommandListPool);
            m_CommandList.Initialize();

            // create the vertex buffer
            float aspectRatio = m_Viewport.Width / m_Viewport.Height;

            m_ConstantBuffer = Device.CreateCommittedResource(new HeapProperties(HeapType.Upload), HeapFlags.None, ResourceDescription.Buffer(1024 * 64), ResourceStates.GenericRead);

            var cbvDesc = new ConstantBufferViewDescription
            {
                BufferLocation = m_ConstantBuffer.GPUVirtualAddress,
                SizeInBytes    = 256 * 256//(Utilities.SizeOf<TransformationCB>() + 255) & ~255
            };
            Device.CreateConstantBufferView(cbvDesc, m_ConstantBufferViewHeap.CPUDescriptorHandleForHeapStart);
        }