This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

XNA - DXT5 Normal Map Content Processor

By: a guest on Sep 30th, 2011  |  syntax: C#  |  size: 1.68 KB  |  views: 236  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. [ContentProcessor( DisplayName = "Texture - DXT Normal Map" )]
  2. public class DxtNormalMapProcessor : TextureProcessor {
  3.  
  4.     // PUBLIC DATA
  5.  
  6.     // Hard-coded parameter values - optional:
  7.  
  8.     public override bool GenerateMipmaps {
  9.         get { return true; }
  10.         set { }
  11.     }
  12.  
  13.     public override bool ColorKeyEnabled {
  14.         get { return false; }
  15.         set { }
  16.     }
  17.  
  18.     public override bool PremultiplyAlpha {
  19.         get { return false; }
  20.         set { }
  21.     }
  22.  
  23.     public override TextureProcessorOutputFormat TextureFormat {
  24.         get { return TextureProcessorOutputFormat.DxtCompressed; }
  25.         set { }
  26.     }
  27.  
  28.  
  29.  
  30.     // PUBLIC METHODS
  31.  
  32.     /// <summary>
  33.     /// Processes the texture for DXT5 normal map compression. Moves X to green and Y to alpha.
  34.     /// </summary>
  35.     public override TextureContent Process( TextureContent input, ContentProcessorContext context ) {
  36.  
  37.         // Move X to green and Y to alpha
  38.         foreach ( MipmapChain face in input.Faces ) {
  39.             foreach ( BitmapContent bitmap in face ) {
  40.                 byte[] data = bitmap.GetPixelData();
  41.                 for ( int i = 0; i < data.Length; i += 4 ) {
  42.                     int red = i, green = i + 1, blue = i + 2, alpha = i + 3;
  43.                     data[ alpha ] = data[ green ];
  44.                     data[ green ] = data[ red ];
  45.                     data[ red ] = 0;
  46.                     data[ blue ] = 0;
  47.                 }
  48.                 bitmap.SetPixelData( data );
  49.             }
  50.         }
  51.  
  52.         // Do base class processing
  53.         TextureContent output = base.Process( input, context );
  54.  
  55.         // Return result
  56.         return output;
  57.     }
  58.  
  59. } // end class
  60.  
clone this paste RAW Paste Data