abstract frustum culling
parent
fc09082f1b
commit
7f986c546a
|
@ -0,0 +1,9 @@
|
|||
using Microsoft.Xna.Framework;
|
||||
|
||||
namespace Kav
|
||||
{
|
||||
public interface ICullable
|
||||
{
|
||||
BoundingBox BoundingBox { get; }
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics;
|
|||
|
||||
namespace Kav
|
||||
{
|
||||
public class MeshSprite
|
||||
public class MeshSprite : ICullable
|
||||
{
|
||||
private static readonly int PixelScale = 40;
|
||||
private static readonly short[] Indices = new short[]
|
||||
|
|
|
@ -2,14 +2,14 @@ using Microsoft.Xna.Framework;
|
|||
|
||||
namespace Kav
|
||||
{
|
||||
public class Model
|
||||
public class Model : ICullable
|
||||
{
|
||||
public Mesh[] Meshes { get; }
|
||||
public BoundingBox BoundingBox { get; }
|
||||
|
||||
public Color Albedo
|
||||
{
|
||||
set
|
||||
public Color Albedo
|
||||
{
|
||||
set
|
||||
{
|
||||
foreach (var mesh in Meshes)
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ namespace Kav
|
|||
meshPart.Metallic = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float Roughness
|
||||
|
@ -46,7 +46,7 @@ namespace Kav
|
|||
meshPart.Roughness = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Model(Mesh[] meshes)
|
||||
|
@ -83,7 +83,7 @@ namespace Kav
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void DisableMetallicRoughnessMaps()
|
||||
{
|
||||
foreach (var mesh in Meshes)
|
||||
|
|
27
Renderer.cs
27
Renderer.cs
|
@ -836,32 +836,17 @@ namespace Kav
|
|||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<(Model, Matrix)> FrustumCull(
|
||||
private static IEnumerable<(T, Matrix)> FrustumCull<T>(
|
||||
BoundingFrustum boundingFrustum,
|
||||
IEnumerable<(Model, Matrix)> modelTransforms
|
||||
) {
|
||||
foreach (var modelTransform in modelTransforms)
|
||||
IEnumerable<(T, Matrix)> cullableTransforms
|
||||
) where T : ICullable {
|
||||
foreach (var (cullable, transform) in cullableTransforms)
|
||||
{
|
||||
var boundingBox = TransformedBoundingBox(modelTransform.Item1.BoundingBox, modelTransform.Item2);
|
||||
var boundingBox = TransformedBoundingBox(cullable.BoundingBox, transform);
|
||||
var containment = boundingFrustum.Contains(boundingBox);
|
||||
if (containment != ContainmentType.Disjoint)
|
||||
{
|
||||
yield return modelTransform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<(MeshSprite, Matrix)> FrustumCull(
|
||||
BoundingFrustum boundingFrustum,
|
||||
IEnumerable<(MeshSprite, Matrix)> meshSpriteTransforms
|
||||
) {
|
||||
foreach (var (meshSprite, transform) in meshSpriteTransforms)
|
||||
{
|
||||
var boundingBox = TransformedBoundingBox(meshSprite.BoundingBox, transform);
|
||||
var containment = boundingFrustum.Contains(boundingBox);
|
||||
if (containment != ContainmentType.Disjoint)
|
||||
{
|
||||
yield return (meshSprite, transform);
|
||||
yield return (cullable, transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue