void RenderSky(double delta) { if (game.SkyboxRenderer.ShouldRender) { return; } Vector3 pos = game.CurrentCameraPos; float normalY = map.Height + 8; float skyY = Math.Max(pos.Y + 8, normalY); IGraphicsApi gfx = game.Graphics; gfx.SetBatchFormat(VertexFormat.P3fC4b); gfx.BindVb(skyVb); if (skyY == normalY) { gfx.DrawVb_IndexedTris(skyVertices); } else { Matrix4 m = game.Graphics.View; float dy = skyY - normalY; // inlined Y translation matrix multiply m.Row3.X += dy * m.Row1.X; m.Row3.Y += dy * m.Row1.Y; m.Row3.Z += dy * m.Row1.Z; m.Row3.W += dy * m.Row1.W; gfx.LoadMatrix(ref m); gfx.DrawVb_IndexedTris(skyVertices); gfx.LoadMatrix(ref game.Graphics.View); } }
public void RenderEdges(double delta) { if (edgesVb == -1) { return; } BlockID block = game.World.Env.EdgeBlock; IGraphicsApi gfx = game.Graphics; Vector3 camPos = game.CurrentCameraPos; gfx.Texturing = true; gfx.SetupAlphaState(BlockInfo.Draw[block]); gfx.EnableMipmaps(); gfx.BindTexture(edgeTexId); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(edgesVb); // Do not draw water when we cannot see it. // Fixes some 'depth bleeding through' issues with 16 bit depth buffers on large maps. float yVisible = Math.Min(0, map.Env.SidesHeight); if (camPos.Y >= yVisible) { gfx.DrawVb_IndexedTris(edgesVertices); } gfx.DisableMipmaps(); gfx.RestoreAlphaState(BlockInfo.Draw[block]); gfx.Texturing = false; }
void RenderClouds(double delta) { if (game.World.Env.CloudHeight < -2000) { return; } double time = game.accumulator; float offset = (float)(time / 2048f * 0.6f * map.Env.CloudsSpeed); IGraphicsApi gfx = game.Graphics; gfx.SetMatrixMode(MatrixType.Texture); Matrix4 matrix = Matrix4.Identity; matrix.Row3.X = offset; // translate X axis gfx.LoadMatrix(ref matrix); gfx.SetMatrixMode(MatrixType.Modelview); gfx.AlphaTest = true; gfx.Texturing = true; gfx.BindTexture(cloudsTex); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(cloudsVb); gfx.DrawVb_IndexedTris(cloudVertices); gfx.AlphaTest = false; gfx.Texturing = false; gfx.SetMatrixMode(MatrixType.Texture); gfx.LoadIdentityMatrix(); gfx.SetMatrixMode(MatrixType.Modelview); }
public void RenderSides(double delta) { if (sidesVb == -1) { return; } BlockID block = game.World.Env.SidesBlock; gfx.Texturing = true; gfx.SetupAlphaState(BlockInfo.Draw[block]); gfx.EnableMipmaps(); gfx.BindTexture(sideTexId); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(sidesVb); gfx.DrawVb_IndexedTris(sidesVertices); gfx.DisableMipmaps(); gfx.RestoreAlphaState(BlockInfo.Draw[block]); gfx.Texturing = false; }
void RenderBorders(BlockID block, int vb, int tex, int count) { if (vb == 0) { return; } IGraphicsApi gfx = game.Graphics; gfx.Texturing = true; gfx.SetupAlphaState(BlockInfo.Draw[block]); gfx.EnableMipmaps(); gfx.BindTexture(tex); gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.BindVb(vb); if (count > 0) { gfx.DrawVb_IndexedTris(count); } gfx.DisableMipmaps(); gfx.RestoreAlphaState(BlockInfo.Draw[block]); gfx.Texturing = false; }
unsafe void RenderTerrainParticles(IGraphicsApi gfx, TerrainParticle[] particles, int elems, double delta, float t) { int count = elems * 4; if (count > vertices.Length) { vertices = new VertexP3fT2fC4b[count]; } Update1DCounts(particles, elems); for (int i = 0; i < elems; i++) { int index = Atlas1D.Get1DIndex(particles[i].texLoc); particles[i].Render(game, t, vertices, ref terrain1DIndices[index]); } int drawCount = Math.Min(count, maxParticles * 4); if (drawCount == 0) { return; fixed(VertexP3fT2fC4b *ptr = vertices) { gfx.SetDynamicVbData(vb, (IntPtr)ptr, drawCount); int offset = 0; for (int i = 0; i < Atlas1D.AtlasesCount; i++) { int partCount = terrain1DCount[i]; if (partCount == 0) { continue; } gfx.BindTexture(Atlas1D.TexIds[i]); gfx.DrawVb_IndexedTris(partCount, offset); offset += partCount; } } } void Update1DCounts(TerrainParticle[] particles, int elems) { for (int i = 0; i < Atlas1D.MaxAtlases; i++) { terrain1DCount[i] = 0; terrain1DIndices[i] = 0; } for (int i = 0; i < elems; i++) { int index = Atlas1D.Get1DIndex(particles[i].texLoc); terrain1DCount[index] += 4; } for (int i = 1; i < Atlas1D.AtlasesCount; i++) { terrain1DIndices[i] = terrain1DIndices[i - 1] + terrain1DCount[i - 1]; } } void RenderRainParticles(IGraphicsApi gfx, RainParticle[] particles, int elems, double delta, float t) { int count = elems * 4; if (count > vertices.Length) { vertices = new VertexP3fT2fC4b[count]; } int index = 0; for (int i = 0; i < elems; i++) { particles[i].Render(game, t, vertices, ref index); } int drawCount = Math.Min(count, maxParticles * 4); if (drawCount == 0) { return; } gfx.BindTexture(ParticlesTexId); gfx.UpdateDynamicVb_IndexedTris(vb, vertices, drawCount); }