feat(rendering): frustum-cull chunk draws and log render counts
This commit is contained in:
29
Core/Game.cs
29
Core/Game.cs
@@ -29,6 +29,7 @@ public sealed class Game : GameWindow
|
||||
private WorldGenerator _generator = null!;
|
||||
private ChunkStreamer _streamer = null!;
|
||||
private Player _player = null!;
|
||||
private double _logAccumSeconds;
|
||||
|
||||
public Game(Configuration cfg, GameWindowSettings gameSettings, NativeWindowSettings nativeSettings)
|
||||
: base(gameSettings, nativeSettings)
|
||||
@@ -127,12 +128,30 @@ public sealed class Game : GameWindow
|
||||
this._shader.SetVector3("u_skyColor", this._cfg.SkyColor);
|
||||
this._texture.Use(TextureUnit.Texture0);
|
||||
|
||||
this._streamer.DrawAll((pos, renderer) =>
|
||||
Matrix4 viewProj = this._player.Camera.GetViewMatrix() * this._player.Camera.GetProjectionMatrix();
|
||||
Frustum frustum = Frustum.FromViewProjection(viewProj);
|
||||
|
||||
int drawn = this._streamer.DrawVisible(
|
||||
pos =>
|
||||
{
|
||||
Vector3 min = new(pos.X * Chunk.Size, pos.Y * Chunk.Size, pos.Z * Chunk.Size);
|
||||
Vector3 max = min + new Vector3(Chunk.Size);
|
||||
return frustum.Intersects(min, max);
|
||||
},
|
||||
(pos, renderer) =>
|
||||
{
|
||||
this._shader.SetMatrix4("model", Matrix4.CreateTranslation(
|
||||
pos.X * Chunk.Size, pos.Y * Chunk.Size, pos.Z * Chunk.Size));
|
||||
renderer.Draw();
|
||||
});
|
||||
|
||||
this._logAccumSeconds += args.Time;
|
||||
if (this._logAccumSeconds >= 1.0)
|
||||
{
|
||||
this._shader.SetMatrix4("model", Matrix4.CreateTranslation(
|
||||
pos.X * Chunk.Size, pos.Y * Chunk.Size, pos.Z * Chunk.Size));
|
||||
renderer.Draw();
|
||||
});
|
||||
this._logAccumSeconds = 0;
|
||||
Log.Information("Rendered {Drawn} / {Renderers} chunks ({Tracked} loaded)",
|
||||
drawn, this._streamer.RendererCount, this._streamer.TrackedCount);
|
||||
}
|
||||
|
||||
this.SwapBuffers();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user