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 void Render(double deltaTime) { if (vb == -1) { return; } LastCelestialAngle = CelestialAngle; double x = ((game.Server.Ticks * 1) / 24000.0) - 0.25; if (x < 0) { x += 1; } CelestialAngle = x + ((1.0 - (Math.Cos(x * Math.PI) + 1.0) / 2.0) - x) / 3.0; game.Graphics.DepthWrite = false; game.Graphics.Texturing = true; game.Graphics.AlphaBlending = true; game.Graphics.DisableMipmaps(); game.Graphics.Fog = false; game.Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.One); game.Graphics.BindTexture(SunTex); game.Graphics.SetBatchFormat(VertexFormat.P3fT2fC4b); Matrix4 m = Matrix4.Identity, rotY, rotX; if (game.Server.DoDayNightCycle) { float skyMul = (float)(Math.Cos(CelestialAngle * (2 * Math.PI)) * 2 + 0.5); Utils.Clamp(ref skyMul, 0, 1); FastColour newSkyCol = FastColour.Lerp(nightSkyCol, WorldEnv.DefaultSkyColour, skyMul); if (newSkyCol != game.World.Env.SkyCol) { game.World.Env.SetSkyColour(newSkyCol); } FastColour newFogCol = FastColour.Lerp(nightFogCol, WorldEnv.DefaultFogColour, skyMul); if (newFogCol != game.World.Env.FogCol) { game.World.Env.SetFogColour(newFogCol); } FastColour newCloudCol = FastColour.Lerp(nightCloudCol, WorldEnv.DefaultCloudsColour, skyMul); if (newCloudCol != game.World.Env.CloudsCol) { game.World.Env.SetCloudsColour(newCloudCol); } byte SunLightSub = CalcSunLightSub(); if (SunLightSub != game.Lighting.sunLightSub) { game.Lighting.sunLightSub = SunLightSub; game.MapRenderer.Refresh(); //game.MapBordersRenderer.ResetEdges(); } } // Base skybox rotation float rotTime = (float)(game.accumulator * 2 * Math.PI); // So speed of 1 rotates whole skybox every second WorldEnv env = game.World.Env; //Matrix4.RotateY(out rotY, env.SkyboxHorSpeed * rotTime); //Matrix4.Mult(out m, ref m, ref rotY); Matrix4.RotateX(out rotX, (float)(360d * CelestialAngle) * Utils.Deg2Rad + 90f * Utils.Deg2Rad); Matrix4.Mult(out m, ref m, ref rotX); // Rotate around camera Vector2 rotation = game.Camera.GetCameraOrientation(); Matrix4.RotateY(out rotY, rotation.X); // Camera yaw Matrix4.Mult(out m, ref m, ref rotY); Matrix4.RotateX(out rotX, rotation.Y); // Cammera pitch Matrix4.Mult(out m, ref m, ref rotX); Matrix4.Mult(out m, ref m, ref game.Camera.tiltM); game.Graphics.LoadMatrix(ref m); game.Graphics.BindVb(vb); game.Graphics.DrawVb_IndexedTris(sunCount); game.Graphics.BindTexture(MoonTex); m = Matrix4.Identity; Matrix4.RotateX(out rotX, (float)(360d * CelestialAngle) * Utils.Deg2Rad + 90f * Utils.Deg2Rad); Matrix4.Mult(out m, ref m, ref rotX); // Rotate around camera rotation = game.Camera.GetCameraOrientation(); Matrix4.RotateY(out rotY, rotation.X); // Camera yaw Matrix4.Mult(out m, ref m, ref rotY); Matrix4.RotateX(out rotX, rotation.Y); // Cammera pitch Matrix4.Mult(out m, ref m, ref rotX); Matrix4.Mult(out m, ref m, ref game.Camera.tiltM); game.Graphics.LoadMatrix(ref m); game.Graphics.BindVb(vb); game.Graphics.DrawVb_IndexedTris(moonCount, sunCount); /*game.Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha); * //game.Graphics.AlphaBlending = false; * * game.Graphics.BindTexture(0); * * m = Matrix4.Identity; * Matrix4.RotateX(out rotX, (float)(360d * CelestialAngle) * Utils.Deg2Rad + 90f * Utils.Deg2Rad); * Matrix4.Mult(out m, ref m, ref rotX); * * * // Rotate around camera * rotation = game.Camera.GetCameraOrientation(); * Matrix4.RotateY(out rotY, rotation.X); // Camera yaw * Matrix4.Mult(out m, ref m, ref rotY); * Matrix4.RotateX(out rotX, rotation.Y); // Cammera pitch * Matrix4.Mult(out m, ref m, ref rotX); * Matrix4.Mult(out m, ref m, ref game.Camera.tiltM); * * game.Graphics.LoadMatrix(ref m); * game.Graphics.BindVb(vb); * game.Graphics.DrawVb_IndexedTris(starCount, (sunCount + moonCount));*/ game.Graphics.Fog = true; game.Graphics.AlphaBlendFunc(BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha); game.Graphics.AlphaBlending = false; game.Graphics.Texturing = false; game.Graphics.LoadMatrix(ref game.Graphics.View); game.Graphics.DepthWrite = true; }
public World( Game game ) { Env = new WorldEnv( game ); this.game = game; info = game.BlockInfo; }
public void OnNewMapLoaded() { map = game.World; env = game.World.Env; width = map.Width; height = map.Height; length = map.Length; clipLevel = Math.Max( 0, game.World.Env.SidesHeight ); maxX = width - 1; maxY = height - 1; maxZ = length - 1; }