PageRenderTime 214ms CodeModel.GetById 121ms app.highlight 3ms RepoModel.GetById 87ms app.codeStats 0ms

/Utilities/Graphics/ShaderFeatures/ParallaxMapShaderFeature.cs

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