From 6dc6297b7b85d390b4f51abdd9fe2aea034f7668 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 22 Jul 2024 19:52:40 +0100 Subject: [PATCH] Add occlusion culling --- project.godot | 4 ++++ project/code/Mission.cs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/project.godot b/project.godot index acd8310..564cf6a 100644 --- a/project.godot +++ b/project.godot @@ -18,3 +18,7 @@ config/icon="res://icon.svg" [dotnet] project/assembly_name="Thief Mission Viewer" + +[rendering] + +occlusion_culling/use_occlusion_culling=true diff --git a/project/code/Mission.cs b/project/code/Mission.cs index c3eb83b..e7fbd20 100644 --- a/project/code/Mission.cs +++ b/project/code/Mission.cs @@ -120,6 +120,8 @@ public partial class Mission : Node3D idxOffset += poly.VertexCount; } + var cellNode = new Node3D(); + var arrMesh = new ArrayMesh(); var arrays = new Godot.Collections.Array(); arrays.Resize((int)Mesh.ArrayType.Max); @@ -133,7 +135,14 @@ public partial class Mission : Node3D Mesh = arrMesh, CastShadow = GeometryInstance3D.ShadowCastingSetting.On }; - AddChild(meshInstance); + cellNode.AddChild(meshInstance); + + var occluderInstance = new OccluderInstance3D(); + var occluder = new ArrayOccluder3D(); + occluder.SetArrays(vertices.ToArray(), indices.ToArray()); + occluderInstance.Occluder = occluder; + cellNode.AddChild(occluderInstance); + var r = new Random(); if (r.NextSingle() > 0.9 && cell.SphereRadius > 5.0) @@ -143,7 +152,9 @@ public partial class Mission : Node3D Position = cell.SphereCenter.ToGodotVec3(4.0f), OmniRange = cell.SphereRadius * (r.NextSingle() + 1.0f) * 0.5f, }; - AddChild(light); + cellNode.AddChild(light); } + + AddChild(cellNode); } } \ No newline at end of file