Browse Source

Merge pull request #901 from Azaezel/alpha401/smaaSlippage

fix smaa backbuffer  colorspace
Brian Roberts 2 năm trước cách đây
mục cha
commit
3f78e90870

+ 30 - 0
Templates/BaseGame/game/core/postFX/scripts/SMAA/BBtoGamma.hlsl

@@ -0,0 +1,30 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+#include "core/rendering/shaders/torque.hlsl"
+#include "core/rendering/shaders/postFX/postFx.hlsl"
+
+TORQUE_UNIFORM_SAMPLER2D(backBuffer, 0);
+
+float4 main(PFXVertToPix IN) : TORQUE_TARGET0
+{
+   return toGamma(TORQUE_TEX2D(backBuffer, IN.uv0));  
+}

+ 46 - 10
Templates/BaseGame/game/core/postFX/scripts/SMAA/SMAAPostFX.tscript

@@ -103,23 +103,59 @@ singleton ShaderData( SMAA_Neighbor_H_Shader )
    pixVersion = 3.0;
 };
 
-singleton PostEffect( SMAAPostFX )
+singleton GFXStateBlockData( BBtoGamma_StateBlock )
+{
+   zDefined = true;
+   zEnable = false;
+   zWriteEnable = false;
+      
+   samplersDefined = true;
+   samplerStates[0] = SamplerClampLinear;
+};
+
+singleton ShaderData( BBtoGammaShader )
 {
-   enabled = false;
+   DXVertexShaderFile 	= $Core::CommonShaderPath @ "/postFX/postFxV.hlsl";
+   DXPixelShaderFile 	= "./BBtoGamma.hlsl";   
+   OGLVertexShaderFile  = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl";
+   OGLPixelShaderFile   = "./gl/BBtoGamma.glsl";
    
-   allowReflectPass = false;
-   renderTime = "PFXAfterDiffuse";
+   samplerNames[0] = "$backBuffer";
    
-   texture[0] = "$backBuffer";
-   texture[1] = "#deferred";
+   pixVersion = 3.0;
+};
 
-   target = "#edgesPass";
+singleton PostEffect( SMAAPostFX )
+{
+   enabled = false;   
+   allowReflectPass = false;
+   renderTime = "PFXBeforeBin";
+   renderBin = "EditorBin";
+   texture[0] = "$backBuffer";
+   target = "#BBtoGamma";
+   renderPriority = 1; 
    targetClear = PFXTargetClear_OnDraw;
    targetClearColor = "0 0 0 0";
+   shader = BBtoGammaShader;
+   stateBlock = BBtoGamma_StateBlock;
+   
+   singleton PostEffect()
+   {
+      enabled = false;
    
-   shader = SMAA_Edge_D_Shader;
-   stateBlock = SMAA_Edge_D_StateBlock;
+      allowReflectPass = false;
+      renderTime = "PFXAfterDiffuse";
    
+      texture[0] = "#BBtoGamma";
+      texture[1] = "#deferred";
+
+      target = "#edgesPass";
+      targetClear = PFXTargetClear_OnDraw;
+      targetClearColor = "0 0 0 0";
+   
+      shader = SMAA_Edge_D_Shader;
+      stateBlock = SMAA_Edge_D_StateBlock;
+   }; 
    singleton PostEffect()
    {
       internalName = "Edge Pass";
@@ -141,7 +177,7 @@ singleton PostEffect( SMAAPostFX )
    {
       internalName = "BlendPass";
 	  
-      texture[0] = "$backBuffer";
+      texture[0] = "#BBtoGamma";
 	  texture[1] = "#blendPass";
 	  
 	  target = "$backBuffer";

+ 2 - 2
Templates/BaseGame/game/core/postFX/scripts/SMAA/SMAA_Neighbor_H_Blending_P.hlsl

@@ -20,7 +20,7 @@
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
 #include "core/rendering/shaders/shaderModel.hlsl"
-
+#include "core/rendering/shaders/torque.hlsl"
 #include "SMAA_Params.hlsl"
     
                                                                          
@@ -38,6 +38,6 @@ struct v_NHBlend
 float4 main( v_NHBlend IN ) : TORQUE_TARGET0
 {   
     //return float4(TORQUE_TEX2D(blendTex, IN.uv0));
-   return SMAANeighborhoodBlendingPS(IN.uv0, IN.offset, texture_sceneTex, texture_blendTex);
+   return toLinear(SMAANeighborhoodBlendingPS(IN.uv0, IN.offset, texture_sceneTex, texture_blendTex));
 } 
 

+ 31 - 0
Templates/BaseGame/game/core/postFX/scripts/SMAA/gl/BBtoGamma.glsl

@@ -0,0 +1,31 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+#include "core/rendering/shaders/gl/torque.glsl"
+#include "core/rendering/shaders/postFX/gl/postFx.glsl"
+
+uniform sampler2D backBuffer; 
+out vec4 OUT_col;
+
+void main()
+{
+   OUT_col= toGamma(texture(backBuffer, uv0));  
+}

+ 2 - 2
Templates/BaseGame/game/core/postFX/scripts/SMAA/gl/SMAA_Neighbor_H_Blending_P.glsl

@@ -20,7 +20,7 @@
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
 #include "core/rendering/shaders/gl/hlslCompat.glsl"
-
+#include "core/rendering/shaders/gl/torque.glsl"
 
 #include "SMAA_Params.glsl"
 #define SMAA_INCLUDE_VS 0
@@ -41,6 +41,6 @@ out vec4 OUT_col;
 void main() 
 {                                    
    //OUT_col =  vec4(texture(blendTex, uv0.xy));     
-  OUT_col= SMAANeighborhoodBlendingPS(uv0, offset, sceneTex, blendTex);
+  OUT_col= toLinear(SMAANeighborhoodBlendingPS(uv0, offset, sceneTex, blendTex));
 }