private int DoRenderPass( RenderContext context, CommandList commandList, RenderBucket bucket, BoundingFrustum cameraFrustum, ResourceSet forwardPassResourceSet, in Plane?clippingPlane1 = null,
private int DoRenderPass( RenderContext context, CommandList commandList, RenderBucket bucket, BoundingFrustum cameraFrustum, ResourceSet cloudResourceSet) { // TODO: Make culling batch size configurable at runtime bucket.RenderItems.CullAndSort(cameraFrustum, ParallelCullingBatchSize); if (bucket.RenderItems.CulledItemIndices.Count == 0) { return(0); } Matrix4x4?lastWorld = null; int? lastRenderItemIndex = null; foreach (var i in bucket.RenderItems.CulledItemIndices) { ref var renderItem = ref bucket.RenderItems[i]; if (lastRenderItemIndex == null || bucket.RenderItems[lastRenderItemIndex.Value].Pipeline != renderItem.Pipeline) { commandList.InsertDebugMarker("Setting pipeline"); commandList.SetPipeline(renderItem.Pipeline); SetGlobalResources(commandList, renderItem.ShaderSet.GlobalResourceSetIndices, cloudResourceSet); } if (renderItem.ShaderSet.GlobalResourceSetIndices.RenderItemConstants != null) { if (lastWorld == null || lastWorld.Value != renderItem.World) { _renderItemConstantsBufferVS.Value.World = renderItem.World; _renderItemConstantsBufferVS.Update(commandList); lastWorld = renderItem.World; } if (renderItem.RenderItemConstantsPS != null) { _renderItemConstantsBufferPS.Value = renderItem.RenderItemConstantsPS.Value; _renderItemConstantsBufferPS.Update(commandList); } } renderItem.BeforeRenderCallback.Invoke(commandList, context); commandList.SetIndexBuffer(renderItem.IndexBuffer, IndexFormat.UInt16); commandList.DrawIndexed( renderItem.IndexCount, 1, renderItem.StartIndex, 0, 0); lastRenderItemIndex = i; }
private void DoRenderPass( CommandList commandList, RenderBucket bucket, BoundingFrustum cameraFrustum, Texture cloudTexture, Texture shadowMap) { // TODO: Make culling batch size configurable at runtime bucket.RenderItems.CullAndSort(cameraFrustum, ParallelCullingBatchSize); if (bucket.RenderItems.CulledItemIndices.Count == 0) { return; } Matrix4x4?lastWorld = null; int? lastRenderItemIndex = null; foreach (var i in bucket.RenderItems.CulledItemIndices) { ref var renderItem = ref bucket.RenderItems[i]; if (lastRenderItemIndex == null || bucket.RenderItems[lastRenderItemIndex.Value].Effect != renderItem.Effect) { var effect = renderItem.Effect; effect.Begin(commandList); SetDefaultMaterialProperties(renderItem.Material, cloudTexture, shadowMap); } if (lastRenderItemIndex == null || bucket.RenderItems[lastRenderItemIndex.Value].Material != renderItem.Material) { renderItem.Material.ApplyPipelineState(); renderItem.Effect.ApplyPipelineState(commandList); } if (lastRenderItemIndex == null || bucket.RenderItems[lastRenderItemIndex.Value].VertexBuffer0 != renderItem.VertexBuffer0) { commandList.SetVertexBuffer(0, renderItem.VertexBuffer0); } if (lastRenderItemIndex == null || bucket.RenderItems[lastRenderItemIndex.Value].VertexBuffer1 != renderItem.VertexBuffer1) { if (renderItem.VertexBuffer1 != null) { commandList.SetVertexBuffer(1, renderItem.VertexBuffer1); } } var renderItemConstantsVSParameter = renderItem.Effect.GetParameter("RenderItemConstantsVS", throwIfMissing: false); if (renderItemConstantsVSParameter != null) { if (lastWorld == null || lastWorld.Value != renderItem.World) { _renderItemConstantsBufferVS.Value.World = renderItem.World; _renderItemConstantsBufferVS.Update(commandList); lastWorld = renderItem.World; } renderItem.Material.SetProperty( "RenderItemConstantsVS", _renderItemConstantsBufferVS.Buffer); } if (renderItem.HouseColor != null) { var renderItemConstantsPSParameter = renderItem.Effect.GetParameter("RenderItemConstantsPS", throwIfMissing: false); if (renderItemConstantsPSParameter != null) { _renderItemConstantsBufferPS.Value.HouseColor = renderItem.HouseColor.Value.ToVector3(); _renderItemConstantsBufferPS.Update(commandList); renderItem.Material.SetProperty( "RenderItemConstantsPS", _renderItemConstantsBufferPS.Buffer); } } renderItem.Material.ApplyProperties(); renderItem.Effect.ApplyParameters(commandList); switch (renderItem.DrawCommand) { case DrawCommand.Draw: commandList.Draw( renderItem.VertexCount, 1, renderItem.VertexStart, 0); break; case DrawCommand.DrawIndexed: commandList.SetIndexBuffer(renderItem.IndexBuffer, IndexFormat.UInt16); commandList.DrawIndexed( renderItem.IndexCount, 1, renderItem.StartIndex, 0, 0); break; default: throw new System.Exception(); } lastRenderItemIndex = i; }