private static void DrawVoxels(MySortedElements sortedElements, MyLodTypeEnum lod, MyRenderVoxelBatchType batchType, ref int ibChangesStats) { int index = sortedElements.GetVoxelIndex(lod, batchType); var matDict = sortedElements.Voxels[index]; if (matDict.RenderElementCount == 0) { return; } var tech = GetTechnique(batchType == MyRenderVoxelBatchType.SINGLE_MATERIAL ? MyMeshDrawTechnique.VOXEL_MAP_SINGLE : MyMeshDrawTechnique.VOXEL_MAP_MULTI); var shader = (MyEffectVoxels)tech.PrepareAndBeginShader(m_currentSetup, lod); MyPerformanceCounter.PerCameraDrawWrite.TechniqueChanges[(int)lod]++; foreach (var mat in matDict.Voxels) { var firstElement = mat.Value.FirstOrDefault(); if (firstElement == null) { continue; } // Setup material tech.SetupVoxelMaterial(shader, firstElement.VoxelBatch); MyPerformanceCounter.PerCameraDrawWrite.MaterialChanges[(int)lod]++; MyRenderObject lastRenderObject = null; VertexBuffer lastVertexBuffer = null; foreach (var renderElement in mat.Value) { if (!object.ReferenceEquals(lastVertexBuffer, renderElement.VertexBuffer)) { lastVertexBuffer = renderElement.VertexBuffer; GraphicsDevice.Indices = renderElement.IndexBuffer; GraphicsDevice.SetStreamSource(0, renderElement.VertexBuffer, 0, renderElement.VertexStride); GraphicsDevice.VertexDeclaration = renderElement.VertexDeclaration; MyPerformanceCounter.PerCameraDrawWrite.VertexBufferChanges[(int)lod]++; ibChangesStats++; } if (lastRenderObject != renderElement.RenderObject) { lastRenderObject = renderElement.RenderObject; MyPerformanceCounter.PerCameraDrawWrite.EntityChanges[(int)lod]++; tech.SetupEntity(shader, renderElement); shader.D3DEffect.CommitChanges(); } GraphicsDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, renderElement.VertexCount, renderElement.IndexStart, renderElement.TriCount); MyPerformanceCounter.PerCameraDrawWrite.TotalDrawCalls++; } } shader.End(); // Technique End }
private static void DrawVoxels(MySortedElements sortedElements, MyLodTypeEnum lod, MyRenderVoxelBatchType batchType, ref int ibChangesStats) { int index = sortedElements.GetVoxelIndex(lod, batchType); var matDict = sortedElements.Voxels[index]; if (matDict.RenderElementCount == 0) return; var tech = GetTechnique(batchType == MyRenderVoxelBatchType.SINGLE_MATERIAL ? MyMeshDrawTechnique.VOXEL_MAP_SINGLE : MyMeshDrawTechnique.VOXEL_MAP_MULTI); var shader = (MyEffectVoxels)tech.PrepareAndBeginShader(m_currentSetup, lod); MyPerformanceCounter.PerCameraDrawWrite.TechniqueChanges[(int)lod]++; foreach (var mat in matDict.Voxels) { var firstElement = mat.Value.FirstOrDefault(); if (firstElement == null) continue; // Setup material tech.SetupVoxelMaterial(shader, firstElement.VoxelBatch); MyPerformanceCounter.PerCameraDrawWrite.MaterialChanges[(int)lod]++; MyRenderObject lastRenderObject = null; VertexBuffer lastVertexBuffer = null; foreach (var renderElement in mat.Value) { if (!object.ReferenceEquals(lastVertexBuffer, renderElement.VertexBuffer)) { lastVertexBuffer = renderElement.VertexBuffer; GraphicsDevice.Indices = renderElement.IndexBuffer; GraphicsDevice.SetStreamSource(0, renderElement.VertexBuffer, 0, renderElement.VertexStride); GraphicsDevice.VertexDeclaration = renderElement.VertexDeclaration; MyPerformanceCounter.PerCameraDrawWrite.VertexBufferChanges[(int)lod]++; ibChangesStats++; } if (lastRenderObject != renderElement.RenderObject) { lastRenderObject = renderElement.RenderObject; MyPerformanceCounter.PerCameraDrawWrite.EntityChanges[(int)lod]++; tech.SetupEntity(shader, renderElement); shader.D3DEffect.CommitChanges(); } GraphicsDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, renderElement.VertexCount, renderElement.IndexStart, renderElement.TriCount); MyPerformanceCounter.PerCameraDrawWrite.TotalDrawCalls++; } } shader.End(); // Technique End }
private static void DrawVoxels(MySortedElements sortedElements, MyLodTypeEnum lod, MyRenderVoxelBatchType batchType, ref int ibChangesStats) { int index = sortedElements.GetVoxelIndex(lod, batchType); var matDict = sortedElements.Voxels[index]; if (matDict.RenderElementCount == 0) { return; } var tech = GetTechnique(batchType == MyRenderVoxelBatchType.SINGLE_MATERIAL ? MyMeshDrawTechnique.VOXEL_MAP_SINGLE : MyMeshDrawTechnique.VOXEL_MAP_MULTI); var shader = (MyEffectVoxels)tech.PrepareAndBeginShader(m_currentSetup, lod); MyPerformanceCounter.PerCameraDrawWrite.TechniqueChanges[(int)lod]++; if (lod == MyLodTypeEnum.LOD_BACKGROUND) { shader.SetAmbientMinimumAndIntensity(new Vector4(AmbientColor * AmbientMultiplier, EnvAmbientIntensity)); shader.SetSunDirection(m_sun.Direction); shader.SetSunColorAndIntensity(new Vector3(m_sun.Color.X, m_sun.Color.Y, m_sun.Color.Z), m_sun.Intensity); shader.SetBacklightColorAndIntensity(new Vector3(m_sun.BackColor.X, m_sun.BackColor.Y, m_sun.BackColor.Z), m_sun.BackIntensity); var postProcess = MyRender.GetPostProcess(MyPostProcessEnum.VolumetricFog) as MyPostProcessVolumetricFog; shader.EnableFog(postProcess.Enabled); shader.SetSunSpecularColor(m_sun.SpecularColor); } foreach (var mat in matDict.Voxels) { var firstElement = mat.Value.FirstOrDefault(); if (firstElement == null) { continue; } // Setup material tech.SetupVoxelMaterial(shader, firstElement.VoxelBatch); MyPerformanceCounter.PerCameraDrawWrite.MaterialChanges[(int)lod]++; MyRenderObject lastRenderObject = null; VertexBuffer lastVertexBuffer = null; foreach (var renderElement in mat.Value) { if (!object.ReferenceEquals(lastVertexBuffer, renderElement.VertexBuffer)) { lastVertexBuffer = renderElement.VertexBuffer; GraphicsDevice.Indices = renderElement.IndexBuffer; GraphicsDevice.SetStreamSource(0, renderElement.VertexBuffer, 0, renderElement.VertexStride); GraphicsDevice.VertexDeclaration = renderElement.VertexDeclaration; MyPerformanceCounter.PerCameraDrawWrite.VertexBufferChanges[(int)lod]++; ibChangesStats++; } if (lastRenderObject != renderElement.RenderObject) { lastRenderObject = renderElement.RenderObject; MyPerformanceCounter.PerCameraDrawWrite.EntityChanges[(int)lod]++; tech.SetupEntity(shader, renderElement); shader.D3DEffect.CommitChanges(); } GraphicsDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, renderElement.VertexCount, renderElement.IndexStart, renderElement.TriCount); MyPerformanceCounter.PerCameraDrawWrite.TotalDrawCalls++; } } shader.End(); // Technique End }
private static void DrawVoxels(MySortedElements sortedElements, MyLodTypeEnum lod, MyRenderVoxelBatchType batchType, ref int ibChangesStats) { int index = sortedElements.GetVoxelIndex(lod, batchType); var matDict = sortedElements.Voxels[index]; if (matDict.RenderElementCount == 0) return; var tech = GetTechnique(batchType == MyRenderVoxelBatchType.SINGLE_MATERIAL ? MyMeshDrawTechnique.VOXEL_MAP_SINGLE : MyMeshDrawTechnique.VOXEL_MAP_MULTI); var shader = (MyEffectVoxels)tech.PrepareAndBeginShader(m_currentSetup, lod); MyPerformanceCounter.PerCameraDrawWrite.TechniqueChanges[(int)lod]++; if (lod == MyLodTypeEnum.LOD_BACKGROUND) { shader.SetAmbientMinimumAndIntensity(new Vector4(AmbientColor * AmbientMultiplier, EnvAmbientIntensity)); shader.SetSunDirection(m_sun.Direction); shader.SetSunColorAndIntensity(new Vector3(m_sun.Color.X, m_sun.Color.Y, m_sun.Color.Z), m_sun.Intensity); shader.SetBacklightColorAndIntensity(new Vector3(m_sun.BackColor.X, m_sun.BackColor.Y, m_sun.BackColor.Z), m_sun.BackIntensity); var postProcess = MyRender.GetPostProcess(MyPostProcessEnum.VolumetricFog) as MyPostProcessVolumetricFog; shader.EnableFog(postProcess.Enabled); shader.SetSunSpecularColor(m_sun.SpecularColor); } foreach (var mat in matDict.Voxels) { var firstElement = mat.Value.FirstOrDefault(); if (firstElement == null) continue; // Setup material tech.SetupVoxelMaterial(shader, firstElement.VoxelBatch); MyPerformanceCounter.PerCameraDrawWrite.MaterialChanges[(int)lod]++; MyRenderObject lastRenderObject = null; VertexBuffer lastVertexBuffer = null; foreach (var renderElement in mat.Value) { if (!object.ReferenceEquals(lastVertexBuffer, renderElement.VertexBuffer)) { lastVertexBuffer = renderElement.VertexBuffer; GraphicsDevice.Indices = renderElement.IndexBuffer; GraphicsDevice.SetStreamSource(0, renderElement.VertexBuffer, 0, renderElement.VertexStride); GraphicsDevice.VertexDeclaration = renderElement.VertexDeclaration; MyPerformanceCounter.PerCameraDrawWrite.VertexBufferChanges[(int)lod]++; ibChangesStats++; } if (lastRenderObject != renderElement.RenderObject) { lastRenderObject = renderElement.RenderObject; MyPerformanceCounter.PerCameraDrawWrite.EntityChanges[(int)lod]++; tech.SetupEntity(shader, renderElement); shader.D3DEffect.CommitChanges(); } GraphicsDevice.DrawIndexedPrimitive(PrimitiveType.TriangleList, 0, 0, renderElement.VertexCount, renderElement.IndexStart, renderElement.TriCount); MyPerformanceCounter.PerCameraDrawWrite.TotalDrawCalls++; } } shader.End(); // Technique End }