Skip to content

Commit

Permalink
= Fix frusturum culling
Browse files Browse the repository at this point in the history
  • Loading branch information
tetreum committed Dec 11, 2024
1 parent 36edf3a commit 2b52a6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
11 changes: 4 additions & 7 deletions Assets/Scripts/World/ChunkSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,12 @@ public void CreateBoundsBox(Transform transform) {
}

public void FrustrumCulling() {
if (!Camera.main) {
return;
}
var visible = Vector3.Distance(bounds.center, Camera.main.transform.position) <= (10 * Chunk.SliceHeight);
visible = true;

float dot = Vector3.Dot((bounds.center - Camera.main.transform.position), Camera.main.transform.forward);

renderer.enabled = (Random.value < dot);
return;

if (visible) {
if (visible) {
Plane[] planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
visible = GeometryUtility.TestPlanesAABB(planes, bounds);
}
Expand Down
22 changes: 10 additions & 12 deletions Assets/Scripts/World/WorldBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,21 @@ public static ushort ChunkIndexFromCoords(int x, int z)
return (ushort)((x + 127) << 8 | (z + 127));
}

/*
void Update () {
void Update () {

foreach (Chunk chunk in ChunksMap) {
if (chunk == null) {
foreach (Chunk chunk in ChunksMap) {
if (chunk == null) {
continue;
}
foreach (ChunkSlice slice in chunk.Slices) {
if (slice.IsEmpty) {
continue;
}
foreach (ChunkSlice slice in chunk.Slices) {
if (slice.IsEmpty) {
continue;
}
slice.FrustrumCulling();
}
slice.FrustrumCulling();
}
}
*/

}
void FixedUpdate()
{
++accumulator;
Expand Down

0 comments on commit 2b52a6b

Please sign in to comment.