/Utilities/Graphics/ShaderFeatures/FogShaderFeature.cs
C# | 160 lines | 84 code | 12 blank | 64 comment | 0 complexity | cebc8c1a764ffb61bdf60603567e27a0 MD5 | raw file
Possible License(s): Apache-2.0
- using System.Collections.Generic;
- using System.IO;
- using Delta.Utilities.Datatypes;
-
- namespace Delta.Utilities.Graphics.ShaderFeatures
- {
- /// <summary>
- /// Fog shader feature
- ///Note: add exponential and exponential^2 flags for better fog, but that
- /// needs more shader testing and finetuning.
- /// </summary>
- public class FogShaderFeature : IShaderFeature
- {
- #region FogColor (Public)
- /// <summary>
- /// The ShaderParameters array should contain: FogColor, FogStart and
- /// FogEnd. This does not mean those variables are used as shader uniforms,
- /// they are usually constant and can be used for both fixed function
- /// pipeline code and for shader code. Adds 4-5 vertex shader instructions
- /// and 2 pixel shader instructions (lerp is costly, but required).
- /// Note: Currently only the FogColor is used in the shader, the rest
- /// is baked as constants into it (faster because we don't need to
- /// calculate FogEnd-FogStart and it makes more sense to have the same
- /// values for all shaders anyway).
- /// </summary>
- public Color FogColor = new Color(0.6f, 0.3f, 0.3f);
- #endregion
-
- #region FogStart (Public)
- /// <summary>
- /// The default fog start distance is 10m, everything closer will also
- /// get a little of the FogColor, see MinimumFogValue.
- /// </summary>
- public float FogStart = 10.0f;
- #endregion
-
- #region FogEnd (Public)
- /// <summary>
- /// Maximum distance for the fog, here the fog is at full intensity (see
- /// MaximumFogValue). Should be synced up with BaseCamera.FarPlane, which
- /// is currently 75.0 for the SoulCraft Tech Demo.
- /// </summary>
- public float FogEnd = 75.0f;
- #endregion
-
- #region MinimumFogValue (Public)
- /// <summary>
- /// Minimum fog value that gets mixed in for each pixel in the pixel
- /// shader. This value is currently pretty high (0.15 like the default
- /// ambient color) to color all pixels a little in the fog color to
- /// colorize everything in the scene with this fog color to fit together
- /// better.
- /// </summary>
- public float MinimumFogValue = 0.15f;
- #endregion
-
- #region MaximumFogValue (Public)
- /// <summary>
- /// Maximum fog value, does not have to be 1.0, the default value for
- /// this is 0.9, which means fog is never at 100%. There will always be
- /// a little bit of the original pixel shader color visible.
- /// </summary>
- public float MaximumFogValue = 0.9f;
- #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.Fog;
- }
- }
- #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 don't need anything for fog, this can be combined with
- // all shaders. It will only make sense for 3D rendering however.
- return ShaderFeatureFlags.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("FogColor", FogColor);
- ret.Add("FogStart", FogStart);
- ret.Add("FogEnd", FogEnd);
- ret.Add("MinimumFogValue", MinimumFogValue);
- ret.Add("MaximumFogValue", MaximumFogValue);
- return ret;
- }
- }
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create fog shader feature
- /// </summary>
- public FogShaderFeature()
- {
- }
-
- /// <summary>
- /// Create fog shader feature
- /// </summary>
- public FogShaderFeature(BinaryReader reader)
- {
- Load(reader);
- }
- #endregion
-
- #region ISaveLoadBinary Members
- /// <summary>
- /// Load this ShaderFeature from a binary data stream.
- /// </summary>
- public void Load(BinaryReader reader)
- {
- FogColor.Load(reader);
- FogStart = reader.ReadSingle();
- FogEnd = reader.ReadSingle();
- MinimumFogValue = reader.ReadSingle();
- MaximumFogValue = reader.ReadSingle();
- }
-
- /// <summary>
- /// Save this ShaderFeature to a binary data stream.
- /// </summary>
- public void Save(BinaryWriter writer)
- {
- FogColor.Save(writer);
- writer.Write(FogStart);
- writer.Write(FogEnd);
- writer.Write(MinimumFogValue);
- writer.Write(MaximumFogValue);
- }
- #endregion
- }
- }