allow sprite flipping on meshsprite
							parent
							
								
									7964d8a171
								
							
						
					
					
						commit
						2f589e584d
					
				
							
								
								
									
										
											BIN
										
									
								
								Effects/FXB/DiffuseLitSpriteEffect.fxb (Stored with Git LFS)
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								Effects/FXB/DiffuseLitSpriteEffect.fxb (Stored with Git LFS)
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -44,7 +44,7 @@ PixelShaderInput main_vs(VertexShaderInput input) | ||||||
| 
 | 
 | ||||||
|     output.Position = mul(input.Position, WorldViewProjection); |     output.Position = mul(input.Position, WorldViewProjection); | ||||||
|     output.TexCoord = input.TexCoord; |     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; |     output.PositionWS = mul(input.Position, World).xyz; | ||||||
| 
 | 
 | ||||||
|     return output; |     return output; | ||||||
|  |  | ||||||
|  | @ -7,16 +7,14 @@ namespace Kav | ||||||
|     { |     { | ||||||
|         private readonly Vector3[] positions; |         private readonly Vector3[] positions; | ||||||
|         private readonly Vector3[] colors; |         private readonly Vector3[] colors; | ||||||
|         private readonly float[] intensities; |  | ||||||
| 
 | 
 | ||||||
|         readonly EffectParameter lightPositionsParam; |         readonly EffectParameter lightPositionsParam; | ||||||
|         readonly EffectParameter lightColorsParam; |         readonly EffectParameter lightColorsParam; | ||||||
| 
 | 
 | ||||||
|         public PointLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam, int maxLights) |         public PointLightCollection(EffectParameter lightPositionsParam, EffectParameter lightColorsParam, int maxLights) | ||||||
|         { |         { | ||||||
|             this.positions = new Vector3[maxLights]; |             positions = new Vector3[maxLights]; | ||||||
|             this.colors = new Vector3[maxLights]; |             colors = new Vector3[maxLights]; | ||||||
|             this.intensities = new float[maxLights]; |  | ||||||
|             this.lightPositionsParam = lightPositionsParam; |             this.lightPositionsParam = lightPositionsParam; | ||||||
|             this.lightColorsParam = lightColorsParam; |             this.lightColorsParam = lightColorsParam; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -6,6 +6,14 @@ namespace Kav | ||||||
| { | { | ||||||
|     public class MeshSprite : ICullable, IIndexDrawable |     public class MeshSprite : ICullable, IIndexDrawable | ||||||
|     { |     { | ||||||
|  |         public enum FlipOptions | ||||||
|  |         { | ||||||
|  |             None, | ||||||
|  |             Horizontal, | ||||||
|  |             Vertical, | ||||||
|  |             Both | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         private static readonly int PixelScale = 40; |         private static readonly int PixelScale = 40; | ||||||
|         private static readonly short[] Indices = new short[] |         private static readonly short[] Indices = new short[] | ||||||
|         { |         { | ||||||
|  | @ -26,7 +34,8 @@ namespace Kav | ||||||
| 
 | 
 | ||||||
|         public MeshSprite( |         public MeshSprite( | ||||||
|             GraphicsDevice graphicsDevice, |             GraphicsDevice graphicsDevice, | ||||||
|             Texture2D texture |             Texture2D texture, | ||||||
|  |             FlipOptions flipOptions | ||||||
|         ) { |         ) { | ||||||
|             Texture = texture; |             Texture = texture; | ||||||
|             Normal = null; |             Normal = null; | ||||||
|  | @ -39,7 +48,7 @@ namespace Kav | ||||||
| 			); | 			); | ||||||
|             IndexBuffer.SetData(Indices); |             IndexBuffer.SetData(Indices); | ||||||
| 
 | 
 | ||||||
|             var vertexArray = GenerateVertexArray(Texture); |             var vertexArray = GenerateVertexArray(Texture, flipOptions); | ||||||
| 
 | 
 | ||||||
|             VertexBuffer = new VertexBuffer( |             VertexBuffer = new VertexBuffer( | ||||||
|                 graphicsDevice, |                 graphicsDevice, | ||||||
|  | @ -55,7 +64,8 @@ namespace Kav | ||||||
|         public MeshSprite( |         public MeshSprite( | ||||||
|             GraphicsDevice graphicsDevice, |             GraphicsDevice graphicsDevice, | ||||||
|             Texture2D texture, |             Texture2D texture, | ||||||
|             Texture2D normal |             Texture2D normal, | ||||||
|  |             FlipOptions flipOptions | ||||||
|         ) { |         ) { | ||||||
|             Texture = texture; |             Texture = texture; | ||||||
|             Normal = normal; |             Normal = normal; | ||||||
|  | @ -68,7 +78,7 @@ namespace Kav | ||||||
| 			); | 			); | ||||||
|             IndexBuffer.SetData(Indices); |             IndexBuffer.SetData(Indices); | ||||||
| 
 | 
 | ||||||
|             var vertexArray = GenerateVertexArray(Texture); |             var vertexArray = GenerateVertexArray(Texture, flipOptions); | ||||||
| 
 | 
 | ||||||
|             VertexBuffer = new VertexBuffer( |             VertexBuffer = new VertexBuffer( | ||||||
|                 graphicsDevice, |                 graphicsDevice, | ||||||
|  | @ -81,25 +91,33 @@ namespace Kav | ||||||
|             BoundingBox = BoundingBox.CreateFromPoints(Positions(vertexArray)); |             BoundingBox = BoundingBox.CreateFromPoints(Positions(vertexArray)); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private static VertexPositionNormalTexture[] GenerateVertexArray(Texture2D texture) |         private static VertexPositionNormalTexture[] GenerateVertexArray(Texture2D texture, FlipOptions flipOptions) | ||||||
|         { |         { | ||||||
|             VertexPositionNormalTexture[] result = new VertexPositionNormalTexture[4]; |             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].Position = new Vector3(-texture.Width / 2, texture.Height / 2, 0) / PixelScale; | ||||||
|             result[0].Normal = new Vector3(0, 0, 1); |             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].Position = new Vector3(texture.Width / 2, texture.Height / 2, 0) / PixelScale; | ||||||
|             result[1].Normal = new Vector3(0, 0, 1); |             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].Position = new Vector3(-texture.Width / 2, -texture.Height / 2, 0) / PixelScale; | ||||||
|             result[2].Normal = new Vector3(0, 0, 1); |             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].Position = new Vector3(texture.Width / 2, -texture.Height / 2, 0) / PixelScale; | ||||||
|             result[3].Normal = new Vector3(0, 0, 1); |             result[3].Normal = new Vector3(0, 0, 1); | ||||||
|             result[3].TextureCoordinate = new Vector2(1, 1); |             result[3].TextureCoordinate = new Vector2(xRight, 1); | ||||||
| 
 | 
 | ||||||
|             return result; |             return result; | ||||||
|         } |         } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue