private string StaticSamplerToString(StaticSampler sampler) { var sb = new StringBuilder(); sb.AppendFormat("StaticSampler(s{0}", sampler.ShaderRegister); if (sampler.Filter != Filter.Anisotropic) { sb.AppendFormat(", filter={0}", sampler.Filter.GetDescription(ChunkType.Rts0)); } if (sampler.AddressU != TextureAddressMode.Wrap) { sb.AppendFormat(", addressU={0}", sampler.AddressU.GetDescription(ChunkType.Rts0)); } if (sampler.AddressV != TextureAddressMode.Wrap) { sb.AppendFormat(", addressV={0}", sampler.AddressV.GetDescription(ChunkType.Rts0)); } if (sampler.AddressW != TextureAddressMode.Wrap) { sb.AppendFormat(", addressW={0}", sampler.AddressW.GetDescription(ChunkType.Rts0)); } if (sampler.MipLODBias != 0) { sb.AppendFormat(", mipLODBias={0}", sampler.MipLODBias); } if (sampler.MaxAnisotropy != 16) { sb.AppendFormat(", maxAnisotropy={0}", sampler.MaxAnisotropy); } if (sampler.ComparisonFunc != ComparisonFunc.LessEqual) { sb.AppendFormat(", comparisonFunc={0}", sampler.ComparisonFunc.GetDescription(ChunkType.Rts0)); } if (sampler.BorderColor != StaticBorderColor.OpaqueWhite) { sb.AppendFormat(", borderColor={0}", sampler.BorderColor.GetDescription()); } if (sampler.MinLOD != 0) { sb.AppendFormat(", minLOD={0}", sampler.MinLOD); } if (sampler.MaxLOD != float.MaxValue) { sb.AppendFormat(", maxLOD={0}", sampler.MaxLOD); } if (sampler.RegisterSpace > 0) { sb.AppendFormat(", space={0}", sampler.RegisterSpace); } if (sampler.ShaderVisibility != ShaderVisibility.All) { sb.AppendFormat(", visibility={0}", sampler.ShaderVisibility.GetDescription()); } sb.Append(")"); return(sb.ToString()); }
public WorldPass(GraphicsDevice device, Camera camera) { _device = device; _camera = camera; _rtvs = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1); _dsvs = _device.CreateDescriptorHeap(DescriptorHeapType.RenderTargetView, 1); var @params = new RootParameter[] { RootParameter.CreateDescriptor(RootParameterType.ConstantBufferView, 0, 0), RootParameter.CreateDescriptor(RootParameterType.ConstantBufferView, 1, 0), RootParameter.CreateDescriptor(RootParameterType.ShaderResourceView, 0, 0, ShaderVisibility.Pixel), RootParameter.CreateDescriptorTable(DescriptorRangeType.ShaderResourceView, 1, 2, 0, visibility: ShaderVisibility.Pixel) }; var samplers = new StaticSampler[] { new StaticSampler(TextureAddressMode.Clamp, SamplerFilterType.MagPoint | SamplerFilterType.MinPoint | SamplerFilterType.MipLinear, 0, 0, ShaderVisibility.Pixel) }; RootSignature = _device.CreateRootSignature(@params, samplers); var shaderFlags = new[] { ShaderCompileFlag.PackMatricesInRowMajorOrder, ShaderCompileFlag.DisableOptimizations, ShaderCompileFlag.EnableDebugInformation, ShaderCompileFlag.WriteDebugInformationToFile() }; var psoDesc = new GraphicsPipelineDesc { RootSignature = RootSignature, Topology = TopologyClass.Triangle, RenderTargetFormats = BackBufferFormat.R8G8B8A8UnsignedNormalized, DepthStencilFormat = DataFormat.Depth32Single, VertexShader = ShaderManager.CompileShader("Shaders/ChunkShader.hlsl", ShaderType.Vertex, shaderFlags, "VertexMain"), PixelShader = ShaderManager.CompileShader("Shaders/ChunkShader.hlsl", ShaderType.Pixel, shaderFlags, "PixelMain"), Inputs = InputLayout.FromType <BlockVertex>() }; Pso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "ChunkPso"); psoDesc.Msaa = MsaaDesc.X8; MsaaPso = _device.PipelineManager.CreatePipelineStateObject(psoDesc, "MsaaChunkPso"); UploadTextures(); Chunks = new[] { new RenderChunk() }; Chunks[0].Chunk.Blocks = new Block?[Width * Height * Depth]; Chunks[0].Chunk.NeedsRebuild = true; var rng = new Random(); foreach (ref readonly var block in Chunks[0].Chunk.Blocks.Span) { Unsafe.AsRef(in block) = new Block { TextureId = (uint)rng.Next(0, _textures.Length) }; } SetConstants(); }