NormalMappingMaterialProcessor.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // NormalMappingMaterialProcessor.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Text;
  12. using Microsoft.Xna.Framework.Content.Pipeline;
  13. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  14. using Microsoft.Xna.Framework.Content.Pipeline.Processors;
  15. using System.ComponentModel;
  16. namespace NormalMappingEffectPipeline
  17. {
  18. /// <summary>
  19. /// The NormalMappingMaterialProcessor is very simple. It extends the regular
  20. /// MaterialProcessor, overriding BuildTexture so that normal maps can go through
  21. /// the NormalMapTextureProcessor and be converted to a signed normalmap format.
  22. /// </summary>
  23. [ContentProcessor]
  24. [DesignTimeVisible(false)]
  25. public class NormalMappingMaterialProcessor : MaterialProcessor
  26. {
  27. protected override ExternalReference<TextureContent> BuildTexture
  28. (string textureName, ExternalReference<TextureContent> texture,
  29. ContentProcessorContext context)
  30. {
  31. if (textureName == NormalMappingModelProcessor.NormalMapKey)
  32. {
  33. // put the normal map through the special NormalMapTextureProcessor,
  34. // which will convert it to a signed format.
  35. return context.BuildAsset<TextureContent, TextureContent>(texture,
  36. typeof(NormalMapTextureProcessor).Name);
  37. }
  38. // Apply default processing to all other textures.
  39. return base.BuildTexture(textureName, texture, context);
  40. }
  41. }
  42. }