diff --git a/Effects/FXB/DiffuseLitSpriteEffect.fxb b/Effects/FXB/DiffuseLitSpriteEffect.fxb index 73db0a9..4516be8 100644 --- a/Effects/FXB/DiffuseLitSpriteEffect.fxb +++ b/Effects/FXB/DiffuseLitSpriteEffect.fxb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e08585959eff5d0cfa7ec9f5ebd5390281626b535f9170ae11b7f899b4053f2e -size 7124 +oid sha256:ad16b1f9036e4c65e4615d3c71cb099bbe2dee346cefef61fc067e6111d3a7b5 +size 7168 diff --git a/Effects/HLSL/DiffuseLitSpriteEffect.fx b/Effects/HLSL/DiffuseLitSpriteEffect.fx index c6e18a9..ca5e7d2 100644 --- a/Effects/HLSL/DiffuseLitSpriteEffect.fx +++ b/Effects/HLSL/DiffuseLitSpriteEffect.fx @@ -44,7 +44,7 @@ PixelShaderInput main_vs(VertexShaderInput input) output.Position = mul(input.Position, WorldViewProjection); output.TexCoord = input.TexCoord; - output.NormalWS = mul(input.Normal, (float3x3)WorldInverseTranspose).xyz; + output.NormalWS = normalize(mul(input.Normal, (float3x3)WorldInverseTranspose)); output.PositionWS = mul(input.Position, World).xyz; return output; diff --git a/Effects/PointLightCollection.cs b/Effects/PointLightCollection.cs index 0ba2f48..4be9f5b 100644 --- a/Effects/PointLightCollection.cs +++ b/Effects/PointLightCollection.cs @@ -7,16 +7,14 @@ namespace Kav { private readonly Vector3[] positions; private readonly Vector3[] colors; - private readonly float[] intensities; readonly EffectParameter lightPositionsParam; readonly EffectParameter lightColorsParam; public PointLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam, int maxLights) { - this.positions = new Vector3[maxLights]; - this.colors = new Vector3[maxLights]; - this.intensities = new float[maxLights]; + positions = new Vector3[maxLights]; + colors = new Vector3[maxLights]; this.lightPositionsParam = lightPositionsParam; this.lightColorsParam = lightColorsParam; } diff --git a/Geometry/MeshSprite.cs b/Geometry/MeshSprite.cs index 33a673e..aab41d3 100644 --- a/Geometry/MeshSprite.cs +++ b/Geometry/MeshSprite.cs @@ -6,6 +6,14 @@ namespace Kav { public class MeshSprite : ICullable, IIndexDrawable { + public enum FlipOptions + { + None, + Horizontal, + Vertical, + Both + } + private static readonly int PixelScale = 40; private static readonly short[] Indices = new short[] { @@ -26,7 +34,8 @@ namespace Kav public MeshSprite( GraphicsDevice graphicsDevice, - Texture2D texture + Texture2D texture, + FlipOptions flipOptions ) { Texture = texture; Normal = null; @@ -39,7 +48,7 @@ namespace Kav ); IndexBuffer.SetData(Indices); - var vertexArray = GenerateVertexArray(Texture); + var vertexArray = GenerateVertexArray(Texture, flipOptions); VertexBuffer = new VertexBuffer( graphicsDevice, @@ -55,7 +64,8 @@ namespace Kav public MeshSprite( GraphicsDevice graphicsDevice, Texture2D texture, - Texture2D normal + Texture2D normal, + FlipOptions flipOptions ) { Texture = texture; Normal = normal; @@ -68,7 +78,7 @@ namespace Kav ); IndexBuffer.SetData(Indices); - var vertexArray = GenerateVertexArray(Texture); + var vertexArray = GenerateVertexArray(Texture, flipOptions); VertexBuffer = new VertexBuffer( graphicsDevice, @@ -81,25 +91,33 @@ namespace Kav BoundingBox = BoundingBox.CreateFromPoints(Positions(vertexArray)); } - private static VertexPositionNormalTexture[] GenerateVertexArray(Texture2D texture) + private static VertexPositionNormalTexture[] GenerateVertexArray(Texture2D texture, FlipOptions flipOptions) { VertexPositionNormalTexture[] result = new VertexPositionNormalTexture[4]; + var xLeft = 0; + var xRight = 1; + if (flipOptions == FlipOptions.Horizontal || flipOptions == FlipOptions.Both) + { + xLeft = 1; + xRight = 0; + } + result[0].Position = new Vector3(-texture.Width / 2, texture.Height / 2, 0) / PixelScale; result[0].Normal = new Vector3(0, 0, 1); - result[0].TextureCoordinate = new Vector2(0, 0); + result[0].TextureCoordinate = new Vector2(xLeft, 0); result[1].Position = new Vector3(texture.Width / 2, texture.Height / 2, 0) / PixelScale; result[1].Normal = new Vector3(0, 0, 1); - result[1].TextureCoordinate = new Vector2(1, 0); + result[1].TextureCoordinate = new Vector2(xRight, 0); result[2].Position = new Vector3(-texture.Width / 2, -texture.Height / 2, 0) / PixelScale; result[2].Normal = new Vector3(0, 0, 1); - result[2].TextureCoordinate = new Vector2(0, 1); + result[2].TextureCoordinate = new Vector2(xLeft, 1); result[3].Position = new Vector3(texture.Width / 2, -texture.Height / 2, 0) / PixelScale; result[3].Normal = new Vector3(0, 0, 1); - result[3].TextureCoordinate = new Vector2(1, 1); + result[3].TextureCoordinate = new Vector2(xRight, 1); return result; }