فهرست منبع

Merge pull request #1887 from Azaezel/hdrCleanups

HDR review: remove from reflections, kill depth check, order of ops
Areloch 8 سال پیش
والد
کامیت
50c856f797

+ 14 - 15
Templates/Empty/game/core/scripts/client/postFx/hdr.cs

@@ -22,7 +22,7 @@
 
 
 /// Blends between the scene and the tone mapped scene.
-$HDRPostFX::enableToneMapping = 1.0;
+$HDRPostFX::enableToneMapping = 0.5;
 
 /// The tone mapping middle grey or exposure value used
 /// to adjust the overall "balance" of the image.
@@ -318,7 +318,7 @@ function HDRPostFX::onDisabled( %this )
    GammaPostFX.enable();
    
    // Restore the non-HDR offscreen surface format.
-   %format = "GFXFormatR8G8B8A8";
+   %format = getBestHDRFormat();
    AL_FormatToken.format = %format;
    setReflectFormat( %format );
    
@@ -333,8 +333,8 @@ function HDRPostFX::onDisabled( %this )
 singleton PostEffect( HDRPostFX )
 {
    isEnabled = false;
-   allowReflectPass = true;
-      
+   allowReflectPass = false;
+
    // Resolve the HDR before we render any editor stuff
    // and before we resolve the scene to the backbuffer.
    renderTime = "PFXBeforeBin";
@@ -359,7 +359,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          shader = HDR_DownScale4x4Shader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -370,7 +370,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          internalName = "bloomH";
          
          shader = HDR_BloomGaussBlurHShader;
@@ -382,7 +382,7 @@ singleton PostEffect( HDRPostFX )
 
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          internalName = "bloomV";
                   
          shader = HDR_BloomGaussBlurVShader;
@@ -397,7 +397,7 @@ singleton PostEffect( HDRPostFX )
    // Now calculate the adapted luminance.
    new PostEffect()
    {
-      allowReflectPass = true;
+      allowReflectPass = false;
       internalName = "adaptLum";
       
       shader = HDR_SampleLumShader;
@@ -409,7 +409,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -420,7 +420,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -431,7 +431,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -445,8 +445,8 @@ singleton PostEffect( HDRPostFX )
       // one... PostEffect takes care to manage that.
       new PostEffect()
       {
-         allowReflectPass = true;
-         internalName = "finalLum";         
+         allowReflectPass = false;
+         internalName = "finalLum";
          shader = HDR_CalcAdaptedLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -462,7 +462,7 @@ singleton PostEffect( HDRPostFX )
    // version of the scene.
    new PostEffect()
    {
-      allowReflectPass = true;
+      allowReflectPass = false;
       internalName = "combinePass";
       
       shader = HDR_CombineShader;
@@ -471,7 +471,6 @@ singleton PostEffect( HDRPostFX )
       texture[1] = "#adaptedLum";            
       texture[2] = "#bloomFinal";
       texture[3] = $HDRPostFX::colorCorrectionRamp;
-      texture[4] = "#prepass";
       target = "$backBuffer";
    };
 };

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

@@ -41,7 +41,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
    color.b = TORQUE_TEX1D( colorCorrectionTex, color.b ).b;
 
    // Apply gamma correction
-    color.rgb = pow( abs(color.rgb), OneOverGamma );
+    color.rgb = pow( saturate(color.rgb), OneOverGamma );
 
    // Apply contrast
    color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f;

+ 1 - 1
Templates/Empty/game/shaders/common/postFx/gl/gammaP.glsl

@@ -45,7 +45,7 @@ void main()
    color.b = texture( colorCorrectionTex, color.b ).b;
 
    // Apply gamma correction
-   color.rgb = pow( abs(color.rgb), vec3(OneOverGamma) );
+   color.rgb = pow( clamp(color.rgb, vec3(0.0),vec3(1.0)), vec3(OneOverGamma) );
 
    // Apply contrast
    color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f;

+ 4 - 9
Templates/Empty/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl

@@ -28,7 +28,6 @@ TORQUE_UNIFORM_SAMPLER2D(sceneTex, 0);
 TORQUE_UNIFORM_SAMPLER2D(luminanceTex, 1);
 TORQUE_UNIFORM_SAMPLER2D(bloomTex, 2);
 TORQUE_UNIFORM_SAMPLER1D(colorCorrectionTex, 3);
-TORQUE_UNIFORM_SAMPLER2D(prepassTex, 4);
 
 uniform float2 texSize0;
 uniform float2 texSize2;
@@ -40,7 +39,6 @@ uniform float g_fEnableBlueShift;
 
 uniform float3 g_fBlueShiftColor;
 uniform float g_fBloomScale;
-
 uniform float g_fOneOverGamma;
 uniform float Brightness;
 uniform float Contrast;
@@ -71,6 +69,9 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
       bloom.rgb = lerp( bloom.rgb, rodColor, coef );
    }
 
+   // Add the bloom effect.
+   sample += g_fBloomScale * bloom;
+   
    // Map the high range of color values into a range appropriate for
    // display, taking into account the user's adaptation level, 
    // white point, and selected value for for middle gray.
@@ -82,19 +83,13 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
       sample.rgb = lerp( sample.rgb, sample.rgb * toneScalar, g_fEnableToneMapping );
    }
 
-   // Add the bloom effect.
-   float depth = TORQUE_PREPASS_UNCONDITION( prepassTex, IN.uv0 ).w;
-   if (depth>0.9999)
-      sample += g_fBloomScale * bloom;
-
    // Apply the color correction.
    sample.r = TORQUE_TEX1D( colorCorrectionTex, sample.r ).r;
    sample.g = TORQUE_TEX1D( colorCorrectionTex, sample.g ).g;
    sample.b = TORQUE_TEX1D( colorCorrectionTex, sample.b ).b;
-
 	  
    // Apply gamma correction
-   sample.rgb = pow( abs(sample.rgb), g_fOneOverGamma );
+   sample.rgb = pow( saturate(sample.rgb), g_fOneOverGamma );
  
    // Apply contrast
    sample.rgb = ((sample.rgb - 0.5f) * Contrast) + 0.5f;

+ 4 - 8
Templates/Empty/game/shaders/common/postFx/hdr/gl/finalPassCombineP.glsl

@@ -29,7 +29,6 @@ uniform sampler2D sceneTex;
 uniform sampler2D luminanceTex;
 uniform sampler2D bloomTex;
 uniform sampler1D colorCorrectionTex;
-uniform sampler2D prepassTex;
 
 uniform vec2 texSize0;
 uniform vec2 texSize2;
@@ -49,7 +48,6 @@ uniform float Contrast;
 
 out vec4 OUT_col;
 
-
 void main()
 {
    vec4 _sample = hdrDecode( texture( sceneTex, IN_uv0 ) );
@@ -76,6 +74,9 @@ void main()
       bloom.rgb = mix( bloom.rgb, rodColor, coef );
    }
 
+   // Add the bloom effect.
+   _sample += g_fBloomScale * bloom;
+   
    // Map the high range of color values into a range appropriate for
    // display, taking into account the user's adaptation level, 
    // white point, and selected value for for middle gray.
@@ -87,18 +88,13 @@ void main()
       _sample.rgb = mix( _sample.rgb, _sample.rgb * toneScalar, g_fEnableToneMapping );
    }
 
-   // Add the bloom effect.
-   float depth = prepassUncondition( prepassTex, IN_uv0 ).w;
-   if (depth>0.9999)
-      _sample += g_fBloomScale * bloom;
-
    // Apply the color correction.
    _sample.r = texture( colorCorrectionTex, _sample.r ).r;
    _sample.g = texture( colorCorrectionTex, _sample.g ).g;
    _sample.b = texture( colorCorrectionTex, _sample.b ).b;
 
    // Apply gamma correction
-   _sample.rgb = pow( abs(_sample.rgb), vec3(g_fOneOverGamma) );
+   _sample.rgb = pow( _sample.rgb, vec3(g_fOneOverGamma) );
    
    // Apply contrast
    _sample.rgb = ((_sample.rgb - 0.5f) * Contrast) + 0.5f;

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

@@ -22,7 +22,7 @@
 
 
 /// Blends between the scene and the tone mapped scene.
-$HDRPostFX::enableToneMapping = 1.0;
+$HDRPostFX::enableToneMapping = 0.5;
 
 /// The tone mapping middle grey or exposure value used
 /// to adjust the overall "balance" of the image.
@@ -333,8 +333,8 @@ function HDRPostFX::onDisabled( %this )
 singleton PostEffect( HDRPostFX )
 {
    isEnabled = false;
-   allowReflectPass = true;
-      
+   allowReflectPass = false;
+
    // Resolve the HDR before we render any editor stuff
    // and before we resolve the scene to the backbuffer.
    renderTime = "PFXBeforeBin";
@@ -359,7 +359,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          shader = HDR_DownScale4x4Shader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -370,7 +370,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          internalName = "bloomH";
          
          shader = HDR_BloomGaussBlurHShader;
@@ -382,7 +382,7 @@ singleton PostEffect( HDRPostFX )
 
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          internalName = "bloomV";
                   
          shader = HDR_BloomGaussBlurVShader;
@@ -397,7 +397,7 @@ singleton PostEffect( HDRPostFX )
    // Now calculate the adapted luminance.
    new PostEffect()
    {
-      allowReflectPass = true;
+      allowReflectPass = false;
       internalName = "adaptLum";
       
       shader = HDR_SampleLumShader;
@@ -409,7 +409,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -420,7 +420,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -431,7 +431,7 @@ singleton PostEffect( HDRPostFX )
       
       new PostEffect()
       {
-         allowReflectPass = true;
+         allowReflectPass = false;
          shader = HDR_DownSampleLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -445,8 +445,8 @@ singleton PostEffect( HDRPostFX )
       // one... PostEffect takes care to manage that.
       new PostEffect()
       {
-         allowReflectPass = true;
-         internalName = "finalLum";         
+         allowReflectPass = false;
+         internalName = "finalLum";
          shader = HDR_CalcAdaptedLumShader;
          stateBlock = HDR_DownSampleStateBlock;
          texture[0] = "$inTex";
@@ -462,7 +462,7 @@ singleton PostEffect( HDRPostFX )
    // version of the scene.
    new PostEffect()
    {
-      allowReflectPass = true;
+      allowReflectPass = false;
       internalName = "combinePass";
       
       shader = HDR_CombineShader;
@@ -471,7 +471,6 @@ singleton PostEffect( HDRPostFX )
       texture[1] = "#adaptedLum";            
       texture[2] = "#bloomFinal";
       texture[3] = $HDRPostFX::colorCorrectionRamp;
-      texture[4] = "#prepass";
       target = "$backBuffer";
    };
 };

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

@@ -41,7 +41,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
    color.b = TORQUE_TEX1D( colorCorrectionTex, color.b ).b;
 
    // Apply gamma correction
-    color.rgb = pow( abs(color.rgb), OneOverGamma );
+    color.rgb = pow( saturate(color.rgb), OneOverGamma );
 
    // Apply contrast
    color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f;

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

@@ -45,7 +45,7 @@ void main()
    color.b = texture( colorCorrectionTex, color.b ).b;
 
    // Apply gamma correction
-   color.rgb = pow( abs(color.rgb), vec3(OneOverGamma) );
+   color.rgb = pow( clamp(color.rgb, vec3(0.0),vec3(1.0)), vec3(OneOverGamma) );
 
    // Apply contrast
    color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f;

+ 4 - 9
Templates/Full/game/shaders/common/postFx/hdr/finalPassCombineP.hlsl

@@ -28,7 +28,6 @@ TORQUE_UNIFORM_SAMPLER2D(sceneTex, 0);
 TORQUE_UNIFORM_SAMPLER2D(luminanceTex, 1);
 TORQUE_UNIFORM_SAMPLER2D(bloomTex, 2);
 TORQUE_UNIFORM_SAMPLER1D(colorCorrectionTex, 3);
-TORQUE_UNIFORM_SAMPLER2D(prepassTex, 4);
 
 uniform float2 texSize0;
 uniform float2 texSize2;
@@ -40,7 +39,6 @@ uniform float g_fEnableBlueShift;
 
 uniform float3 g_fBlueShiftColor;
 uniform float g_fBloomScale;
-
 uniform float g_fOneOverGamma;
 uniform float Brightness;
 uniform float Contrast;
@@ -71,6 +69,9 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
       bloom.rgb = lerp( bloom.rgb, rodColor, coef );
    }
 
+   // Add the bloom effect.
+   sample += g_fBloomScale * bloom;
+   
    // Map the high range of color values into a range appropriate for
    // display, taking into account the user's adaptation level, 
    // white point, and selected value for for middle gray.
@@ -82,19 +83,13 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
       sample.rgb = lerp( sample.rgb, sample.rgb * toneScalar, g_fEnableToneMapping );
    }
 
-   // Add the bloom effect.
-   float depth = TORQUE_PREPASS_UNCONDITION( prepassTex, IN.uv0 ).w;
-   if (depth>0.9999)
-      sample += g_fBloomScale * bloom;
-
    // Apply the color correction.
    sample.r = TORQUE_TEX1D( colorCorrectionTex, sample.r ).r;
    sample.g = TORQUE_TEX1D( colorCorrectionTex, sample.g ).g;
    sample.b = TORQUE_TEX1D( colorCorrectionTex, sample.b ).b;
-
 	  
    // Apply gamma correction
-   sample.rgb = pow( abs(sample.rgb), g_fOneOverGamma );
+   sample.rgb = pow( saturate(sample.rgb), g_fOneOverGamma );
  
    // Apply contrast
    sample.rgb = ((sample.rgb - 0.5f) * Contrast) + 0.5f;

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

@@ -29,7 +29,6 @@ uniform sampler2D sceneTex;
 uniform sampler2D luminanceTex;
 uniform sampler2D bloomTex;
 uniform sampler1D colorCorrectionTex;
-uniform sampler2D prepassTex;
 
 uniform vec2 texSize0;
 uniform vec2 texSize2;
@@ -49,7 +48,6 @@ uniform float Contrast;
 
 out vec4 OUT_col;
 
-
 void main()
 {
    vec4 _sample = hdrDecode( texture( sceneTex, IN_uv0 ) );
@@ -76,6 +74,9 @@ void main()
       bloom.rgb = mix( bloom.rgb, rodColor, coef );
    }
 
+   // Add the bloom effect.
+   _sample += g_fBloomScale * bloom;
+   
    // Map the high range of color values into a range appropriate for
    // display, taking into account the user's adaptation level, 
    // white point, and selected value for for middle gray.
@@ -87,18 +88,13 @@ void main()
       _sample.rgb = mix( _sample.rgb, _sample.rgb * toneScalar, g_fEnableToneMapping );
    }
 
-   // Add the bloom effect.
-   float depth = prepassUncondition( prepassTex, IN_uv0 ).w;
-   if (depth>0.9999)
-      _sample += g_fBloomScale * bloom;
-
    // Apply the color correction.
    _sample.r = texture( colorCorrectionTex, _sample.r ).r;
    _sample.g = texture( colorCorrectionTex, _sample.g ).g;
    _sample.b = texture( colorCorrectionTex, _sample.b ).b;
 
    // Apply gamma correction
-   _sample.rgb = pow( abs(_sample.rgb), vec3(g_fOneOverGamma) );
+   _sample.rgb = pow( _sample.rgb, vec3(g_fOneOverGamma) );
    
    // Apply contrast
    _sample.rgb = ((_sample.rgb - 0.5f) * Contrast) + 0.5f;