PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Utilities/Graphics/ShaderFeatures/SpecularShaderFeature.cs

#
C# | 118 lines | 66 code | 9 blank | 43 comment | 0 complexity | 151eb0f329830e07e58c5d6b7d27b974 MD5 | raw file
Possible License(s): Apache-2.0
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using Delta.Utilities.Datatypes;
  4. namespace Delta.Utilities.Graphics.ShaderFeatures
  5. {
  6. /// <summary>
  7. /// Specular shader feature
  8. /// </summary>
  9. public class SpecularShaderFeature : IShaderFeature
  10. {
  11. #region SpecularColor (Public)
  12. /// <summary>
  13. /// Specular color is the color of highlights on a shiny surface.
  14. /// The highlights are reflections of the lights that illuminate the
  15. /// surface. For a naturalistic effect, set the specular color to the
  16. /// same color as the key light source, or make it a high-value,
  17. /// low-saturation version of the diffuse color.
  18. /// </summary>
  19. public Color SpecularColor = ShaderConstants.DefaultSpecularColor;
  20. #endregion
  21. #region SpecularPower (Public)
  22. /// <summary>
  23. /// A specular power refers to how much light is reflected in a mirror
  24. /// like fashion, rather than scattered randomly in a diffuse manner.
  25. /// So a mirror would have high specular power, a glossy surface some
  26. /// specular power and a matt black surface none.
  27. /// </summary>
  28. public float SpecularPower = ShaderConstants.DefaultSpecularPower;
  29. #endregion
  30. #region ShaderFeature (Public)
  31. /// <summary>
  32. /// Which shader feature flag is this ShaderFeature class using?
  33. /// Important for loading this file via ShaderData.LoadShaderFeature.
  34. /// Each flag should obviously only have one class for it!
  35. /// </summary>
  36. public ShaderFeatureFlags ShaderFeature
  37. {
  38. get
  39. {
  40. return ShaderFeatureFlags.Specular;
  41. }
  42. }
  43. #endregion
  44. #region RequiredShaderFeatures (Public)
  45. /// <summary>
  46. /// Which shader feature flags are required for this ShaderFeature.
  47. /// Very important for creating of a new ShaderFeature.
  48. /// </summary>
  49. public ShaderFeatureFlags RequiredShaderFeatures
  50. {
  51. get
  52. {
  53. // NOTE: We don't need the AmbientDiffuse flag here.
  54. // The Lighting has it already.
  55. return ShaderFeatureFlags.DynamicDirectionalLighting;
  56. }
  57. }
  58. #endregion
  59. #region Parameters (Public)
  60. /// <summary>
  61. /// Parameters as a dictionary, will be generated on the fly when
  62. /// requested.
  63. /// </summary>
  64. public Dictionary<string, object> Parameters
  65. {
  66. get
  67. {
  68. Dictionary<string, object> ret = new Dictionary<string, object>();
  69. ret.Add("SpecularColor", SpecularColor);
  70. ret.Add("SpecularPower", SpecularPower);
  71. return ret;
  72. }
  73. }
  74. #endregion
  75. #region Constructors
  76. /// <summary>
  77. /// Create specular shader feature
  78. /// </summary>
  79. public SpecularShaderFeature()
  80. {
  81. }
  82. /// <summary>
  83. /// Create specular shader feature
  84. /// </summary>
  85. public SpecularShaderFeature(BinaryReader reader)
  86. {
  87. Load(reader);
  88. }
  89. #endregion
  90. #region ISaveLoadBinary Members
  91. /// <summary>
  92. /// Load this ShaderFeature from a binary data stream.
  93. /// </summary>
  94. public void Load(BinaryReader reader)
  95. {
  96. SpecularColor.Load(reader);
  97. SpecularPower = reader.ReadSingle();
  98. }
  99. /// <summary>
  100. /// Save this ShaderFeature to a binary data stream.
  101. /// </summary>
  102. public void Save(BinaryWriter writer)
  103. {
  104. SpecularColor.Save(writer);
  105. writer.Write(SpecularPower);
  106. }
  107. #endregion
  108. }
  109. }