public void DrawTransparent(Camera camera) { int gameWidgetIndex = camera.GameWidget.GameWidgetIndex; Vector3 viewPosition = camera.ViewPosition; Vector3 v = new Vector3(MathUtils.Floor(viewPosition.X), 0f, MathUtils.Floor(viewPosition.Z)); Matrix value = Matrix.CreateTranslation(v - viewPosition) * camera.ViewMatrix.OrientationMatrix * camera.ProjectionMatrix; Display.BlendState = BlendState.AlphaBlend; Display.DepthStencilState = DepthStencilState.Default; Display.RasterizerState = ((m_subsystemSky.ViewUnderWaterDepth > 0f) ? RasterizerState.CullClockwiseScissor : RasterizerState.CullCounterClockwiseScissor); m_transparentShader.GetParameter("u_origin").SetValue(v.XZ); m_transparentShader.GetParameter("u_viewProjectionMatrix").SetValue(value); m_transparentShader.GetParameter("u_viewPosition").SetValue(viewPosition); m_transparentShader.GetParameter("u_texture").SetValue(m_subsystemAnimatedTextures.AnimatedBlocksTexture); m_transparentShader.GetParameter("u_samplerState").SetValue(SettingsManager.TerrainMipmapsEnabled ? m_samplerStateMips : m_samplerState); m_transparentShader.GetParameter("u_fogYMultiplier").SetValue(m_subsystemSky.VisibilityRangeYMultiplier); m_transparentShader.GetParameter("u_fogColor").SetValue(new Vector3(m_subsystemSky.ViewFogColor)); ShaderParameter parameter = m_transparentShader.GetParameter("u_fogStartInvLength"); for (int i = 0; i < m_chunksToDraw.Count; i++) { TerrainChunk terrainChunk = m_chunksToDraw[i]; float num = MathUtils.Min(terrainChunk.FogEnds[gameWidgetIndex], m_subsystemSky.ViewFogRange.Y); float num2 = MathUtils.Min(m_subsystemSky.ViewFogRange.X, num - 1f); parameter.SetValue(new Vector2(num2, 1f / (num - num2))); int subsetsMask = 64; DrawTerrainChunkGeometrySubsets(m_transparentShader, terrainChunk.Geometry, subsetsMask); } }
public void DrawFillHighlight(Camera camera) { if (camera.Eye.HasValue && m_highlightRaycastResult is TerrainRaycastResult) { CellFace cellFace = ((TerrainRaycastResult)m_highlightRaycastResult).CellFace; int cellValue = m_subsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z); int num = Terrain.ExtractContents(cellValue); Block block = BlocksManager.Blocks[num]; if (m_geometry == null || cellValue != m_value || cellFace != m_cellFace) { m_geometry = new Geometry(); block.GenerateTerrainVertices(m_subsystemTerrain.BlockGeometryGenerator, m_geometry, cellValue, cellFace.X, cellFace.Y, cellFace.Z); m_cellFace = cellFace; m_value = cellValue; } DynamicArray <TerrainVertex> vertices = m_geometry.SubsetOpaque.Vertices; DynamicArray <ushort> indices = m_geometry.SubsetOpaque.Indices; float x = m_subsystemSky.ViewFogRange.X; float y = m_subsystemSky.ViewFogRange.Y; Vector3 viewPosition = camera.ViewPosition; Vector3 v = new Vector3(MathUtils.Floor(viewPosition.X), 0f, MathUtils.Floor(viewPosition.Z)); Matrix value = Matrix.CreateTranslation(v - viewPosition) * camera.ViewMatrix.OrientationMatrix * camera.ProjectionMatrix; Display.BlendState = BlendState.NonPremultiplied; Display.DepthStencilState = DepthStencilState.Default; Display.RasterizerState = RasterizerState.CullCounterClockwiseScissor; m_shader.GetParameter("u_origin").SetValue(v.XZ); m_shader.GetParameter("u_viewProjectionMatrix").SetValue(value); m_shader.GetParameter("u_viewPosition").SetValue(viewPosition); m_shader.GetParameter("u_texture").SetValue(m_subsystemAnimatedTextures.AnimatedBlocksTexture); m_shader.GetParameter("u_samplerState").SetValue(SamplerState.PointWrap); m_shader.GetParameter("u_fogColor").SetValue(new Vector3(m_subsystemSky.ViewFogColor)); m_shader.GetParameter("u_fogStartInvLength").SetValue(new Vector2(x, 1f / (y - x))); Display.DrawUserIndexed(PrimitiveType.TriangleList, m_shader, TerrainVertex.VertexDeclaration, vertices.Array, 0, vertices.Count, indices.Array, 0, indices.Count); } }
public void Draw(Camera camera, int drawOrder) { if (!m_componentMiner.DigCellFace.HasValue || !(m_componentMiner.DigProgress > 0f) || !(m_componentMiner.DigTime > 0.2f)) { return; } Point3 point = m_componentMiner.DigCellFace.Value.Point; int cellValue = m_subsystemTerrain.Terrain.GetCellValue(point.X, point.Y, point.Z); int num = Terrain.ExtractContents(cellValue); Block block = BlocksManager.Blocks[num]; if (m_geometry == null || cellValue != m_value || point != m_point) { m_geometry = new Geometry(); block.GenerateTerrainVertices(m_subsystemTerrain.BlockGeometryGenerator, m_geometry, cellValue, point.X, point.Y, point.Z); m_point = point; m_value = cellValue; m_vertices.Clear(); CracksVertex item = default(CracksVertex); for (int i = 0; i < m_geometry.SubsetOpaque.Vertices.Count; i++) { TerrainVertex terrainVertex = m_geometry.SubsetOpaque.Vertices.Array[i]; byte b = (byte)((terrainVertex.Color.R + terrainVertex.Color.G + terrainVertex.Color.B) / 3); item.X = terrainVertex.X; item.Y = terrainVertex.Y; item.Z = terrainVertex.Z; item.Tx = (float)terrainVertex.Tx / 32767f * 16f; item.Ty = (float)terrainVertex.Ty / 32767f * 16f; item.Color = new Color(b, b, b, (byte)128); m_vertices.Add(item); } } Vector3 viewPosition = camera.ViewPosition; Vector3 v = new Vector3(MathUtils.Floor(viewPosition.X), 0f, MathUtils.Floor(viewPosition.Z)); Matrix value = Matrix.CreateTranslation(v - viewPosition) * camera.ViewMatrix.OrientationMatrix * camera.ProjectionMatrix; DynamicArray <ushort> indices = m_geometry.SubsetOpaque.Indices; float x = m_subsystemSky.ViewFogRange.X; float y = m_subsystemSky.ViewFogRange.Y; int num2 = MathUtils.Clamp((int)(m_componentMiner.DigProgress * 8f), 0, 7); Display.BlendState = BlendState.NonPremultiplied; Display.DepthStencilState = DepthStencilState.Default; Display.RasterizerState = RasterizerState.CullCounterClockwiseScissor; m_shader.GetParameter("u_origin").SetValue(v.XZ); m_shader.GetParameter("u_viewProjectionMatrix").SetValue(value); m_shader.GetParameter("u_viewPosition").SetValue(camera.ViewPosition); m_shader.GetParameter("u_texture").SetValue(m_textures[num2]); m_shader.GetParameter("u_samplerState").SetValue(SamplerState.PointWrap); m_shader.GetParameter("u_fogColor").SetValue(new Vector3(m_subsystemSky.ViewFogColor)); m_shader.GetParameter("u_fogStartInvLength").SetValue(new Vector2(x, 1f / (y - x))); Display.DrawUserIndexed(PrimitiveType.TriangleList, m_shader, CracksVertex.VertexDeclaration, m_vertices.Array, 0, m_vertices.Count, indices.Array, 0, indices.Count); }
public void Draw(Camera camera, int drawOrder) { m_vertices.Clear(); m_indices.Clear(); foreach (MovingBlockSet movingBlockSet2 in m_movingBlockSets) { DrawMovingBlockSet(camera, movingBlockSet2); } int num = 0; while (num < m_removing.Count) { MovingBlockSet movingBlockSet = m_removing[num]; if (movingBlockSet.RemainCounter-- > 0) { DrawMovingBlockSet(camera, movingBlockSet); num++; } else { m_removing.RemoveAt(num); } } if (m_vertices.Count > 0) { Vector3 viewPosition = camera.ViewPosition; Vector3 v = new Vector3(MathUtils.Floor(viewPosition.X), 0f, MathUtils.Floor(viewPosition.Z)); Matrix value = Matrix.CreateTranslation(v - viewPosition) * camera.ViewMatrix.OrientationMatrix * camera.ProjectionMatrix; Display.BlendState = BlendState.Opaque; Display.DepthStencilState = DepthStencilState.Default; Display.RasterizerState = RasterizerState.CullCounterClockwiseScissor; m_shader.GetParameter("u_origin").SetValue(v.XZ); m_shader.GetParameter("u_viewProjectionMatrix").SetValue(value); m_shader.GetParameter("u_viewPosition").SetValue(camera.ViewPosition); m_shader.GetParameter("u_texture").SetValue(m_subsystemAnimatedTextures.AnimatedBlocksTexture); m_shader.GetParameter("u_samplerState").SetValue(SamplerState.PointClamp); m_shader.GetParameter("u_fogColor").SetValue(new Vector3(m_subsystemSky.ViewFogColor)); m_shader.GetParameter("u_fogStartInvLength").SetValue(new Vector2(m_subsystemSky.ViewFogRange.X, 1f / (m_subsystemSky.ViewFogRange.Y - m_subsystemSky.ViewFogRange.X))); Display.DrawUserIndexed(PrimitiveType.TriangleList, m_shader, TerrainVertex.VertexDeclaration, m_vertices.Array, 0, m_vertices.Count, m_indices.Array, 0, m_indices.Count); } if (DebugDrawMovingBlocks) { DebugDraw(); } }