DistorterMaterialProcessor.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // DistorterMaterialProcessor.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using System.Collections.Generic;
  12. using Microsoft.Xna.Framework.Content.Pipeline;
  13. using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
  14. using Microsoft.Xna.Framework.Content.Pipeline.Processors;
  15. #endregion
  16. namespace DistortionPipeline
  17. {
  18. /// <summary>
  19. /// Applies the Distorters effect and builds a distortion map if one is specified.
  20. /// Note that the distortion map is set as a parameter in the model file.
  21. /// </summary>
  22. [ContentProcessor]
  23. class DistorterMaterialProcessor : MaterialProcessor
  24. {
  25. /// <summary>
  26. /// Name of the effect parameter set for the displacement height map texture
  27. /// </summary>
  28. public const string DisplacementMapKey = "DisplacementMap";
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. public override MaterialContent Process(MaterialContent input,
  33. ContentProcessorContext context)
  34. {
  35. // Reference the Distorters effect file
  36. EffectMaterialContent effect = new EffectMaterialContent();
  37. effect.Effect =
  38. new ExternalReference<EffectContent>("Distorters.fx");
  39. // If the model specifies a displacement map, carry it over
  40. ExternalReference<TextureContent> displacementMap;
  41. if (input.Textures.TryGetValue(DisplacementMapKey, out displacementMap))
  42. {
  43. effect.Textures.Add(DisplacementMapKey, displacementMap);
  44. }
  45. // Continue processing the distorter effect with the default effect behavior
  46. return base.Process(effect, context);
  47. }
  48. /// <summary>
  49. /// Builds Distorter textures with the DisplacementMapProcessor
  50. /// </summary>
  51. protected override ExternalReference<TextureContent> BuildTexture(
  52. string textureName, ExternalReference<TextureContent> texture,
  53. ContentProcessorContext context)
  54. {
  55. return context.BuildAsset<TextureContent,
  56. TextureContent>(texture, "DisplacementMapProcessor");
  57. }
  58. }
  59. }