Răsfoiți Sursa

Bloom Updates

Samuel Skiff 3 ani în urmă
părinte
comite
ecf7298c68

+ 36 - 17
Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript

@@ -20,13 +20,20 @@
 // IN THE SOFTWARE.
 //-----------------------------------------------------------------------------
 
-$PostFX::BloomPostFX::threshold = 0.75;
+// Inspired by bloom described in paper listed here:
+// http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare
+
+$PostFX::BloomPostFX::threshold = 0.65;
 $PostFX::BloomPostFX::intensity = 0.5;
-$PostFX::BloomPostFX::radius = 8.0;
+$PostFX::BloomPostFX::radius = 4.0;
 
 $PostFX::BloomPostFX::dirtEnabled = true;
 $PostFX::BloomPostFX::dirtScale = 2048.0;
-$PostFX::BloomPostFX::dirtIntensity = 7.0;
+$PostFX::BloomPostFX::dirtIntensity = 2.0;
+$PostFX::BloomPostFX::dirtEdgeMinDist = 0.125;
+$PostFX::BloomPostFX::dirtEdgeMaxDist = 0.75;
+$PostFX::BloomPostFX::dirtEdgeMinVal = 0.05;
+$PostFX::BloomPostFX::dirtImage = "core/postFX/images/lensDirt.png";
 
 singleton ShaderData( PFX_BloomThreshold_Shader )
 {
@@ -112,6 +119,11 @@ function BloomPostFX::setShaderConsts( %this )
    %dirtScale = $PostFX::BloomPostFX::dirtScale;
    %dirtIntensity = $PostFX::BloomPostFX::dirtIntensity;
    %final.setShaderConst("$dirtParams", %dirtScale SPC %dirtScale SPC %dirtIntensity);
+	 
+	 %edgeMin = $PostFX::BloomPostFX::dirtEdgeMinDist;
+	 %edgeMax = $PostFX::BloomPostFX::dirtEdgeMaxDist;
+	 %edgeVal = $PostFX::BloomPostFX::dirtEdgeMinVal;
+	 %final.setShaderConst("$edgeParams", %edgeMin SPC %edgeMax SPC %edgeVal);
 }
 
 function BloomPostFX::preProcess( %this )
@@ -129,15 +141,12 @@ function BloomPostFX::preProcess( %this )
      }
   }
   
-  if($PostFX::BloomPostFX::dirtImage $= "")
-  {
-    $PostFX::BloomPostFX::dirtImage = "core/postFX/images/lensDirt.png";
-  }
-  
-  if($PostFX::BloomPostFX::dirtImage !$= "")
+  if(%this.dirtImage !$= $PostFX::BloomPostFX::dirtImage)
   {
+		%this.dirtImage = $PostFX::BloomPostFX::dirtImage;
+		
     %final = %this->bloomFinal;
-    %final.setTexture(1, $PostFX::BloomPostFX::dirtImage);
+    %final.setTexture(1, %this.dirtImage);
   }
 }
 
@@ -153,7 +162,8 @@ function BloomPostFX::SetupBlurFX( %this )
      stateBlock = BloomPostFX_SampleStateBlock;
      texture[0] = "#threshold";
      target = "#bloom_0";
-     targetFormat = "GFXFormatR16G16B16A16F";
+		 targetScale = "0.5 0.5";
+     targetFormat = %this.selTexFormat;
    };
   
    %textureName = "#bloom_0";
@@ -169,7 +179,7 @@ function BloomPostFX::SetupBlurFX( %this )
        texture[0] = %textureName;
        target = "#" @ %mipName;
        targetScale = "0.5 0.5";
-       targetFormat = "GFXFormatR16G16B16A16F";
+       targetFormat = %this.selTexFormat;
      };
      
      %blurFX.add(%mipFX);
@@ -179,7 +189,7 @@ function BloomPostFX::SetupBlurFX( %this )
    for (%idx = %this.mipsCount; %idx > 0; %idx--)
    {
      %nxt = "#bloom_" @ (%idx - 1);
-     %mipName = "upsample_" @ (%idx - 1);
+     %mipName = "upSample_" @ (%idx - 1);
      echo(%mipName SPC %textureName SPC %nxt);
      
      %mipFX = new PostEffect()
@@ -191,6 +201,8 @@ function BloomPostFX::SetupBlurFX( %this )
        texture[0] = %nxt;
        texture[1] = %textureName;
        target = "#" @ %mipName;
+			 targetScale = "1.0 1.0";
+			 targetFormat = %this.selTexFormat;
      };
      
      %blurFX.add(%mipFX);
@@ -233,6 +245,9 @@ function BloomPostFX::populatePostFXSettings(%this)
    PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtEnabled", "Enable Dirt", "bool", "", $PostFX::BloomPostFX::dirtEnabled, "");
    PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtScale", "Scale", "float", "", $PostFX::BloomPostFX::dirtScale, "");
    PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtIntensity", "Intensity", "float", "", $PostFX::BloomPostFX::dirtIntensity, "");
+	 PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtEdgeMinDist", "Min Dist", "range", "", $PostFX::BloomPostFX::dirtEdgeMinDist, "0 1 10");
+	 PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtEdgeMaxDist", "Max Dist", "range", "", $PostFX::BloomPostFX::dirtEdgeMaxDist, "0 1 10");
+	 PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtEdgeMinVal", "Min Value", "range", "", $PostFX::BloomPostFX::dirtEdgeMinVal, "0 1 10");
    PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtImage", "Dirt Image", "image", "", $PostFX::BloomPostFX::dirtImage, "");
    PostEffectEditorInspector.endGroup();
 }
@@ -269,12 +284,18 @@ function BloomPostFX::savePresetSettings(%this)
    PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtScale");
    PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtIntensity");
    PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtImage");
+	 
+	 PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMinDist");
+	 PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMaxDist");
+	 PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMinVal");
 }
 
 //Our actual postFX
 singleton PostEffect( BloomPostFX )
 {
-   mipsCount = 4;
+   mipsCount = 5;
+	 selTexFormat = "GFXFormatR16G16B16A16F";
+	 
    enabled = false;
    allowReflectPass = false;
    
@@ -287,8 +308,6 @@ singleton PostEffect( BloomPostFX )
    texture[0] = "$backBuffer";
    target = "#threshold";
    targetFormat = "GFXFormatR16G16B16A16F";
-   targetClear = PFXTargetClear_OnDraw;
-   targetClearColor = "0 0 0 0";
    
    new PostEffect()
    {
@@ -296,7 +315,7 @@ singleton PostEffect( BloomPostFX )
     allowReflectPass = false;
     shader = PFX_BloomStrength_Shader;
     stateBlock = BloomPostFX_Add_SampleStateBlock;
-    texture[0] = "#upsample_0";
+    texture[0] = "#upSample_0";
     target = "$backBuffer";
    };
 };

+ 9 - 5
Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomStrengthP.hlsl

@@ -28,21 +28,25 @@ uniform float strength;
 // XY: Dirt Texture Size/Scale
 // Z: Dirt Effect Strength
 uniform float3 dirtParams;
+// XY: Edge Min & Max Distance
+// Z: Edge Min Value
+uniform float3 edgeParams;
 uniform float2 oneOverTargetSize;
 
 float4 main(PFXVertToPix IN) : TORQUE_TARGET0
 {
 	#if defined(USE_DIRT)
-	float3 dirt = TORQUE_TEX2D(dirtTex, IN.uv0 / (dirtParams.xy * oneOverTargetSize)).rgb * dirtParams.z;
+		float edge = distance(IN.uv0, float2(0.5f, 0.5f));
+		edge = max(smoothstep(edgeParams.x, edgeParams.y, edge), edgeParams.z);
+		float3 dirt = TORQUE_TEX2D(dirtTex, IN.uv0 / (dirtParams.xy * oneOverTargetSize)).rgb * dirtParams.z * edge;
 	#endif
 	
-	float4 upSample = TORQUE_TEX2D(inputTex, IN.uv0);
+	float4 upSample = TORQUE_TEX2D(inputTex, IN.uv0) * strength;
 	
 	#if defined(USE_DIRT)
-	upSample.rgb += upSample.rgb * dirt;
+		upSample.rgb += upSample.rgb * dirt;
+		//upSample.rgb = dirt;
 	#endif
 	
-	upSample.rgb *= strength;
-	
 	return upSample;
 }

+ 1 - 2
Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomThresholdP.hlsl

@@ -29,8 +29,7 @@ float4 main(PFXVertToPix IN) : TORQUE_TARGET0
 {
 	float4 screenColor = TORQUE_TEX2D(inputTex, IN.uv0);
 	float brightness = max(screenColor.r, max(screenColor.g, screenColor.b));
-	float contribution = max(brightness - threshold, 0);
+	float contribution = pow(brightness, threshold * 10.0f);
 	contribution /= max(brightness, 0.0001f);
-	clip(contribution > 0.0001f ? 1 : -1);
 	return screenColor * contribution;
 }

+ 25 - 28
Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl

@@ -22,40 +22,37 @@
 
 #include "core/rendering/shaders/postFX/postFx.hlsl"
 
-//-----------------------------------------------------------------------------
-// Data 
-//-----------------------------------------------------------------------------
+static const int KERNEL_SAMPLES = 9;
+static const float3 KERNEL[9] = {
+	float3( 0.0000f, 0.0000f, 0.2500f),
+	float3( 1.0000f, 0.0000f, 0.1250f),
+	float3( 0.0000f, 1.0000f, 0.1250f),
+	float3(-1.0000f, 0.0000f, 0.1250f),
+	float3( 0.0000f,-1.0000f, 0.1250f),
+	float3( 1.0000f, 1.0000f, 0.0625f),
+	float3( 1.0000f,-1.0000f, 0.0625f),
+	float3(-1.0000f,-1.0000f, 0.0625f),
+	float3(-1.0000f, 1.0000f, 0.0625f)
+};
 
 TORQUE_UNIFORM_SAMPLER2D(inputTex, 0);
 uniform float2 oneOverTargetSize;
  
-//-----------------------------------------------------------------------------
-// Main
-//-----------------------------------------------------------------------------
 float4 main(PFXVertToPix IN) : TORQUE_TARGET0
 {
-	float x = oneOverTargetSize.x;
-	float y = oneOverTargetSize.y;
-	float4 a = TORQUE_TEX2D(inputTex, IN.uv0 + float2(-x*2.0f, y*2.0f));
-	float4 b = TORQUE_TEX2D(inputTex, IN.uv0 + float2( 0.0f  , y*2.0f));
-	float4 c = TORQUE_TEX2D(inputTex, IN.uv0 + float2( x*2.0f, y*2.0f));
-																	
-	float4 d = TORQUE_TEX2D(inputTex, IN.uv0 + float2(-x*2.0f,   0.0f));
-	float4 e = TORQUE_TEX2D(inputTex, IN.uv0);
-	float4 f = TORQUE_TEX2D(inputTex, IN.uv0 + float2( x*2.0f,   0.0f));
-																	
-	float4 g = TORQUE_TEX2D(inputTex, IN.uv0 + float2(-x*2.0f,-y*2.0f));
-	float4 h = TORQUE_TEX2D(inputTex, IN.uv0 + float2( 0.0f  ,-y*2.0f));
-	float4 i = TORQUE_TEX2D(inputTex, IN.uv0 + float2( x*2.0f,-y*2.0f));
-																	
-	float4 j = TORQUE_TEX2D(inputTex, IN.uv0 + float2(-x, y));
-	float4 k = TORQUE_TEX2D(inputTex, IN.uv0 + float2( x, y));
-	float4 l = TORQUE_TEX2D(inputTex, IN.uv0 + float2(-x,-y));
-	float4 m = TORQUE_TEX2D(inputTex, IN.uv0 + float2( x,-y));
+	float4 downSample = float4(0, 0, 0, 0);
+	
+	[unroll]
+	for (int i=0; i<KERNEL_SAMPLES; i++)
+	{
+		// XY: Sample Offset
+		// Z: Sample Weight
+		float3 offsetWeight = KERNEL[i];
+		float2 offset = offsetWeight.xy * oneOverTargetSize;
+		float weight = offsetWeight.z;
+		float4 sampleCol = TORQUE_TEX2D(inputTex, IN.uv0 + offset);
+		downSample += sampleCol * weight;
+	}
 	
-	float4 downSample = e * 0.125f;
-	downSample += (a+c+g+i) * 0.03125f;
-	downSample += (b+d+f+h) * 0.0625;
-	downSample += (j+k+l+m) * 0.125;
 	return downSample;
 }

+ 10 - 36
Templates/BaseGame/game/core/postFX/scripts/Bloom/upSampleP.hlsl

@@ -24,15 +24,15 @@
 
 static const int KERNEL_SAMPLES = 9;
 static const float3 KERNEL[9] = {
-	float3( 0.0000, 0.0000, 0.2500),
-	float3( 1.0000, 0.0000, 0.1250),
-	float3( 0.0000, 1.0000, 0.1250),
-	float3(-1.0000, 0.0000, 0.1250),
-	float3( 0.0000,-1.0000, 0.1250),
-	float3( 0.7070, 0.7070, 0.0625),
-	float3( 0.7070,-0.7070, 0.0625),
-	float3(-0.7070,-0.7070, 0.0625),
-	float3(-0.7070, 0.7070, 0.0625)
+	float3( 0.0000f, 0.0000f, 0.5000f),
+	float3( 1.0000f, 0.0000f, 0.0625f),
+	float3( 0.0000f, 1.0000f, 0.0625f),
+	float3(-1.0000f, 0.0000f, 0.0625f),
+	float3( 0.0000f,-1.0000f, 0.0625f),
+	float3( 0.7070f, 0.7070f, 0.0625f),
+	float3( 0.7070f,-0.7070f, 0.0625f),
+	float3(-0.7070f,-0.7070f, 0.0625f),
+	float3(-0.7070f, 0.7070f, 0.0625f)
 };
 
 TORQUE_UNIFORM_SAMPLER2D(nxtTex, 0);
@@ -56,33 +56,7 @@ float4 main(PFXVertToPix IN) : TORQUE_TARGET0
 		upSample += sampleCol * weight;
 	}
 	
-	upSample = TORQUE_TEX2D(nxtTex, IN.uv0) + upSample;
-	upSample.a = saturate(upSample.a);
+	upSample = (TORQUE_TEX2D(nxtTex, IN.uv0) + upSample) * 0.5f;
 	
 	return upSample;
-	
-	//float x = filterRadius * oneOverTargetSize.x;
-	//float y = filterRadius * oneOverTargetSize.y;
-	//
-	//float4 a = TORQUE_TEX2D(mipTex, IN.uv0 + float2(-x, y));
-	//float4 b = TORQUE_TEX2D(mipTex, IN.uv0 + float2( 0, y));
-	//float4 c = TORQUE_TEX2D(mipTex, IN.uv0 + float2( x, y));
-	//
-	//float4 d = TORQUE_TEX2D(mipTex, IN.uv0 + float2(-x, 0));
-	//float4 e = TORQUE_TEX2D(mipTex, IN.uv0 + float2( 0, 0));
-	//float4 f = TORQUE_TEX2D(mipTex, IN.uv0 + float2( x, 0));
-	//
-	//float4 g = TORQUE_TEX2D(mipTex, IN.uv0 + float2(-x,-y));
-	//float4 h = TORQUE_TEX2D(mipTex, IN.uv0 + float2( 0,-y));
-	//float4 i = TORQUE_TEX2D(mipTex, IN.uv0 + float2( x,-y));
-	//
-	//float4 upSample = e * 4.0f;
-	//upSample += (b+d+f+h) * 2.0f;
-	//upSample += (a+c+g+i);
-	//upSample *= 1.0f / 16.0f;
-	//
-	//upSample = TORQUE_TEX2D(nxtTex, IN.uv0) + upSample;
-	//upSample.a = saturate(upSample.a);
-	
-	//return upSample;
 }

+ 4 - 4
Templates/BaseGame/game/core/postFX/scripts/default.postfxpreset.tscript

@@ -1,9 +1,9 @@
 $PostFX::BloomPostFX::Enabled = "1";
-$PostFX::BloomPostFX::threshold = "0.394230783";
-$PostFX::BloomPostFX::intensity = "0.192307696";
+$PostFX::BloomPostFX::threshold = "0.721153855";
+$PostFX::BloomPostFX::intensity = "0.5";
 $PostFX::BloomPostFX::radius = "8";
 $PostFX::BloomPostFX::dirtEnabled = "1";
-$PostFX::BloomPostFX::dirtScale = "2048";
+$PostFX::BloomPostFX::dirtScale = 2048;
 $PostFX::BloomPostFX::dirtIntensity = "2";
 $PostFX::BloomPostFX::dirtImage = "core/postFX/images/lensDirt.png";
 $PostFX::HDRPostFX::Enabled = 1;
@@ -11,7 +11,7 @@ $PostFX::HDRPostFX::exposureValue = 1;
 $PostFX::HDRPostFX::minLuminace = 0.001;
 $PostFX::HDRPostFX::whiteCutoff = 1;
 $PostFX::HDRPostFX::adaptRate = "1";
-$PostFX::HDRPostFX::tonemapMode = "Filmic";
+$PostFX::HDRPostFX::tonemapMode = "ACES";
 $PostFX::HDRPostFX::enableBloom = "0";
 $PostFX::HDRPostFX::brightPassThreshold = 1;
 $PostFX::HDRPostFX::gaussMultiplier = 0.3;