From 40b5d71bfe4af0133ccc0d06b0a402d926b6046c Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 10 Dec 2020 16:02:13 -0800 Subject: [PATCH] trying to do tiled draws --- Data/MeshPartDrawData.cs | 35 ++++++++++ Data/MeshSpriteDrawData.cs | 10 +-- Data/UVData.cs | 5 ++ Effects/DeferredPBR_GBufferEffect.cs | 42 +++--------- Effects/DiffuseLitSpriteEffect.cs | 30 +++------ Effects/EffectHelpers.cs | 2 +- Effects/FXB/DeferredPBR_GBufferEffect.fxb | 4 +- Effects/HLSL/DeferredPBR_GBufferEffect.fx | 63 ++++++++---------- Geometry/Interfaces/ICullable.cs | 1 + Geometry/Interfaces/IGBufferDrawable.cs | 4 +- Geometry/Interfaces/IUVDrawable.cs | 9 +++ Geometry/MeshPart.cs | 5 +- Geometry/MeshSprite.cs | 2 +- Geometry/Model.cs | 2 +- Renderer.cs | 65 +++++++------------ VertexDeclarations.cs | 2 +- .../PositionTextureOffsetInstanceVertex.cs | 6 +- 17 files changed, 134 insertions(+), 153 deletions(-) create mode 100644 Data/MeshPartDrawData.cs create mode 100644 Geometry/Interfaces/IUVDrawable.cs diff --git a/Data/MeshPartDrawData.cs b/Data/MeshPartDrawData.cs new file mode 100644 index 0000000..dc6b25a --- /dev/null +++ b/Data/MeshPartDrawData.cs @@ -0,0 +1,35 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Kav.Data +{ + public struct MeshPartDrawData : IGBufferDrawable, IUVDrawable, ICullable, IIndexDrawable + { + public MeshPart MeshPart { get; } + public Matrix TransformMatrix { get; } + public UVData UVData { get; } + + public BoundingBox BoundingBox => MeshPart.BoundingBox; + + public IndexBuffer IndexBuffer => MeshPart.IndexBuffer; + public VertexBuffer VertexBuffer => MeshPart.VertexBuffer; + + public Vector3 Albedo => MeshPart.Albedo; + public float Metallic => MeshPart.Metallic; + public float Roughness => MeshPart.Roughness; + + public Texture2D AlbedoTexture => MeshPart.AlbedoTexture; + public Texture2D NormalTexture => MeshPart.NormalTexture; + public Texture2D MetallicRoughnessTexture => MeshPart.MetallicRoughnessTexture; + + public MeshPartDrawData( + MeshPart meshPart, + Matrix transformMatrix, + UVData uvData + ) { + MeshPart = meshPart; + TransformMatrix = transformMatrix; + UVData = uvData; + } + } +} diff --git a/Data/MeshSpriteDrawData.cs b/Data/MeshSpriteDrawData.cs index 8d064bb..cbbc330 100644 --- a/Data/MeshSpriteDrawData.cs +++ b/Data/MeshSpriteDrawData.cs @@ -2,23 +2,25 @@ using Microsoft.Xna.Framework; namespace Kav.Data { - public struct MeshSpriteDrawData + public struct MeshSpriteDrawData : ICullable { public MeshSprite MeshSprite { get; } public SpriteBillboardConstraint BillboardConstraint { get; } public Matrix TransformMatrix { get; } - public UVData UVOffset { get; } + public UVData UVData { get; } + + public BoundingBox BoundingBox => MeshSprite.BoundingBox; public MeshSpriteDrawData( MeshSprite meshSprite, SpriteBillboardConstraint billboardConstraint, Matrix transformMatrix, - UVData offset + UVData uvData ) { MeshSprite = meshSprite; BillboardConstraint = billboardConstraint; TransformMatrix = transformMatrix; - UVOffset = offset; + UVData = uvData; } } } diff --git a/Data/UVData.cs b/Data/UVData.cs index 0295804..fd6590c 100644 --- a/Data/UVData.cs +++ b/Data/UVData.cs @@ -15,5 +15,10 @@ namespace Kav.Data Percentage = subTextureDimensions / atlasDimensions; Offset = positionInAtlas / atlasDimensions; } + + public Vector4 ToVector4() + { + return new Vector4(Offset.X, Offset.Y, Percentage.X, Percentage.Y); + } } } diff --git a/Effects/DeferredPBR_GBufferEffect.cs b/Effects/DeferredPBR_GBufferEffect.cs index be3e3ff..e43250d 100644 --- a/Effects/DeferredPBR_GBufferEffect.cs +++ b/Effects/DeferredPBR_GBufferEffect.cs @@ -12,14 +12,12 @@ namespace Kav EffectParameter normalTextureParam; EffectParameter metallicRoughnessTextureParam; + EffectParameter uvOffsetAndDimensionsParam; + EffectParameter albedoParam; EffectParameter metallicParam; EffectParameter roughnessParam; - EffectParameter numTextureRowsParam; - EffectParameter numTextureColumnsParam; - - EffectParameter vertexShaderIndexParam; EffectParameter shaderIndexParam; Matrix world = Matrix.Identity; @@ -30,8 +28,7 @@ namespace Kav float metallic; float roughness; - int numTextureRows = 1; - int numTextureColumns = 1; + Vector4 uvData; bool albedoTextureEnabled = false; bool metallicRoughnessMapEnabled = false; @@ -133,24 +130,15 @@ namespace Kav } } - public int NumTextureRows + public Vector4 UVData { - get { return numTextureRows; } + get { return uvData; } set { - numTextureRows = value; - numTextureRowsParam.SetValue(numTextureRows); + uvData = value; + uvOffsetAndDimensionsParam.SetValue(uvData); } - } - public int NumTextureColumns - { - get { return numTextureColumns; } - set - { - numTextureColumns = value; - numTextureColumnsParam.SetValue(numTextureColumns); - } } public bool HardwareInstancingEnabled @@ -210,18 +198,6 @@ namespace Kav dirtyFlags &= ~EffectDirtyFlags.ViewProj; } - if ((dirtyFlags & EffectDirtyFlags.VertexShaderIndex) != 0) - { - int vertexShaderIndex = 0; - - if (hardwareInstancingEnabled) - { - vertexShaderIndex = 1; - } - - vertexShaderIndexParam.SetValue(vertexShaderIndex); - } - if ((dirtyFlags & EffectDirtyFlags.PixelShaderIndex) != 0) { int shaderIndex = 0; @@ -274,11 +250,9 @@ namespace Kav metallicParam = Parameters["MetallicValue"]; roughnessParam = Parameters["RoughnessValue"]; - numTextureRowsParam = Parameters["NumTextureRows"]; - numTextureColumnsParam = Parameters["NumTextureColumns"]; + uvOffsetAndDimensionsParam = Parameters["UVOffsetAndDimensions"]; shaderIndexParam = Parameters["PixelShaderIndex"]; - vertexShaderIndexParam = Parameters["VertexShaderIndex"]; } } } diff --git a/Effects/DiffuseLitSpriteEffect.cs b/Effects/DiffuseLitSpriteEffect.cs index 0b7ea57..0d234d3 100644 --- a/Effects/DiffuseLitSpriteEffect.cs +++ b/Effects/DiffuseLitSpriteEffect.cs @@ -33,8 +33,7 @@ namespace Kav Matrix view = Matrix.Identity; Matrix projection = Matrix.Identity; - Vector2 uvOffset; - Vector2 subTextureDimensions; + Vector4 uvData; EffectDirtyFlags dirtyFlags = EffectDirtyFlags.All; @@ -115,23 +114,13 @@ namespace Kav } } - public Vector2 UVOffset + public Vector4 UVData { - get { return uvOffset; } + get { return uvData; } set { - uvOffset = value; - dirtyFlags |= EffectDirtyFlags.UVOrDimensions; - } - } - - public Vector2 SubTextureDimensions - { - get { return subTextureDimensions; } - set - { - subTextureDimensions = value; - dirtyFlags |= EffectDirtyFlags.UVOrDimensions; + uvData = value; + dirtyFlags |= EffectDirtyFlags.UVData; } } @@ -168,14 +157,11 @@ namespace Kav dirtyFlags &= ~EffectDirtyFlags.WorldViewProj; } - if ((dirtyFlags & EffectDirtyFlags.UVOrDimensions) != 0) + if ((dirtyFlags & EffectDirtyFlags.UVData) != 0) { - uvOffsetAndDimensionsParam.SetValue(new Vector4( - UVOffset.X, UVOffset.Y, - SubTextureDimensions.X, SubTextureDimensions.Y - )); + uvOffsetAndDimensionsParam.SetValue(uvData); - dirtyFlags &= ~EffectDirtyFlags.UVOrDimensions; + dirtyFlags &= ~EffectDirtyFlags.UVData; } if ((dirtyFlags & EffectDirtyFlags.PixelShaderIndex) != 0) diff --git a/Effects/EffectHelpers.cs b/Effects/EffectHelpers.cs index 8705b63..ec44f9b 100644 --- a/Effects/EffectHelpers.cs +++ b/Effects/EffectHelpers.cs @@ -11,7 +11,7 @@ namespace Kav VertexShaderIndex = 8, PixelShaderIndex = 16, ViewProj = 32, - UVOrDimensions = 64, + UVData = 64, All = -1 } } diff --git a/Effects/FXB/DeferredPBR_GBufferEffect.fxb b/Effects/FXB/DeferredPBR_GBufferEffect.fxb index 0f379e6..f4ccd35 100644 --- a/Effects/FXB/DeferredPBR_GBufferEffect.fxb +++ b/Effects/FXB/DeferredPBR_GBufferEffect.fxb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ebcbca875c8ce99a59a733d9bf45f35126b22dbee7e2a6378c91088fce2181dc -size 9232 +oid sha256:1f3c33d2078e98d878258f706a84ed668ff9ecba3892e3f8f959b4a91e977692 +size 9636 diff --git a/Effects/HLSL/DeferredPBR_GBufferEffect.fx b/Effects/HLSL/DeferredPBR_GBufferEffect.fx index b73b617..0a982e1 100644 --- a/Effects/HLSL/DeferredPBR_GBufferEffect.fx +++ b/Effects/HLSL/DeferredPBR_GBufferEffect.fx @@ -4,29 +4,31 @@ DECLARE_TEXTURE(AlbedoTexture, 0); DECLARE_TEXTURE(NormalTexture, 1); DECLARE_TEXTURE(MetallicRoughnessTexture, 2); -BEGIN_CONSTANTS +float3 AlbedoValue; +float MetallicValue; +float RoughnessValue; - float3 AlbedoValue _ps(c0) _cb(c0); - float MetallicValue _ps(c1) _cb(c1); - float RoughnessValue _ps(c2) _cb(c2); +float4 UVOffsetAndDimensions; - int NumTextureRows _vs(c9) _cb(c3); - int NumTextureColumns _vs(c10) _cb(c4); - -MATRIX_CONSTANTS - - float4x4 World _vs(c0) _cb(c7); - float4x4 ViewProjection _vs(c4) _cb(c11); - -END_CONSTANTS +float4x4 World; +float4x4 ViewProjection; struct VertexInput { - float4 Position : POSITION; + float3 Position : POSITION; float3 Normal : NORMAL; float2 TexCoord : TEXCOORD; }; +struct VertexInstancedInput +{ + float3 Position : POSITION; + float3 Normal : NORMAL; + float2 TexCoord : TEXCOORD0; + float3 Translation : TEXCOORD2; + float2 UVData : TANGENT; +}; + struct PixelInput { float4 Position : SV_POSITION; @@ -51,7 +53,11 @@ PixelInput main_vs(VertexInput input) output.PositionWorld = mul(input.Position, World).xyz; output.NormalWorld = normalize(mul(input.Normal, World)); - output.TexCoord = input.TexCoord; + + float2 texCoord; + texCoord.x = (input.TexCoord.x / UVOffsetAndDimensions.z) + UVOffsetAndDimensions.x; + texCoord.y = (input.TexCoord.y / UVOffsetAndDimensions.w) + UVOffsetAndDimensions.y; + output.TexCoord = texCoord; float4x4 worldViewProjection = mul(World, ViewProjection); output.Position = mul(input.Position, worldViewProjection); @@ -60,9 +66,7 @@ PixelInput main_vs(VertexInput input) } PixelInput instanced_vs( - VertexInput input, - float3 Translation : TEXCOORD2, - float2 UVOffset : TEXCOORD5 + VertexInstancedInput input ) { PixelInput output; @@ -70,7 +74,7 @@ PixelInput instanced_vs( float4(1, 0, 0, 0), float4(0, 1, 0, 0), float4(0, 0, 1, 0), - float4(Translation.x, Translation.y, Translation.z, 1) + float4(input.Translation.x, input.Translation.y, input.Translation.z, 1) ); float4x4 worldViewProjection = mul(world, ViewProjection); @@ -79,9 +83,9 @@ PixelInput instanced_vs( output.NormalWorld = mul(input.Normal, world); float2 texCoord; - texCoord.x = (input.TexCoord.x / NumTextureColumns + UVOffset.x); - texCoord.y = (input.TexCoord.y / NumTextureRows + UVOffset.y); - output.TexCoord = texCoord; + texCoord.x = (input.TexCoord.x / 8) + input.UVData.x; + texCoord.y = (input.TexCoord.y / 1) + input.UVData.y; + output.TexCoord = input.TexCoord; output.Position = mul(input.Position, worldViewProjection); @@ -204,19 +208,6 @@ PixelOutput AlbedoMetallicRoughnessNormalMapPS(PixelInput input) return output; } -VertexShader VSArray[2] = -{ - compile vs_3_0 main_vs(), - compile vs_3_0 instanced_vs() -}; - -int VSIndices[2] = -{ - 0, 1 -}; - -int VertexShaderIndex = 0; - PixelShader PSArray[8] = { compile ps_3_0 NonePS(), @@ -243,7 +234,7 @@ Technique GBuffer { Pass { - VertexShader = (VSArray[VSIndices[VertexShaderIndex]]); + VertexShader = compile vs_3_0 instanced_vs(); PixelShader = (PSArray[PSIndices[PixelShaderIndex]]); } } diff --git a/Geometry/Interfaces/ICullable.cs b/Geometry/Interfaces/ICullable.cs index 831fc83..a70c1f4 100644 --- a/Geometry/Interfaces/ICullable.cs +++ b/Geometry/Interfaces/ICullable.cs @@ -5,5 +5,6 @@ namespace Kav public interface ICullable { BoundingBox BoundingBox { get; } + Matrix TransformMatrix { get; } } } diff --git a/Geometry/Interfaces/IGBufferDrawable.cs b/Geometry/Interfaces/IGBufferDrawable.cs index d6fcae9..76a118c 100644 --- a/Geometry/Interfaces/IGBufferDrawable.cs +++ b/Geometry/Interfaces/IGBufferDrawable.cs @@ -1,3 +1,4 @@ +using Kav.Data; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -12,8 +13,5 @@ namespace Kav Texture2D AlbedoTexture { get; } Texture2D NormalTexture { get; } Texture2D MetallicRoughnessTexture { get; } - - int NumTextureRows { get; } - int NumTextureColumns { get; } } } diff --git a/Geometry/Interfaces/IUVDrawable.cs b/Geometry/Interfaces/IUVDrawable.cs new file mode 100644 index 0000000..d1fe14a --- /dev/null +++ b/Geometry/Interfaces/IUVDrawable.cs @@ -0,0 +1,9 @@ +using Kav.Data; + +namespace Kav +{ + public interface IUVDrawable + { + UVData UVData { get; } + } +} diff --git a/Geometry/MeshPart.cs b/Geometry/MeshPart.cs index a5a6a70..e5d8b44 100644 --- a/Geometry/MeshPart.cs +++ b/Geometry/MeshPart.cs @@ -3,7 +3,7 @@ using Microsoft.Xna.Framework.Graphics; namespace Kav { - public class MeshPart : IIndexDrawable, IGBufferDrawable, ICullable, IHasVertexPositions + public class MeshPart : IIndexDrawable, IGBufferDrawable, IHasVertexPositions { public IndexBuffer IndexBuffer { get; } public VertexBuffer VertexBuffer { get; } @@ -38,9 +38,6 @@ namespace Kav public float Metallic { get; set; } = 0.5f; public float Roughness { get; set; } = 0.5f; - public int NumTextureRows { get; set; } = 1; - public int NumTextureColumns { get; set; } = 1; - public bool DisableAlbedoMap { get; set; } = false; public bool DisableNormalMap { get; set; } = false; public bool DisableMetallicRoughnessMap { get; set; } = false; diff --git a/Geometry/MeshSprite.cs b/Geometry/MeshSprite.cs index c7fd105..9688f05 100644 --- a/Geometry/MeshSprite.cs +++ b/Geometry/MeshSprite.cs @@ -4,7 +4,7 @@ using Microsoft.Xna.Framework.Graphics; namespace Kav { - public class MeshSprite : ICullable, IIndexDrawable + public class MeshSprite : IIndexDrawable { public enum FlipOptions { diff --git a/Geometry/Model.cs b/Geometry/Model.cs index 3acbb44..5b913f5 100644 --- a/Geometry/Model.cs +++ b/Geometry/Model.cs @@ -2,7 +2,7 @@ using Microsoft.Xna.Framework; namespace Kav { - public class Model : ICullable + public class Model { public Mesh[] Meshes { get; } public BoundingBox BoundingBox { get; } diff --git a/Renderer.cs b/Renderer.cs index 2b4f8ae..d9441ec 100644 --- a/Renderer.cs +++ b/Renderer.cs @@ -159,20 +159,14 @@ namespace Kav var boundingFrustum = new BoundingFrustum(camera.View * camera.Projection); - foreach (var data in meshSpriteDrawDatas) + foreach (var data in FrustumCull(boundingFrustum, meshSpriteDrawDatas)) { var matrix = BillboardTransforms(camera, data.TransformMatrix, data.BillboardConstraint); - if (FrustumCull(boundingFrustum, data.MeshSprite, matrix)) - { - continue; - } - DiffuseLitSpriteEffect.NormalMapEnabled = data.MeshSprite.Normal != null; DiffuseLitSpriteEffect.World = matrix; - DiffuseLitSpriteEffect.UVOffset = data.UVOffset.Offset; - DiffuseLitSpriteEffect.SubTextureDimensions = data.UVOffset.Percentage; + DiffuseLitSpriteEffect.UVData = data.UVData.ToVector4(); GraphicsDevice.Textures[0] = data.MeshSprite.Texture; GraphicsDevice.Textures[1] = data.MeshSprite.Normal; @@ -232,13 +226,13 @@ namespace Kav public static void CullAndRenderIndexed( GraphicsDevice graphicsDevice, BoundingFrustum boundingFrustum, - IEnumerable<(T, Matrix)> drawableTransformPairs, + IEnumerable drawables, U effect ) where T : IIndexDrawable, ICullable where U : Effect, IHasWorldMatrix { - foreach (var (drawable, transform) in FrustumCull(boundingFrustum, drawableTransformPairs)) + foreach (var drawable in FrustumCull(boundingFrustum, drawables)) { - effect.World = transform; + effect.World = drawable.TransformMatrix; RenderIndexed( graphicsDevice, @@ -316,7 +310,7 @@ namespace Kav public void RenderDepthIndexed( RenderTarget2D renderTarget, PerspectiveCamera camera, - IEnumerable<(T, Matrix)> drawableTransforms + IEnumerable drawables ) where T : ICullable, IIndexDrawable { GraphicsDevice.SetRenderTarget(renderTarget); @@ -328,7 +322,7 @@ namespace Kav CullAndRenderIndexed( GraphicsDevice, new BoundingFrustum(camera.View * camera.Projection), - drawableTransforms, + drawables, SimpleDepthEffect ); } @@ -381,9 +375,6 @@ namespace Kav Deferred_GBufferEffect.Metallic = drawable.Metallic; Deferred_GBufferEffect.Roughness = drawable.Roughness; - Deferred_GBufferEffect.NumTextureRows = drawable.NumTextureRows; - Deferred_GBufferEffect.NumTextureColumns = drawable.NumTextureColumns; - Deferred_GBufferEffect.AlbedoTexture = drawable.AlbedoTexture; Deferred_GBufferEffect.NormalTexture = drawable.NormalTexture; Deferred_GBufferEffect.MetallicRoughnessTexture = drawable.MetallicRoughnessTexture; @@ -417,8 +408,8 @@ namespace Kav public void RenderGBufferIndexed( RenderTargetBinding[] gBuffer, PerspectiveCamera camera, - IEnumerable<(T, Matrix)> drawableTransforms - ) where T : ICullable, IIndexDrawable, IGBufferDrawable { + IEnumerable drawables + ) where T : ICullable, IIndexDrawable, IUVDrawable, IGBufferDrawable { GraphicsDevice.SetRenderTargets(gBuffer); GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.BlendState = BlendState.Opaque; @@ -429,9 +420,9 @@ namespace Kav var boundingFrustum = new BoundingFrustum(camera.View * camera.Projection); - foreach (var (drawable, transform) in FrustumCull(boundingFrustum, drawableTransforms)) + foreach (var drawable in FrustumCull(boundingFrustum, drawables)) { - Deferred_GBufferEffect.World = transform; + Deferred_GBufferEffect.World = drawable.TransformMatrix; Deferred_GBufferEffect.HardwareInstancingEnabled = false; @@ -439,6 +430,8 @@ namespace Kav Deferred_GBufferEffect.Metallic = drawable.Metallic; Deferred_GBufferEffect.Roughness = drawable.Roughness; + Deferred_GBufferEffect.UVData = drawable.UVData.ToVector4(); + Deferred_GBufferEffect.AlbedoTexture = drawable.AlbedoTexture; Deferred_GBufferEffect.NormalTexture = drawable.NormalTexture; Deferred_GBufferEffect.MetallicRoughnessTexture = drawable.MetallicRoughnessTexture; @@ -684,7 +677,7 @@ namespace Kav public void RenderDirectionalShadowsIndexed( DirectionalShadowMapData shadowMapData, - IEnumerable<(T, Matrix)> drawableTransforms + IEnumerable drawableTransforms ) where T : ICullable, IIndexDrawable { // render the individual shadow cascades for (var i = 0; i < shadowMapData.NumShadowCascades; i++) @@ -700,7 +693,7 @@ namespace Kav private void RenderDirectionalShadowMapIndexed( DirectionalShadowMapData shadowMapData, int shadowCascadeIndex, - IEnumerable<(T, Matrix)> drawableTransforms + IEnumerable drawables ) where T : ICullable, IIndexDrawable { GraphicsDevice.SetRenderTarget(shadowMapData.ShadowMaps[shadowCascadeIndex]); GraphicsDevice.DepthStencilState = DepthStencilState.Default; @@ -712,7 +705,7 @@ namespace Kav CullAndRenderIndexed( GraphicsDevice, new BoundingFrustum(SimpleDepthEffect.View * SimpleDepthEffect.Projection), - drawableTransforms, + drawables, SimpleDepthEffect ); } @@ -763,7 +756,7 @@ namespace Kav public void RenderPointShadowMapIndexed( RenderTargetCube pointShadowCubeMap, - IEnumerable<(T, Matrix)> modelTransforms, + IEnumerable drawables, PointLight pointLight ) where T : ICullable, IIndexDrawable { GraphicsDevice.DepthStencilState = DepthStencilState.Default; @@ -831,7 +824,7 @@ namespace Kav CullAndRenderIndexed( GraphicsDevice, new BoundingFrustum(LinearDepthEffect.View * LinearDepthEffect.Projection), - modelTransforms, + drawables, LinearDepthEffect ); } @@ -843,7 +836,7 @@ namespace Kav VertexBuffer instanceVertexBuffer, int numInstances, PointLight pointLight - ) where T : ICullable, IIndexDrawable + ) where T : IIndexDrawable { GraphicsDevice.DepthStencilState = DepthStencilState.Default; GraphicsDevice.BlendState = BlendState.Opaque; @@ -917,31 +910,21 @@ namespace Kav } } - private static IEnumerable<(T, Matrix)> FrustumCull( + private static IEnumerable FrustumCull( BoundingFrustum boundingFrustum, - IEnumerable<(T, Matrix)> cullableTransforms + IEnumerable cullables ) where T : ICullable { - foreach (var (cullable, transform) in cullableTransforms) + foreach (var cullable in cullables) { - var boundingBox = TransformedBoundingBox(cullable.BoundingBox, transform); + var boundingBox = TransformedBoundingBox(cullable.BoundingBox, cullable.TransformMatrix); var containment = boundingFrustum.Contains(boundingBox); if (containment != ContainmentType.Disjoint) { - yield return (cullable, transform); + yield return cullable; } } } - private static bool FrustumCull( - BoundingFrustum boundingFrustum, - T cullable, - Matrix transform - ) where T : ICullable { - var boundingBox = TransformedBoundingBox(cullable.BoundingBox, transform); - var containment = boundingFrustum.Contains(boundingBox); - return (containment == ContainmentType.Disjoint); - } - private static BoundingBox TransformedBoundingBox(BoundingBox boundingBox, Matrix matrix) { var center = (boundingBox.Min + boundingBox.Max) / 2f; diff --git a/VertexDeclarations.cs b/VertexDeclarations.cs index a7349e0..902b3ef 100644 --- a/VertexDeclarations.cs +++ b/VertexDeclarations.cs @@ -12,7 +12,7 @@ namespace Kav public static VertexDeclaration PositionTextureOffsetInstanceDeclaration = new VertexDeclaration ( new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.TextureCoordinate, 2), - new VertexElement(12, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 5) + new VertexElement(12, VertexElementFormat.Vector4, VertexElementUsage.Tangent, 0) ); } } diff --git a/Vertices/PositionTextureOffsetInstanceVertex.cs b/Vertices/PositionTextureOffsetInstanceVertex.cs index a4831fd..92585fd 100644 --- a/Vertices/PositionTextureOffsetInstanceVertex.cs +++ b/Vertices/PositionTextureOffsetInstanceVertex.cs @@ -16,16 +16,16 @@ namespace Kav } public Vector3 Translation { get; set; } - public Vector2 UVOffset { get; set; } + public Vector4 UVData { get; set; } public static readonly VertexDeclaration VertexDeclaration; public PositionTextureOffsetInstanceVertex( Vector3 translation, - Vector2 uvOffset + Vector4 uvData ) { Translation = translation; - UVOffset = uvOffset; + UVData = uvData; } } }