PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Utilities/Graphics/ShaderFeatures/ParallaxMapShaderFeature.cs

#
C# | 111 lines | 59 code | 8 blank | 44 comment | 0 complexity | f1ae3feeaee98ce6c08d68ab9c9c4215 MD5 | raw file
Possible License(s): Apache-2.0
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace Delta.Utilities.Graphics.ShaderFeatures
  4. {
  5. /// <summary>
  6. /// ParallaxMap shader feature
  7. /// Note: add some flags where the parallax height map is coming from
  8. /// (lightmap (currently), diffuse, normal map, extra map, etc.)
  9. /// </summary>
  10. public class ParallaxMapShaderFeature : IShaderFeature
  11. {
  12. #region ParallaxAmount (Public)
  13. /// <summary>
  14. /// Parallax mapping is usually used in combination with normal mapping,
  15. /// but you can use it own its own. It needs an extra height map (usually
  16. /// just the light map or normal map extra alpha color channel) for even
  17. /// cooler depth effects on the texture. Adds about 2 instructions, but
  18. /// even if that overhead is ok, also additional work at the artist side
  19. /// is needed, not only to create the extra height/bump map, but also to
  20. /// fine tune the parallax amount to look nice. The height map should be
  21. /// as blurry as possible, high variations will cause parallax glitches.
  22. /// </summary>
  23. public float ParallaxAmount = ShaderConstants.DefaultParallaxAmount;
  24. #endregion
  25. #region ShaderFeature (Public)
  26. /// <summary>
  27. /// Which shader feature flag is this ShaderFeature class using?
  28. /// Important for loading this file via ShaderData.LoadShaderFeature.
  29. /// Each flag should obviously only have one class for it!
  30. /// </summary>
  31. public ShaderFeatureFlags ShaderFeature
  32. {
  33. get
  34. {
  35. return ShaderFeatureFlags.ParallaxMap;
  36. }
  37. }
  38. #endregion
  39. #region RequiredShaderFeatures (Public)
  40. /// <summary>
  41. /// Which shader feature flags are required for this ShaderFeature.
  42. /// Very important for creating of a new ShaderFeature.
  43. /// </summary>
  44. public ShaderFeatureFlags RequiredShaderFeatures
  45. {
  46. get
  47. {
  48. // Note: We need nothing for parallax, but it is usually combined
  49. // with many other flags, most importantly NormalMap to look cool.
  50. // Currently we use the LightMap alpha channel for the parallax, so
  51. // we always need those two flags together.
  52. return ShaderFeatureFlags.LightMap; //.Basic;
  53. }
  54. }
  55. #endregion
  56. #region Parameters (Public)
  57. /// <summary>
  58. /// Parameters as a dictionary, will be generated on the fly when
  59. /// requested.
  60. /// </summary>
  61. public Dictionary<string, object> Parameters
  62. {
  63. get
  64. {
  65. Dictionary<string, object> ret = new Dictionary<string, object>();
  66. ret.Add("ParallaxAmount", ParallaxAmount);
  67. return ret;
  68. }
  69. }
  70. #endregion
  71. #region Constructors
  72. /// <summary>
  73. /// Create parallax shader feature
  74. /// </summary>
  75. public ParallaxMapShaderFeature()
  76. {
  77. }
  78. /// <summary>
  79. /// Create parallax shader feature
  80. /// </summary>
  81. public ParallaxMapShaderFeature(BinaryReader reader)
  82. {
  83. Load(reader);
  84. }
  85. #endregion
  86. #region ISaveLoadBinary Members
  87. /// <summary>
  88. /// Load this ShaderFeature from a binary data stream.
  89. /// </summary>
  90. public void Load(BinaryReader reader)
  91. {
  92. ParallaxAmount = reader.ReadSingle();
  93. }
  94. /// <summary>
  95. /// Save this ShaderFeature to a binary data stream.
  96. /// </summary>
  97. public void Save(BinaryWriter writer)
  98. {
  99. writer.Write(ParallaxAmount);
  100. }
  101. #endregion
  102. }
  103. }