public void Render(double delta, VertexP3fC4b[] vertices, VertexP3fC4b[] lineVertices, ref int index, ref int lineIndex) { float offset = MinDist < 32 * 32 ? 1 / 32f : 1 / 16f; Vector3 p1 = (Vector3)Min - new Vector3(offset, offset, offset); Vector3 p2 = (Vector3)Max + new Vector3(offset, offset, offset); int col = Colour.Pack(); HorQuad(vertices, ref index, col, p1.X, p1.Z, p2.X, p2.Z, p1.Y); // bottom HorQuad(vertices, ref index, col, p1.X, p1.Z, p2.X, p2.Z, p2.Y); // top VerQuad(vertices, ref index, col, p1.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z); // sides VerQuad(vertices, ref index, col, p1.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z); VerQuad(vertices, ref index, col, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p2.Z); VerQuad(vertices, ref index, col, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z); col = new FastColour((byte)~Colour.R, (byte)~Colour.G, (byte)~Colour.B).Pack(); // bottom face Line(lineVertices, ref lineIndex, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z, col); Line(lineVertices, ref lineIndex, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z, col); Line(lineVertices, ref lineIndex, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z, col); Line(lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z, col); // top face Line(lineVertices, ref lineIndex, p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z, col); Line(lineVertices, ref lineIndex, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z, col); Line(lineVertices, ref lineIndex, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z, col); Line(lineVertices, ref lineIndex, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z, col); // side faces Line(lineVertices, ref lineIndex, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z, col); Line(lineVertices, ref lineIndex, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z, col); Line(lineVertices, ref lineIndex, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z, col); Line(lineVertices, ref lineIndex, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col); }
unsafe void RenderStars(ref VertexP3fT2fC4b *vertices) { VertexP3fT2fC4b v; v.Colour = starColour.Pack(); for (int i = 0; i < 500; i++) { float pitch = (float)(Utils.Lerp(0.025f, 0.975f, rand.NextFloat()) * 2 * Math.PI); float yaw = (float)(Utils.Lerp(0.025f, 0.975f, rand.NextFloat()) * 2 * Math.PI); const float size = 0.001f; Vector3 p00 = new Vector3(-size, -size, 0.2f); Vector3 p10 = new Vector3(+size, -size, 0.2f); Vector3 p11 = new Vector3(+size, +size, 0.2f); Vector3 p01 = new Vector3(-size, +size, 0.2f); p00 = Utils.RotateY(p00, yaw); p10 = Utils.RotateY(p10, yaw); p11 = Utils.RotateY(p11, yaw); p01 = Utils.RotateY(p01, yaw); p00 = Utils.RotateZ(p00, pitch); p10 = Utils.RotateZ(p10, pitch); p11 = Utils.RotateZ(p11, pitch); p01 = Utils.RotateZ(p01, pitch); v.X = p00.X; v.Y = p00.Y; v.Z = p00.Z; v.U = 0.00f; v.V = 0.00f; *vertices = v; vertices++; v.X = p10.X; v.Y = p10.Y; v.Z = p10.Z; v.U = 1.00f; *vertices = v; vertices++; v.X = p11.X; v.Y = p11.Y; v.Z = p11.Z; v.V = 1.00f; *vertices = v; vertices++; v.X = p01.X; v.Y = p01.Y; v.Z = p01.Z; v.U = 0.00f; *vertices = v; vertices++; } }
public virtual void Draw2DTexture(ref Texture tex, FastColour col) { int index = 0; Make2DQuad(ref tex, col.Pack(), texVerts, ref index); SetBatchFormat(VertexFormat.P3fT2fC4bN1v); UpdateDynamicVb_IndexedTris(texVb, texVerts, 4); }
public virtual void Draw2DTexture(ref Texture tex, FastColour col) { int index = 0; Make2DQuad(ref tex, col.Pack(), texVerts, ref index); SetBatchFormat(VertexFormat.P3fT2fC4b); UpdateDynamicIndexedVb(DrawMode.Triangles, texVb, texVerts, 4); }
public override void SetFogColour(FastColour col) { fogCol = col.Pack(); if (fogCol == lastFogCol) { return; } device.SetRenderState(RenderState.FogColor, fogCol); lastFogCol = fogCol; }
public virtual void Draw2DQuad(int x, int y, int width, int height, FastColour col) { int c = col.Pack(); quadVerts[0] = new VertexP3fC4b(x, y, 0, c); quadVerts[1] = new VertexP3fC4b(x + width, y, 0, c); quadVerts[2] = new VertexP3fC4b(x + width, y + height, 0, c); quadVerts[3] = new VertexP3fC4b(x, y + height, 0, c); SetBatchFormat(VertexFormat.P3fC4b); UpdateDynamicVb_IndexedTris(quadVb, quadVerts, 4); }
public virtual void Draw2DQuad(float x, float y, float width, float height, FastColour col) { int c = col.Pack(); quadVerts[0] = new VertexP3fC4b(x, y, 0, c); quadVerts[1] = new VertexP3fC4b(x + width, y, 0, c); quadVerts[2] = new VertexP3fC4b(x + width, y + height, 0, c); quadVerts[3] = new VertexP3fC4b(x, y + height, 0, c); SetBatchFormat(VertexFormat.P3fC4b); UpdateDynamicIndexedVb(DrawMode.Triangles, quadVb, quadVerts, 4); }
void ResetLight() { Shadowlight = DefaultShadowlight; Shadow = Shadowlight.Pack(); FastColour.GetShaded(Shadowlight, out ShadowXSide, out ShadowZSide, out ShadowYBottom); Sunlight = DefaultSunlight; Sun = Sunlight.Pack(); FastColour.GetShaded(Sunlight, out SunXSide, out SunZSide, out SunYBottom); }
/// <summary> Sets current shadowlight colour, and raises /// EnvVariableChanged event with variable 'ShadowlightColour'. </summary> public void SetShadowlight(FastColour col) { if (!Set(col, ref Shadowlight, EnvVar.ShadowlightColour)) { return; } FastColour.GetShaded(Shadowlight, out ShadowXSide, out ShadowZSide, out ShadowYBottom); Shadow = Shadowlight.Pack(); game.WorldEvents.RaiseEnvVariableChanged(EnvVar.ShadowlightColour); }
/// <summary> Sets current shadowlight colour, and raises /// EnvVariableChanged event with variable 'ShadowlightColour'. </summary> public void SetShadowlight(FastColour col) { if (col == Shadowlight) { return; } Shadowlight = col; FastColour.GetShaded(col, out ShadowXSide, out ShadowZSide, out ShadowYBottom); Shadow = Shadowlight.Pack(); game.WorldEvents.RaiseEnvVariableChanged(EnvVar.ShadowlightColour); }
public static void Make2DQuad(ref Texture tex, FastColour col, VertexP3fT2fC4b[] vertices, ref int index) { float x1 = tex.X, y1 = tex.Y, x2 = tex.X + tex.Width, y2 = tex.Y + tex.Height; #if USE_DX // NOTE: see "https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx", // i.e. the msdn article called "Directly Mapping Texels to Pixels (Direct3D 9)" for why we have to do this. x1 -= 0.5f; x2 -= 0.5f; y1 -= 0.5f; y2 -= 0.5f; #endif int c = col.Pack(); vertices[index++] = new VertexP3fT2fC4b(x1, y1, 0, tex.U1, tex.V1, c); vertices[index++] = new VertexP3fT2fC4b(x2, y1, 0, tex.U2, tex.V1, c); vertices[index++] = new VertexP3fT2fC4b(x2, y2, 0, tex.U2, tex.V2, c); vertices[index++] = new VertexP3fT2fC4b(x1, y2, 0, tex.U1, tex.V2, c); }
void UpdateStars() { float skyMul = (float)(Math.Cos(CelestialAngle * (2 * Math.PI)) * 4 + 0.5); Utils.Clamp(ref skyMul, 0, 1); FastColour newStarColour = FastColour.Lerp2(starColour, starColourHidden, skyMul); if (newStarColour != curStarColour) { int newStarColourPacked = newStarColour.Pack(); for (int i = 0; i < starCount; i++) { vertices4[i].Colour = newStarColourPacked; } curStarColour = newStarColour; } }
public void Render(Game game, float t, VertexP3fT2fC4b[] vertices, ref int index) { Vector3 pos = Vector3.Lerp(lastPos, nextPos, t); int col = FastColour.WhitePacked; if (!BlockInfo.FullBright[block]) { int x = Utils.Floor(pos.X), y = Utils.Floor(pos.Y), z = Utils.Floor(pos.Z); col = game.World.IsValidPos(x, y, z) ? game.Lighting.LightCol_ZSide(x, y, z) : game.Lighting.OutsideZSide; } if (BlockInfo.Tinted[block]) { FastColour fogCol = BlockInfo.FogColour[block]; FastColour newCol = FastColour.Unpack(col); newCol *= fogCol; col = newCol.Pack(); } DoRender(game, ref terrainSize, ref pos, ref rec, col, vertices, ref index); }
public override void Render(Game game, double delta, float t, VertexP3fT2fC4b[] vertices, ref int index) { Position = Vector3.Lerp(lastPos, nextPos, t); int col = FastColour.WhitePacked; if (!game.BlockInfo.FullBright[block]) { Vector3I P = Vector3I.Floor(Position); col = game.World.IsValidPos(P) ? game.Lighting.LightCol_ZSide(P.X, P.Y, P.Z) : game.Lighting.OutsideZSide; } if (game.BlockInfo.Tinted[block]) { FastColour fogCol = game.BlockInfo.FogColour[block]; FastColour newCol = FastColour.Unpack(col); newCol *= fogCol; col = newCol.Pack(); } DoRender(game, ref terrainSize, ref rec, col, vertices, ref index); }
public void Render(double deltaTime) { Weather weather = map.Env.Weather; if (weather == Weather.Sunny) { return; } if (heightmap == null) { InitHeightmap(); } IGraphicsApi gfx = game.Graphics; gfx.BindTexture(weather == Weather.Rainy ? RainTexId : SnowTexId); Vector3 camPos = game.CurrentCameraPos; Vector3I pos = Vector3I.Floor(camPos); bool moved = pos != lastPos; lastPos = pos; WorldEnv env = game.World.Env; float speed = (weather == Weather.Rainy ? 1.0f : 0.2f) * env.WeatherSpeed; float vOffset = (float)game.accumulator * speed; rainAcc += deltaTime; bool particles = weather == Weather.Rainy; int vCount = 0; FastColour col = game.World.Env.Sunlight; VertexP3fT2fC4b v = default(VertexP3fT2fC4b); for (int dx = -extent; dx <= extent; dx++) { for (int dz = -extent; dz <= extent; dz++) { int x = pos.X + dx, z = pos.Z + dz; float y = RainHeight(x, z); float height = Math.Max(game.World.Height, pos.Y + 64) - y; if (height <= 0) { continue; } if (particles && (rainAcc >= 0.25 || moved)) { game.ParticleManager.AddRainParticle(new Vector3(x, y, z)); } float alpha = AlphaAt(dx * dx + dz * dz); Utils.Clamp(ref alpha, 0, 0xFF); col.A = (byte)alpha; // NOTE: Making vertex is inlined since this is called millions of times. v.Colour = col.Pack(); float worldV = vOffset + (z & 1) / 2f - (x & 0x0F) / 16f; float v1 = y / 6f + worldV, v2 = (y + height) / 6f + worldV; float x1 = x, y1 = y, z1 = z; float x2 = x + 1, y2 = y + height, z2 = z + 1; v.X = x1; v.Y = y1; v.Z = z1; v.U = 0; v.V = v1; vertices[vCount++] = v; v.Y = y2; v.V = v2; vertices[vCount++] = v; v.X = x2; v.Z = z2; v.U = 1; vertices[vCount++] = v; v.Y = y1; v.V = v1; vertices[vCount++] = v; v.Z = z1; vertices[vCount++] = v; v.Y = y2; v.V = v2; vertices[vCount++] = v; v.X = x1; v.Z = z2; v.U = 0; vertices[vCount++] = v; v.Y = y1; v.V = v1; vertices[vCount++] = v; } } if (particles && (rainAcc >= 0.25 || moved)) { rainAcc = 0; } if (vCount == 0) { return; } gfx.AlphaTest = false; gfx.DepthWrite = false; gfx.AlphaArgBlend = true; gfx.SetBatchFormat(VertexFormat.P3fT2fC4b); gfx.UpdateDynamicVb_IndexedTris(vb, vertices, vCount); gfx.AlphaArgBlend = false; gfx.AlphaTest = true; gfx.DepthWrite = true; }
public override void BlendColour(FastColour col) { int col2 = col.Pack(); device.SetRenderState(RenderState.BlendFactor, col2); }
public override void ClearColour(FastColour col) { lastClearCol = col.Pack(); }
void SetLightmap(int x, int y, FastColour col) { lightmap[x * 16 + y] = col.Pack(); FastColour.GetShaded(col, out lightmapXSide[x * 16 + y], out lightmapZSide[x * 16 + y], out lightmapYBottom[x * 16 + y]); }
void SetShadow(FastColour col) { shadow = col.Pack(); FastColour.GetShaded(col, out shadowXSide, out shadowZSide, out shadowYBottom); }
void SetSun(FastColour col) { Outside = col.Pack(); FastColour.GetShaded(col, out OutsideXSide, out OutsideZSide, out OutsideYBottom); }