Add occlusion culling

This commit is contained in:
Jarrod Doyle 2024-07-22 19:52:40 +01:00
parent 76b95bcf67
commit 6dc6297b7b
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 17 additions and 2 deletions

View File

@ -18,3 +18,7 @@ config/icon="res://icon.svg"
[dotnet]
project/assembly_name="Thief Mission Viewer"
[rendering]
occlusion_culling/use_occlusion_culling=true

View File

@ -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);
}
}