PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/Utilities/Graphics/ShaderFeatures/SpecularShaderFeature.cs

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