/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
- using System.Collections.Generic;
- using System.IO;
-
- namespace Delta.Utilities.Graphics.ShaderFeatures
- {
- /// <summary>
- /// ParallaxMap shader feature
- /// Note: add some flags where the parallax height map is coming from
- /// (lightmap (currently), diffuse, normal map, extra map, etc.)
- /// </summary>
- public class ParallaxMapShaderFeature : IShaderFeature
- {
- #region ParallaxAmount (Public)
- /// <summary>
- /// Parallax mapping is usually used in combination with normal mapping,
- /// but you can use it own its own. It needs an extra height map (usually
- /// just the light map or normal map extra alpha color channel) for even
- /// cooler depth effects on the texture. Adds about 2 instructions, but
- /// even if that overhead is ok, also additional work at the artist side
- /// is needed, not only to create the extra height/bump map, but also to
- /// fine tune the parallax amount to look nice. The height map should be
- /// as blurry as possible, high variations will cause parallax glitches.
- /// </summary>
- public float ParallaxAmount = ShaderConstants.DefaultParallaxAmount;
- #endregion
-
- #region ShaderFeature (Public)
- /// <summary>
- /// Which shader feature flag is this ShaderFeature class using?
- /// Important for loading this file via ShaderData.LoadShaderFeature.
- /// Each flag should obviously only have one class for it!
- /// </summary>
- public ShaderFeatureFlags ShaderFeature
- {
- get
- {
- return ShaderFeatureFlags.ParallaxMap;
- }
- }
- #endregion
-
- #region RequiredShaderFeatures (Public)
- /// <summary>
- /// Which shader feature flags are required for this ShaderFeature.
- /// Very important for creating of a new ShaderFeature.
- /// </summary>
- public ShaderFeatureFlags RequiredShaderFeatures
- {
- get
- {
- // Note: We need nothing for parallax, but it is usually combined
- // with many other flags, most importantly NormalMap to look cool.
- // Currently we use the LightMap alpha channel for the parallax, so
- // we always need those two flags together.
- return ShaderFeatureFlags.LightMap; //.Basic;
- }
- }
- #endregion
-
- #region Parameters (Public)
- /// <summary>
- /// Parameters as a dictionary, will be generated on the fly when
- /// requested.
- /// </summary>
- public Dictionary<string, object> Parameters
- {
- get
- {
- Dictionary<string, object> ret = new Dictionary<string, object>();
- ret.Add("ParallaxAmount", ParallaxAmount);
- return ret;
- }
- }
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create parallax shader feature
- /// </summary>
- public ParallaxMapShaderFeature()
- {
- }
-
- /// <summary>
- /// Create parallax shader feature
- /// </summary>
- public ParallaxMapShaderFeature(BinaryReader reader)
- {
- Load(reader);
- }
- #endregion
-
- #region ISaveLoadBinary Members
- /// <summary>
- /// Load this ShaderFeature from a binary data stream.
- /// </summary>
- public void Load(BinaryReader reader)
- {
- ParallaxAmount = reader.ReadSingle();
- }
-
- /// <summary>
- /// Save this ShaderFeature to a binary data stream.
- /// </summary>
- public void Save(BinaryWriter writer)
- {
- writer.Write(ParallaxAmount);
- }
- #endregion
- }
- }