Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ContentProcessor( DisplayName = "Texture - DXT Normal Map" )]
- public class DxtNormalMapProcessor : TextureProcessor {
- // PUBLIC DATA
- // Hard-coded parameter values - optional:
- public override bool GenerateMipmaps {
- get { return true; }
- set { }
- }
- public override bool ColorKeyEnabled {
- get { return false; }
- set { }
- }
- public override bool PremultiplyAlpha {
- get { return false; }
- set { }
- }
- public override TextureProcessorOutputFormat TextureFormat {
- get { return TextureProcessorOutputFormat.DxtCompressed; }
- set { }
- }
- // PUBLIC METHODS
- /// <summary>
- /// Processes the texture for DXT5 normal map compression. Moves X to green and Y to alpha.
- /// </summary>
- public override TextureContent Process( TextureContent input, ContentProcessorContext context ) {
- // Move X to green and Y to alpha
- foreach ( MipmapChain face in input.Faces ) {
- foreach ( BitmapContent bitmap in face ) {
- byte[] data = bitmap.GetPixelData();
- for ( int i = 0; i < data.Length; i += 4 ) {
- int red = i, green = i + 1, blue = i + 2, alpha = i + 3;
- data[ alpha ] = data[ green ];
- data[ green ] = data[ red ];
- data[ red ] = 0;
- data[ blue ] = 0;
- }
- bitmap.SetPixelData( data );
- }
- }
- // Do base class processing
- TextureContent output = base.Process( input, context );
- // Return result
- return output;
- }
- } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement