Răsfoiți Sursa

Merge pull request #1461 from Azaezel/textureLinearization

Diffuse/albedo texture linearization
Areloch 9 ani în urmă
părinte
comite
cb22357eb2
31 a modificat fișierele cu 396 adăugiri și 107 ștergeri
  1. 1 1
      Engine/source/lighting/advanced/advancedLightManager.cpp
  2. 1 0
      Engine/source/materials/materialFeatureTypes.cpp
  3. 1 0
      Engine/source/materials/materialFeatureTypes.h
  4. 2 0
      Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp
  5. 25 18
      Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp
  6. 5 0
      Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h
  7. 1 0
      Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp
  8. 2 0
      Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp
  9. 23 19
      Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp
  10. 5 0
      Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h
  11. 1 0
      Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp
  12. 7 0
      Engine/source/terrain/glsl/terrFeatureGLSL.cpp
  13. 3 0
      Engine/source/terrain/glsl/terrFeatureGLSL.h
  14. 7 0
      Engine/source/terrain/hlsl/terrFeatureHLSL.cpp
  15. 4 0
      Engine/source/terrain/hlsl/terrFeatureHLSL.h
  16. 1 0
      Engine/source/util/imposterCapture.cpp
  17. 169 47
      Templates/Full/game/art/gui/optionsDlg.gui
  18. 3 1
      Templates/Full/game/core/scripts/client/defaults.cs
  19. 4 2
      Templates/Full/game/core/scripts/client/postFx/GammaPostFX.cs
  20. 13 2
      Templates/Full/game/core/scripts/client/postFx/hdr.cs
  21. 17 16
      Templates/Full/game/core/scripts/client/renderManager.cs
  22. 33 0
      Templates/Full/game/shaders/common/gl/torque.glsl
  23. 8 1
      Templates/Full/game/shaders/common/postFx/gammaP.hlsl
  24. 8 0
      Templates/Full/game/shaders/common/postFx/gl/gammaP.glsl
  25. 8 0
      Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl
  26. 8 0
      Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl
  27. 32 0
      Templates/Full/game/shaders/common/torque.hlsl
  28. 1 0
      Templates/Full/game/shaders/common/water/gl/waterBasicP.glsl
  29. 1 0
      Templates/Full/game/shaders/common/water/gl/waterP.glsl
  30. 1 0
      Templates/Full/game/shaders/common/water/waterBasicP.hlsl
  31. 1 0
      Templates/Full/game/shaders/common/water/waterP.hlsl

+ 1 - 1
Engine/source/lighting/advanced/advancedLightManager.cpp

@@ -105,7 +105,7 @@ void AdvancedLightManager::activate( SceneManager *sceneManager )
    // we prefer the floating point format if it works.
    Vector<GFXFormat> formats;
    formats.push_back( GFXFormatR16G16B16A16F );
-   formats.push_back( GFXFormatR16G16B16A16 );
+   //formats.push_back( GFXFormatR16G16B16A16 );
    GFXFormat blendTargetFormat = GFX->selectSupportedFormat( &GFXDefaultRenderTargetProfile,
                                                          formats,
                                                          true,

+ 1 - 0
Engine/source/materials/materialFeatureTypes.cpp

@@ -46,6 +46,7 @@ ImplementFeatureType( MFT_AlphaTest, MFG_Texture, 7.0f, true );
 ImplementFeatureType( MFT_SpecularMap, MFG_Texture, 8.0f, true );
 ImplementFeatureType( MFT_NormalMap, MFG_Texture, 9.0f, true );
 ImplementFeatureType( MFT_DetailNormalMap, MFG_Texture, 10.0f, true );
+ImplementFeatureType( MFT_Imposter, U32(-1), -1, true );
 
 ImplementFeatureType( MFT_AccuMap, MFG_PreLighting, 2.0f, true );
 

+ 1 - 0
Engine/source/materials/materialFeatureTypes.h

@@ -94,6 +94,7 @@ DeclareFeatureType( MFT_OverlayMap );
 DeclareFeatureType( MFT_DetailMap );
 DeclareFeatureType( MFT_DiffuseColor );
 DeclareFeatureType( MFT_DetailNormalMap );
+DeclareFeatureType( MFT_Imposter );
 
 DeclareFeatureType( MFT_AccuMap );
 DeclareFeatureType( MFT_AccuScale );

+ 2 - 0
Engine/source/shaderGen/GLSL/accuFeatureGLSL.cpp

@@ -144,6 +144,8 @@ void AccuTexFeatGLSL::processPix(Vector<ShaderComponent*> &componentList,
 
    // get the accu pixel color
    meta->addStatement( new GenOp( "   @ = tex2D(@, @ * @);\r\n", colorAccuDecl, accuMap, inTex, accuScale ) );
+   if (!fd.features[MFT_Imposter])
+      meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", accuColor, accuColor));
 
    // scale up normals
    meta->addStatement( new GenOp( "   @.xyz = @.xyz * 2.0 - 0.5;\r\n", bumpNorm, bumpNorm ) );

+ 25 - 18
Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp

@@ -828,6 +828,12 @@ Var* ShaderFeatureGLSL::addOutDetailTexCoord(   Vector<ShaderComponent*> &compon
 // Base Texture
 //****************************************************************************
 
+DiffuseMapFeatGLSL::DiffuseMapFeatGLSL()
+: mTorqueDep("shaders/common/gl/torque.glsl")
+{
+	addDependency(&mTorqueDep);
+}
+
 void DiffuseMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList, 
                                        const MaterialFeatureData &fd )
 {
@@ -855,20 +861,23 @@ void DiffuseMapFeatGLSL::processPix(   Vector<ShaderComponent*> &componentList,
    diffuseMap->sampler = true;
    diffuseMap->constNum = Var::getTexUnitNum();     // used as texture unit num here
 
+   // create sample color var
+   Var *diffColor = new Var;
+   diffColor->setType("vec4");
+   diffColor->setName("diffuseColor");
+   LangElement *colorDecl = new DecOp( diffColor );
+
+   MultiLine * meta = new MultiLine;
+   output = meta;
+
    if (  fd.features[MFT_CubeMap] )
    {
-      MultiLine * meta = new MultiLine;
-      
-      // create sample color
-      Var *diffColor = new Var;
-      diffColor->setType( "vec4" );
-      diffColor->setName( "diffuseColor" );
-      LangElement *colorDecl = new DecOp( diffColor );
-   
       meta->addStatement(  new GenOp( "   @ = tex2D(@, @);\r\n", 
                            colorDecl, 
                            diffuseMap, 
                            inTex ) );
+      if (!fd.features[MFT_Imposter])
+         meta->addStatement( new GenOp("   @ = toLinear(@);\r\n", diffColor, diffColor) );
       
       meta->addStatement( new GenOp( "   @;\r\n", assignColor( diffColor, Material::Mul ) ) );
       output = meta;
@@ -877,8 +886,6 @@ void DiffuseMapFeatGLSL::processPix(   Vector<ShaderComponent*> &componentList,
    {   
       // Handle atlased textures
       // http://www.infinity-universe.com/Infinity/index.php?option=com_content&task=view&id=65&Itemid=47
-      MultiLine * meta = new MultiLine;
-      output = meta;
 
       Var *atlasedTex = new Var;
       atlasedTex->setName("atlasedTexCoord");
@@ -934,11 +941,6 @@ void DiffuseMapFeatGLSL::processPix(   Vector<ShaderComponent*> &componentList,
       // For the rest of the feature...
       inTex = atlasedTex;
 
-      // create sample color var
-      Var *diffColor = new Var;
-      diffColor->setType("vec4");
-      diffColor->setName("diffuseColor");
-
       // To dump out UV coords...
       //#define DEBUG_ATLASED_UV_COORDS
 #ifdef DEBUG_ATLASED_UV_COORDS
@@ -954,21 +956,26 @@ void DiffuseMapFeatGLSL::processPix(   Vector<ShaderComponent*> &componentList,
       {
          meta->addStatement(new GenOp( "   @ = tex2Dlod(@, float4(@, 0.0, mipLod));\r\n", 
             new DecOp(diffColor), diffuseMap, inTex));
+         if (!fd.features[MFT_Imposter])
+            meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", diffColor, diffColor));
       }
       else
       {
          meta->addStatement(new GenOp( "   @ = tex2D(@, @);\r\n", 
             new DecOp(diffColor), diffuseMap, inTex));
+          if (!fd.features[MFT_Imposter])
+             meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", diffColor, diffColor));
       }
 
       meta->addStatement(new GenOp( "   @;\r\n", assignColor(diffColor, Material::Mul)));
    }
    else
    {
-      LangElement *statement = new GenOp( "tex2D(@, @)", diffuseMap, inTex );
-      output = new GenOp( "   @;\r\n", assignColor( statement, Material::Mul ) );
+      meta->addStatement(new GenOp("@ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex));
+      if (!fd.features[MFT_Imposter])
+         meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", diffColor, diffColor));
+      meta->addStatement(new GenOp("   @;\r\n", assignColor(diffColor, Material::Mul)));
    }
-   
 }
 
 ShaderFeature::Resources DiffuseMapFeatGLSL::getResources( const MaterialFeatureData &fd )

+ 5 - 0
Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h

@@ -236,7 +236,12 @@ public:
 /// Base texture
 class DiffuseMapFeatGLSL : public ShaderFeatureGLSL
 {
+
+protected:
+
+	ShaderIncludeDependency mTorqueDep;
 public:
+	DiffuseMapFeatGLSL();
    virtual void processVert( Vector<ShaderComponent*> &componentList,
                              const MaterialFeatureData &fd );
 

+ 1 - 0
Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp

@@ -68,6 +68,7 @@ void _initShaderGenGLSL( ShaderGen *shaderGen )
    FEATUREMGR->registerFeature( MFT_IsTranslucent, new NamedFeatureGLSL( "Translucent" ) );
    FEATUREMGR->registerFeature( MFT_Visibility, new VisibilityFeatGLSL );
    FEATUREMGR->registerFeature( MFT_Fog, new FogFeatGLSL );
+   FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureGLSL( "Imposter" ) );
 
 	FEATUREMGR->registerFeature( MFT_NormalsOut, new NormalsOutFeatGLSL );
 	

+ 2 - 0
Engine/source/shaderGen/HLSL/accuFeatureHLSL.cpp

@@ -141,6 +141,8 @@ void AccuTexFeatHLSL::processPix(   Vector<ShaderComponent*> &componentList,
 
    // get the accu pixel color
    meta->addStatement( new GenOp( "   @ = tex2D(@, @ * @);\r\n", colorAccuDecl, accuMap, inTex, accuScale ) );
+   if (!fd.features[MFT_Imposter])
+      meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", accuColor, accuColor));
 
    // scale up normals
    meta->addStatement( new GenOp( "   @.xyz = @.xyz * 2.0 - 0.5;\r\n", bumpNorm, bumpNorm ) );

+ 23 - 19
Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp

@@ -826,6 +826,12 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord(   Vector<ShaderComponent*> &compon
 // Base Texture
 //****************************************************************************
 
+DiffuseMapFeatHLSL::DiffuseMapFeatHLSL()
+: mTorqueDep("shaders/common/torque.hlsl")
+{
+	addDependency(&mTorqueDep);
+}
+
 void DiffuseMapFeatHLSL::processVert( Vector<ShaderComponent*> &componentList, 
                                        const MaterialFeatureData &fd )
 {
@@ -853,30 +859,30 @@ void DiffuseMapFeatHLSL::processPix(   Vector<ShaderComponent*> &componentList,
    diffuseMap->sampler = true;
    diffuseMap->constNum = Var::getTexUnitNum();     // used as texture unit num here
 
+   // create sample color
+   Var *diffColor = new Var;
+   diffColor->setType("float4");
+   diffColor->setName("diffuseColor");
+   LangElement *colorDecl = new DecOp(diffColor);
+
+   MultiLine * meta = new MultiLine;
+   output = meta;
+
    if (  fd.features[MFT_CubeMap] )
    {
-      MultiLine * meta = new MultiLine;
-      
-      // create sample color
-      Var *diffColor = new Var;
-      diffColor->setType( "float4" );
-      diffColor->setName( "diffuseColor" );
-      LangElement *colorDecl = new DecOp( diffColor );
-   
       meta->addStatement(  new GenOp( "   @ = tex2D(@, @);\r\n", 
                            colorDecl, 
                            diffuseMap, 
                            inTex ) );
+      if (!fd.features[MFT_Imposter])
+         meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", diffColor, diffColor));
       
       meta->addStatement( new GenOp( "   @;\r\n", assignColor( diffColor, Material::Mul ) ) );
-      output = meta;
    }
    else if(fd.features[MFT_DiffuseMapAtlas])
    {   
       // Handle atlased textures
       // http://www.infinity-universe.com/Infinity/index.php?option=com_content&task=view&id=65&Itemid=47
-      MultiLine * meta = new MultiLine;
-      output = meta;
 
       Var *atlasedTex = new Var;
       atlasedTex->setName("atlasedTexCoord");
@@ -932,11 +938,6 @@ void DiffuseMapFeatHLSL::processPix(   Vector<ShaderComponent*> &componentList,
       // For the rest of the feature...
       inTex = atlasedTex;
 
-      // create sample color var
-      Var *diffColor = new Var;
-      diffColor->setType("float4");
-      diffColor->setName("diffuseColor");
-
       // To dump out UV coords...
 //#define DEBUG_ATLASED_UV_COORDS
 #ifdef DEBUG_ATLASED_UV_COORDS
@@ -958,15 +959,18 @@ void DiffuseMapFeatHLSL::processPix(   Vector<ShaderComponent*> &componentList,
          meta->addStatement(new GenOp( "   @ = tex2D(@, @);\r\n", 
             new DecOp(diffColor), diffuseMap, inTex));
       }
+      if (!fd.features[MFT_Imposter])
+         meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", diffColor, diffColor));
 
       meta->addStatement(new GenOp( "   @;\r\n", assignColor(diffColor, Material::Mul)));
    }
    else
    {
-      LangElement *statement = new GenOp( "tex2D(@, @)", diffuseMap, inTex );
-      output = new GenOp( "   @;\r\n", assignColor( statement, Material::Mul ) );
+      meta->addStatement(new GenOp("@ = tex2D(@, @);\r\n", colorDecl, diffuseMap, inTex));
+      if (!fd.features[MFT_Imposter])
+         meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", diffColor, diffColor));
+      meta->addStatement(new GenOp("   @;\r\n", assignColor(diffColor, Material::Mul)));
    }
-   
 }
 
 ShaderFeature::Resources DiffuseMapFeatHLSL::getResources( const MaterialFeatureData &fd )

+ 5 - 0
Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h

@@ -236,7 +236,12 @@ public:
 /// Base texture
 class DiffuseMapFeatHLSL : public ShaderFeatureHLSL
 {
+protected:
+
+   ShaderIncludeDependency mTorqueDep;
+
 public:
+   DiffuseMapFeatHLSL();
    virtual void processVert( Vector<ShaderComponent*> &componentList,
                              const MaterialFeatureData &fd );
 

+ 1 - 0
Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp

@@ -70,6 +70,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen )
    FEATUREMGR->registerFeature( MFT_GlossMap, new NamedFeatureHLSL( "Gloss Map" ) );
    FEATUREMGR->registerFeature( MFT_LightbufferMRT, new NamedFeatureHLSL( "Lightbuffer MRT" ) );
    FEATUREMGR->registerFeature( MFT_RenderTarget1_Zero, new RenderTargetZeroHLSL( ShaderFeature::RenderTarget1 ) );
+   FEATUREMGR->registerFeature( MFT_Imposter, new NamedFeatureHLSL( "Imposter" ) );
 
    FEATUREMGR->registerFeature( MFT_DiffuseMapAtlas, new NamedFeatureHLSL( "Diffuse Map Atlas" ) );
    FEATUREMGR->registerFeature( MFT_NormalMapAtlas, new NamedFeatureHLSL( "Normal Map Atlas" ) );

+ 7 - 0
Engine/source/terrain/glsl/terrFeatureGLSL.cpp

@@ -64,6 +64,12 @@ MODULE_BEGIN( TerrainFeatGLSL )
 MODULE_END;
 
 
+TerrainFeatGLSL::TerrainFeatGLSL()
+   : mTorqueDep( "shaders/common/gl/torque.glsl" )
+   {      
+   addDependency( &mTorqueDep );
+   }
+
 Var* TerrainFeatGLSL::_getUniformVar( const char *name, const char *type, ConstantSortPosition csp )
 {
    Var *theVar = (Var*)LangElement::find( name );
@@ -262,6 +268,7 @@ void TerrainBaseMapFeatGLSL::processPix(  Vector<ShaderComponent*> &componentLis
    baseColor->setType( "vec4" );
    baseColor->setName( "baseColor" );
    meta->addStatement( new GenOp( "   @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) );
+   meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", baseColor, baseColor));
    meta->addStatement( new GenOp( "   @;\r\n", assignColor( baseColor, Material::Mul ) ) );
 
    output = meta;

+ 3 - 0
Engine/source/terrain/glsl/terrFeatureGLSL.h

@@ -36,7 +36,10 @@
 class TerrainFeatGLSL : public ShaderFeatureGLSL
 {
 protected:
+   ShaderIncludeDependency mTorqueDep;
    
+public:
+   TerrainFeatGLSL();
    Var* _getInDetailCoord(Vector<ShaderComponent*> &componentList );
    
    Var* _getInMacroCoord(Vector<ShaderComponent*> &componentList );

+ 7 - 0
Engine/source/terrain/hlsl/terrFeatureHLSL.cpp

@@ -64,6 +64,12 @@ MODULE_BEGIN( TerrainFeatHLSL )
 MODULE_END;
 
 
+TerrainFeatHLSL::TerrainFeatHLSL()
+   : mTorqueDep( "shaders/common/torque.hlsl" )
+   {      
+   addDependency( &mTorqueDep );
+   }
+
 Var* TerrainFeatHLSL::_getUniformVar( const char *name, const char *type, ConstantSortPosition csp )
 {
    Var *theVar = (Var*)LangElement::find( name );
@@ -262,6 +268,7 @@ void TerrainBaseMapFeatHLSL::processPix(  Vector<ShaderComponent*> &componentLis
    baseColor->setType( "float4" );
    baseColor->setName( "baseColor" );
    meta->addStatement( new GenOp( "   @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) );
+   meta->addStatement(new GenOp("   @ = toLinear(@);\r\n", baseColor, baseColor));
    meta->addStatement( new GenOp( "   @;\r\n", assignColor( baseColor, Material::Mul ) ) );
 
    output = meta;

+ 4 - 0
Engine/source/terrain/hlsl/terrFeatureHLSL.h

@@ -37,6 +37,10 @@ class TerrainFeatHLSL : public ShaderFeatureHLSL
 {
 protected:
 
+   ShaderIncludeDependency mTorqueDep;
+
+public:
+   TerrainFeatHLSL();
    Var* _getInDetailCoord(Vector<ShaderComponent*> &componentList );
 
    Var* _getInMacroCoord(Vector<ShaderComponent*> &componentList );

+ 1 - 0
Engine/source/util/imposterCapture.cpp

@@ -136,6 +136,7 @@ void ImposterCaptureMaterialHook::_overrideFeatures(  ProcessedMaterial *mat,
       fd.features.addFeature( MFT_NormalsOut );
 
    fd.features.addFeature( MFT_ForwardShading );
+   fd.features.addFeature( MFT_Imposter );
 }
 
 ImposterCaptureMaterialHook* ImposterCaptureMaterialHook::_getOrCreateHook( BaseMatInstance *inMat )

+ 169 - 47
Templates/Full/game/art/gui/optionsDlg.gui

@@ -33,7 +33,7 @@
       anchorLeft = "1";
       anchorRight = "0";
       position = "323 232";
-      extent = "377 303";
+      extent = "377 355";
       minExtent = "8 8";
       horizSizing = "center";
       vertSizing = "center";
@@ -51,7 +51,7 @@
          groupNum = "-1";
          buttonType = "PushButton";
          useMouseEvents = "0";
-         position = "306 271";
+         position = "304 319";
          extent = "60 23";
          minExtent = "8 8";
          horizSizing = "right";
@@ -179,47 +179,49 @@
             canSave = "1";
             canSaveDynamicFields = "0";
          };
-		 
-         new GuiSliderCtrl(OptMouseSensitivity) {  
-            range = "0.02 2";  
-            ticks = "10";  
-            value = "0.75";  
-            isContainer = "0";  
-            Profile = "GuiSliderProfile";  
-            HorizSizing = "right";  
-            VertSizing = "bottom";  
-            position = "105 182";  
-            Extent = "244 18";  
-            MinExtent = "8 2";  
-            canSave = "1";  
-            Visible = "1";  
-            Command = "OptMouseSetSensitivity(OptMouseSensitivity.value);";  
-            tooltipprofile = "GuiToolTipProfile";  
-            hovertime = "1000";  
-            canSaveDynamicFields = "0";  
-         };  
-         new GuiTextCtrl() {  
-            text = "Mouse Sensitivity:"; 
-            maxLength = "255";  
-            Margin = "0 0 0 0";  
-            Padding = "0 0 0 0";  
-            AnchorTop = "1";  
-            AnchorBottom = "0";  
-            AnchorLeft = "1";  
-            AnchorRight = "0";  
-            isContainer = "0";  
-            Profile = "GuiTextProfile";  
-            HorizSizing = "right";  
-            VertSizing = "bottom";  
-            position = "15 182";  
-            Extent = "85 18";  
-            MinExtent = "8 8";  
-            canSave = "1";  
-            Visible = "1";  
-            tooltipprofile = "GuiToolTipProfile";  
-            hovertime = "1000";  
-            canSaveDynamicFields = "0";  
-         };  
+         new GuiSliderCtrl(OptMouseSensitivity) {
+            range = "0.02 2";
+            ticks = "10";
+            snap = "0";
+            value = "1";
+            position = "105 182";
+            extent = "244 18";
+            minExtent = "8 2";
+            horizSizing = "right";
+            vertSizing = "bottom";
+            profile = "GuiSliderProfile";
+            visible = "1";
+            active = "1";
+            command = "OptMouseSetSensitivity(OptMouseSensitivity.value);";
+            tooltipProfile = "GuiToolTipProfile";
+            hovertime = "1000";
+            isContainer = "0";
+            canSave = "1";
+            canSaveDynamicFields = "0";
+         };
+         new GuiTextCtrl() {
+            text = "Mouse Sensitivity:";
+            maxLength = "255";
+            margin = "0 0 0 0";
+            padding = "0 0 0 0";
+            anchorTop = "1";
+            anchorBottom = "0";
+            anchorLeft = "1";
+            anchorRight = "0";
+            position = "15 182";
+            extent = "85 18";
+            minExtent = "8 8";
+            horizSizing = "right";
+            vertSizing = "bottom";
+            profile = "GuiTextProfile";
+            visible = "1";
+            active = "1";
+            tooltipProfile = "GuiToolTipProfile";
+            hovertime = "1000";
+            isContainer = "0";
+            canSave = "1";
+            canSaveDynamicFields = "0";
+         };
       };
       new GuiBitmapBorderCtrl() {
          position = "9 55";
@@ -601,7 +603,7 @@
       };
       new GuiBitmapBorderCtrl() {
          position = "9 55";
-         extent = "358 210";
+         extent = "358 252";
          minExtent = "8 8";
          horizSizing = "right";
          vertSizing = "bottom";
@@ -1253,7 +1255,7 @@
             canSaveDynamicFields = "0";
          };
          new GuiControl() {
-            position = "0 190";
+            position = "0 227";
             extent = "352 15";
             minExtent = "8 2";
             horizSizing = "width";
@@ -1269,7 +1271,7 @@
             canSaveDynamicFields = "0";
 
             new GuiSliderCtrl() {
-               range = "0.001 2.2";
+               range = "0.5 1.5";
                ticks = "0";
                snap = "0";
                value = "1";
@@ -1281,6 +1283,66 @@
                profile = "GuiSliderProfile";
                visible = "1";
                active = "1";
+               variable = "$pref::Video::Contrast";
+               tooltipProfile = "GuiToolTipProfile";
+               hovertime = "1000";
+               isContainer = "0";
+               canSave = "1";
+               canSaveDynamicFields = "0";
+            };
+            new GuiTextCtrl() {
+               text = "Contrast:";
+               maxLength = "255";
+               margin = "0 0 0 0";
+               padding = "0 0 0 0";
+               anchorTop = "1";
+               anchorBottom = "0";
+               anchorLeft = "1";
+               anchorRight = "0";
+               position = "18 -4";
+               extent = "105 18";
+               minExtent = "8 2";
+               horizSizing = "right";
+               vertSizing = "bottom";
+               profile = "GuiTextProfile";
+               visible = "1";
+               active = "1";
+               tooltipProfile = "GuiToolTipProfile";
+               hovertime = "1000";
+               isContainer = "0";
+               canSave = "1";
+               canSaveDynamicFields = "0";
+            };
+         };
+         new GuiControl() {
+            position = "0 190";
+            extent = "352 15";
+            minExtent = "8 2";
+            horizSizing = "width";
+            vertSizing = "bottom";
+            profile = "GuiDefaultProfile";
+            visible = "1";
+            active = "1";
+            tooltipProfile = "GuiToolTipProfile";
+            hovertime = "1000";
+            isContainer = "1";
+            internalName = "GammaSliderContainer";
+            canSave = "1";
+            canSaveDynamicFields = "0";
+
+            new GuiSliderCtrl() {
+               range = "2.0 2.5";
+               ticks = "0";
+               snap = "0";
+               value = "2.2";
+               position = "76 -1";
+               extent = "268 15";
+               minExtent = "8 2";
+               horizSizing = "right";
+               vertSizing = "bottom";
+               profile = "GuiSliderProfile";
+               visible = "1";
+               active = "1";
                variable = "$pref::Video::Gamma";
                tooltipProfile = "GuiToolTipProfile";
                hovertime = "1000";
@@ -1312,6 +1374,66 @@
                canSaveDynamicFields = "0";
             };
          };
+         new GuiControl() {
+            position = "0 208";
+            extent = "352 15";
+            minExtent = "8 2";
+            horizSizing = "width";
+            vertSizing = "bottom";
+            profile = "GuiDefaultProfile";
+            visible = "1";
+            active = "1";
+            tooltipProfile = "GuiToolTipProfile";
+            hovertime = "1000";
+            isContainer = "1";
+            internalName = "GammaSliderContainer";
+            canSave = "1";
+            canSaveDynamicFields = "0";
+
+            new GuiSliderCtrl() {
+               range = "-0.5 0.5";
+               ticks = "0";
+               snap = "0";
+               value = "0";
+               position = "76 -1";
+               extent = "268 15";
+               minExtent = "8 2";
+               horizSizing = "right";
+               vertSizing = "bottom";
+               profile = "GuiSliderProfile";
+               visible = "1";
+               active = "1";
+               variable = "$pref::Video::Brightness";
+               tooltipProfile = "GuiToolTipProfile";
+               hovertime = "1000";
+               isContainer = "0";
+               canSave = "1";
+               canSaveDynamicFields = "0";
+            };
+            new GuiTextCtrl() {
+               text = "Brightness:";
+               maxLength = "255";
+               margin = "0 0 0 0";
+               padding = "0 0 0 0";
+               anchorTop = "1";
+               anchorBottom = "0";
+               anchorLeft = "1";
+               anchorRight = "0";
+               position = "6 -3";
+               extent = "105 18";
+               minExtent = "8 2";
+               horizSizing = "right";
+               vertSizing = "bottom";
+               profile = "GuiTextProfile";
+               visible = "1";
+               active = "1";
+               tooltipProfile = "GuiToolTipProfile";
+               hovertime = "1000";
+               isContainer = "0";
+               canSave = "1";
+               canSaveDynamicFields = "0";
+            };
+         };
       };
       new GuiControl() {
          position = "9 55";
@@ -1396,7 +1518,7 @@
          groupNum = "-1";
          buttonType = "PushButton";
          useMouseEvents = "0";
-         position = "241 271";
+         position = "239 319";
          extent = "60 23";
          minExtent = "8 8";
          horizSizing = "right";

+ 3 - 1
Templates/Full/game/core/scripts/client/defaults.cs

@@ -73,7 +73,9 @@ $pref::Video::disableCubemapping = false;
 ///
 $pref::Video::disableParallaxMapping = false;
 
-$pref::Video::Gamma = 1.0;
+$pref::Video::Gamma = 2.2;
+$pref::Video::Contrast = 1.0;
+$pref::Video::Brightness = 0;
 
 // Console-friendly defaults
 if($platform $= "xenon")

+ 4 - 2
Templates/Full/game/core/scripts/client/postFx/GammaPostFX.cs

@@ -44,7 +44,7 @@ singleton GFXStateBlockData( GammaStateBlock : PFX_DefaultStateBlock )
 singleton PostEffect( GammaPostFX )
 {
    isEnabled = true;
-   allowReflectPass = false;
+   allowReflectPass = true;
    
    renderTime = "PFXBeforeBin";
    renderBin = "EditorBin";
@@ -65,6 +65,8 @@ function GammaPostFX::preProcess( %this )
 
 function GammaPostFX::setShaderConsts( %this )
 {
-   %clampedGamma  = mClamp( $pref::Video::Gamma, 0.001, 2.2);
+   %clampedGamma  = mClamp( $pref::Video::Gamma, 2.0, 2.5);
    %this.setShaderConst( "$OneOverGamma", 1 / %clampedGamma );
+   %this.setShaderConst( "$Brightness", $pref::Video::Brightness );
+   %this.setShaderConst( "$Contrast", $pref::Video::Contrast );
 }

+ 13 - 2
Templates/Full/game/core/scripts/client/postFx/hdr.cs

@@ -253,8 +253,10 @@ function HDRPostFX::setShaderConsts( %this )
    %combinePass.setShaderConst( "$g_fEnableBlueShift", $HDRPostFX::enableBlueShift );   
    %combinePass.setShaderConst( "$g_fBlueShiftColor", $HDRPostFX::blueShiftColor );   
    
-   %clampedGamma  = mClamp( $pref::Video::Gamma, 0.001, 2.2);
+   %clampedGamma  = mClamp( $pref::Video::Gamma, 2.0, 2.5);
    %combinePass.setShaderConst( "$g_fOneOverGamma",  1 / %clampedGamma );       
+   %combinePass.setShaderConst( "$Brightness", $pref::Video::Brightness );
+   %combinePass.setShaderConst( "$Contrast", $pref::Video::Contrast );
 
    %whiteCutoff = ( $HDRPostFX::whiteCutoff * $HDRPostFX::whiteCutoff ) *
                   ( $HDRPostFX::whiteCutoff * $HDRPostFX::whiteCutoff );                  
@@ -329,7 +331,7 @@ function HDRPostFX::onDisabled( %this )
 singleton PostEffect( HDRPostFX )
 {
    isEnabled = false;
-   allowReflectPass = false;
+   allowReflectPass = true;
       
    // Resolve the HDR before we render any editor stuff
    // and before we resolve the scene to the backbuffer.
@@ -355,6 +357,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
+         allowReflectPass = true;
          shader = HDR_DownScale4x4Shader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -365,6 +368,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
+         allowReflectPass = true;
          internalName = "bloomH";
          
          shader = HDR_BloomGaussBlurHShader;
@@ -376,6 +380,7 @@ singleton PostEffect( HDRPostFX )
 
       new PostEffect()
       {
+         allowReflectPass = true;
          internalName = "bloomV";
                   
          shader = HDR_BloomGaussBlurVShader;
@@ -390,6 +395,7 @@ singleton PostEffect( HDRPostFX )
    // Now calculate the adapted luminance.
    new PostEffect()
    {
+      allowReflectPass = true;
       internalName = "adaptLum";
       
       shader = HDR_SampleLumShader;
@@ -401,6 +407,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
+         allowReflectPass = true;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -411,6 +418,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
+         allowReflectPass = true;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -421,6 +429,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
+         allowReflectPass = true;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -434,6 +443,7 @@ singleton PostEffect( HDRPostFX )
       // one... PostEffect takes care to manage that.
       new PostEffect()
       {
+         allowReflectPass = true;
          internalName = "finalLum";         
          shader = HDR_CalcAdaptedLumShader;
          stateBlock = HDR_DownSampleStateBlock;
@@ -450,6 +460,7 @@ singleton PostEffect( HDRPostFX )
    // version of the scene.
    new PostEffect()
    {
+      allowReflectPass = true;
       internalName = "combinePass";
       
       shader = HDR_CombineShader;

+ 17 - 16
Templates/Full/game/core/scripts/client/renderManager.cs

@@ -33,7 +33,7 @@ function initRenderManager()
    {
       enabled = "false";
       
-      format = "GFXFormatR8G8B8A8";
+      format = "GFXFormatR16G16B16A16F";
       depthFormat = "GFXFormatD24S8";
       aaLevel = 0; // -1 = match backbuffer
       
@@ -49,20 +49,21 @@ function initRenderManager()
      
    // We really need to fix the sky to render after all the 
    // meshes... but that causes issues in reflections.
-   DiffuseRenderPassManager.addManager( new RenderObjectMgr() { bintype = "Sky"; renderOrder = 0.1; processAddOrder = 0.1; } );
+   DiffuseRenderPassManager.addManager( new RenderObjectMgr(SkyBin) { bintype = "Sky"; renderOrder = 0.1; processAddOrder = 0.1; } );
    
    //DiffuseRenderPassManager.addManager( new RenderVistaMgr()               { bintype = "Vista"; renderOrder = 0.15; processAddOrder = 0.15; } );
    
-   DiffuseRenderPassManager.addManager( new RenderObjectMgr()              { bintype = "Begin"; renderOrder = 0.2; processAddOrder = 0.2; } );
+   DiffuseRenderPassManager.addManager( new RenderObjectMgr(BeginBin)      { bintype = "Begin"; renderOrder = 0.2; processAddOrder = 0.2; } );
    // Normal mesh rendering.
-   DiffuseRenderPassManager.addManager( new RenderTerrainMgr()             { renderOrder = 0.4; processAddOrder = 0.4; } );
-   DiffuseRenderPassManager.addManager( new RenderMeshMgr()                { bintype = "Mesh"; renderOrder = 0.5; processAddOrder = 0.5; } );
-   DiffuseRenderPassManager.addManager( new RenderImposterMgr()            { renderOrder = 0.56; processAddOrder = 0.56; } );
-   DiffuseRenderPassManager.addManager( new RenderObjectMgr()              { bintype = "Object"; renderOrder = 0.6; processAddOrder = 0.6; } );
-     
-   DiffuseRenderPassManager.addManager( new RenderObjectMgr()              { bintype = "Shadow"; renderOrder = 0.7; processAddOrder = 0.7; } );
-   DiffuseRenderPassManager.addManager( new RenderMeshMgr()                { bintype = "Decal"; renderOrder = 0.8; processAddOrder = 0.8; } );
-   DiffuseRenderPassManager.addManager( new RenderOcclusionMgr()           { bintype = "Occluder"; renderOrder = 0.9; processAddOrder = 0.9; } );
+   DiffuseRenderPassManager.addManager( new RenderTerrainMgr(TerrainBin)   { renderOrder = 0.4; processAddOrder = 0.4; } );
+   DiffuseRenderPassManager.addManager( new RenderMeshMgr(MeshBin)         { bintype = "Mesh"; renderOrder = 0.5; processAddOrder = 0.5; } );
+   DiffuseRenderPassManager.addManager( new RenderImposterMgr(ImposterBin) { renderOrder = 0.56; processAddOrder = 0.56; } );
+   DiffuseRenderPassManager.addManager( new RenderObjectMgr(ObjectBin)     { bintype = "Object"; renderOrder = 0.6; processAddOrder = 0.6; } );
+
+   DiffuseRenderPassManager.addManager( new RenderObjectMgr(ShadowBin)     { bintype = "Shadow"; renderOrder = 0.7; processAddOrder = 0.7; } );
+   DiffuseRenderPassManager.addManager( new RenderMeshMgr(DecalRoadBin)    { bintype = "DecalRoad"; renderOrder = 0.8; processAddOrder = 0.8; } );
+   DiffuseRenderPassManager.addManager( new RenderMeshMgr(DecalBin)        { bintype = "Decal"; renderOrder = 0.81; processAddOrder = 0.81; } );
+   DiffuseRenderPassManager.addManager( new RenderOcclusionMgr(OccluderBin){ bintype = "Occluder"; renderOrder = 0.9; processAddOrder = 0.9; } );
      
    // We now render translucent objects that should handle
    // their own fogging and lighting.
@@ -70,10 +71,10 @@ function initRenderManager()
    // Note that the fog effect is triggered before this bin.
    DiffuseRenderPassManager.addManager( new RenderObjectMgr(ObjTranslucentBin) { bintype = "ObjectTranslucent"; renderOrder = 1.0; processAddOrder = 1.0; } );
          
-   DiffuseRenderPassManager.addManager( new RenderObjectMgr()              { bintype = "Water"; renderOrder = 1.2; processAddOrder = 1.2; } );
-   DiffuseRenderPassManager.addManager( new RenderObjectMgr()              { bintype = "Foliage"; renderOrder = 1.3; processAddOrder = 1.3; } );
-	DiffuseRenderPassManager.addManager( new RenderParticleMgr()            { renderOrder = 1.35; processAddOrder = 1.35; } );
-   DiffuseRenderPassManager.addManager( new RenderTranslucentMgr()         { renderOrder = 1.4; processAddOrder = 1.4; } );
+   DiffuseRenderPassManager.addManager( new RenderObjectMgr(WaterBin)          { bintype = "Water"; renderOrder = 1.2; processAddOrder = 1.2; } );
+   DiffuseRenderPassManager.addManager( new RenderObjectMgr(FoliageBin)        { bintype = "Foliage"; renderOrder = 1.3; processAddOrder = 1.3; } );
+	DiffuseRenderPassManager.addManager( new RenderParticleMgr(ParticleBin)    { renderOrder = 1.35; processAddOrder = 1.35; } );
+   DiffuseRenderPassManager.addManager( new RenderTranslucentMgr(TranslucentBin){ renderOrder = 1.4; processAddOrder = 1.4; } );
    
    DiffuseRenderPassManager.addManager(new RenderObjectMgr(FogBin){ bintype = "ObjectVolumetricFog"; renderOrder = 1.45; processAddOrder = 1.45; } );
    
@@ -85,7 +86,7 @@ function initRenderManager()
    DiffuseRenderPassManager.addManager( new RenderObjectMgr(EditorBin) { bintype = "Editor"; renderOrder = 1.6; processAddOrder = 1.6; } );
                
    // Resolve format change token last.
-   DiffuseRenderPassManager.addManager( new RenderPassStateBin() { renderOrder = 1.7; stateToken = AL_FormatToken; } );
+   DiffuseRenderPassManager.addManager( new RenderPassStateBin(FinalBin)       { renderOrder = 1.7; stateToken = AL_FormatToken; } );
 }
 
 /// This post effect is used to copy data from the non-MSAA back-buffer to the

+ 33 - 0
Templates/Full/game/shaders/common/gl/torque.glsl

@@ -284,4 +284,37 @@ void fizzle(vec2 vpos, float visibility)
 /// @note This macro will only work in the void main() method of a pixel shader.
 #define assert(condition, color) { if(!any(condition)) { OUT_col = color; return; } }
 
+// Deferred Shading: Material Info Flag Check
+bool getFlag(float flags, int num)
+{
+   float process = round(flags * 255);
+   float squareNum = pow(2, num);
+   return (mod(process, pow(2, squareNum)) >= squareNum); 
+}
+
+// #define TORQUE_STOCK_GAMMA
+#ifdef TORQUE_STOCK_GAMMA
+// Sample in linear space. Decodes gamma.
+vec4 toLinear(vec4 tex)
+{
+   return tex;
+}
+// Encodes gamma.
+vec4 toGamma(vec4 tex)
+{
+   return tex;
+}
+#else
+// Sample in linear space. Decodes gamma.
+vec4 toLinear(vec4 tex)
+{
+   return vec4(pow(abs(tex.rgb), vec3(2.2)), tex.a);
+}
+// Encodes gamma.
+vec4 toGamma(vec4 tex)
+{
+   return vec4(pow(abs(tex.rgb), vec3(1.0/2.2)), tex.a);
+}
+#endif //
+
 #endif // _TORQUE_GLSL_

+ 8 - 1
Templates/Full/game/shaders/common/postFx/gammaP.hlsl

@@ -28,7 +28,8 @@ uniform sampler2D backBuffer : register(S0);
 uniform sampler1D colorCorrectionTex : register( s1 );
 
 uniform float OneOverGamma;
-
+uniform float Brightness;
+uniform float Contrast;
 
 float4 main( PFXVertToPix IN ) : COLOR0  
 {
@@ -42,5 +43,11 @@ float4 main( PFXVertToPix IN ) : COLOR0
    // Apply gamma correction
     color.rgb = pow( abs(color.rgb), OneOverGamma );
 
+   // Apply contrast
+   color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f;
+ 
+   // Apply brightness
+   color.rgb += Brightness;
+
     return color;    
 }

+ 8 - 0
Templates/Full/game/shaders/common/postFx/gl/gammaP.glsl

@@ -28,6 +28,8 @@ uniform sampler2D backBuffer;
 uniform sampler1D colorCorrectionTex;
 
 uniform float OneOverGamma;
+uniform float Brightness;
+uniform float Contrast;
 
 in vec2 uv0;
 
@@ -45,5 +47,11 @@ void main()
    // Apply gamma correction
    color.rgb = pow( abs(color.rgb), vec3(OneOverGamma) );
 
+   // Apply contrast
+   color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f;
+ 
+   // Apply brightness
+   color.rgb += Brightness;
+   
    OUT_col = color;
 }

+ 8 - 0
Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl

@@ -41,6 +41,8 @@ uniform float3 g_fBlueShiftColor;
 uniform float g_fBloomScale;
 
 uniform float g_fOneOverGamma;
+uniform float Brightness;
+uniform float Contrast;
 
 
 float4 main( PFXVertToPix IN ) : COLOR0
@@ -90,6 +92,12 @@ float4 main( PFXVertToPix IN ) : COLOR0
 
    // Apply gamma correction
    sample.rgb = pow( abs(sample.rgb), g_fOneOverGamma );
+ 
+   // Apply contrast
+   sample.rgb = ((sample.rgb - 0.5f) * Contrast) + 0.5f;
+ 
+   // Apply brightness
+   sample.rgb += Brightness;
 
    return sample;
 }

+ 8 - 0
Templates/Full/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl

@@ -42,6 +42,8 @@ uniform vec3 g_fBlueShiftColor;
 uniform float g_fBloomScale;
 
 uniform float g_fOneOverGamma;
+uniform float Brightness;
+uniform float Contrast;
 
 out vec4 OUT_col;
 
@@ -93,6 +95,12 @@ void main()
 
    // Apply gamma correction
    _sample.rgb = pow( abs(_sample.rgb), vec3(g_fOneOverGamma) );
+   
+   // Apply contrast
+   _sample.rgb = ((_sample.rgb - 0.5f) * Contrast) + 0.5f;
+ 
+   // Apply brightness
+   _sample.rgb += Brightness;
 
    OUT_col = _sample;
 }

+ 32 - 0
Templates/Full/game/shaders/common/torque.hlsl

@@ -277,5 +277,37 @@ void fizzle(float2 vpos, float visibility)
    clip( visibility - frac( determinant( m ) ) );
 }
 
+// Deferred Shading: Material Info Flag Check
+bool getFlag(float flags, int num)
+{
+   int process = round(flags * 255);
+   int squareNum = pow(2, num);
+   return (fmod(process, pow(2, squareNum)) >= squareNum); 
+}
+
+// #define TORQUE_STOCK_GAMMA
+#ifdef TORQUE_STOCK_GAMMA
+// Sample in linear space. Decodes gamma.
+float4 toLinear(float4 tex)
+{
+   return tex;
+}
+// Encodes gamma.
+float4 toLinear(float4 tex)
+{
+   return tex;
+}
+#else
+// Sample in linear space. Decodes gamma.
+float4 toLinear(float4 tex)
+{
+   return float4(pow(abs(tex.rgb), 2.2), tex.a);
+}
+// Encodes gamma.
+float4 toGamma(float4 tex)
+{
+   return float4(pow(abs(tex.rgb), 1.0/2.2), tex.a);
+}
+#endif //
 
 #endif // _TORQUE_HLSL_

+ 1 - 0
Templates/Full/game/shaders/common/water/gl/waterBasicP.glsl

@@ -120,6 +120,7 @@ void main()
 { 
    // Modulate baseColor by the ambientColor.
    vec4 waterBaseColor = baseColor * vec4( ambientColor.rgb, 1 );
+   waterBaseColor = toLinear(waterBaseColor);
    
    // Get the bumpNorm...
    vec3 bumpNorm = ( texture( bumpMap, IN_rippleTexCoord01.xy ).rgb * 2.0 - 1.0 ) * rippleMagnitude.x;

+ 1 - 0
Templates/Full/game/shaders/common/water/gl/waterP.glsl

@@ -324,6 +324,7 @@ void main()
    
    // Calculate the water "base" color based on depth.
    vec4 waterBaseColor = baseColor * texture( depthGradMap, saturate( delta / depthGradMax ) );
+   waterBaseColor = toLinear(waterBaseColor);
       
    // Modulate baseColor by the ambientColor.
    waterBaseColor *= vec4( ambientColor.rgb, 1 );     

+ 1 - 0
Templates/Full/game/shaders/common/water/waterBasicP.hlsl

@@ -117,6 +117,7 @@ float4 main( ConnectData IN ) : COLOR
 { 
    // Modulate baseColor by the ambientColor.
    float4 waterBaseColor = baseColor * float4( ambientColor.rgb, 1 );
+   waterBaseColor = toLinear(waterBaseColor);
    
    // Get the bumpNorm...
    float3 bumpNorm = ( tex2D( bumpMap, IN.rippleTexCoord01.xy ).rgb * 2.0 - 1.0 ) * rippleMagnitude.x;

+ 1 - 0
Templates/Full/game/shaders/common/water/waterP.hlsl

@@ -311,6 +311,7 @@ float4 main( ConnectData IN ) : COLOR
    
    // Calculate the water "base" color based on depth.
    float4 waterBaseColor = baseColor * tex1D( depthGradMap, saturate( delta / depthGradMax ) );
+   waterBaseColor = toLinear(waterBaseColor);
       
    // Modulate baseColor by the ambientColor.
    waterBaseColor *= float4( ambientColor.rgb, 1 );