Bloom Updates

This commit is contained in:
Samuel Skiff 2022-08-24 11:54:18 -05:00
parent 633053a307
commit ecf7298c68
6 changed files with 85 additions and 92 deletions

View file

@ -20,13 +20,20 @@
// IN THE SOFTWARE. // 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::intensity = 0.5;
$PostFX::BloomPostFX::radius = 8.0; $PostFX::BloomPostFX::radius = 4.0;
$PostFX::BloomPostFX::dirtEnabled = true; $PostFX::BloomPostFX::dirtEnabled = true;
$PostFX::BloomPostFX::dirtScale = 2048.0; $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 ) singleton ShaderData( PFX_BloomThreshold_Shader )
{ {
@ -112,6 +119,11 @@ function BloomPostFX::setShaderConsts( %this )
%dirtScale = $PostFX::BloomPostFX::dirtScale; %dirtScale = $PostFX::BloomPostFX::dirtScale;
%dirtIntensity = $PostFX::BloomPostFX::dirtIntensity; %dirtIntensity = $PostFX::BloomPostFX::dirtIntensity;
%final.setShaderConst("$dirtParams", %dirtScale SPC %dirtScale SPC %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 ) function BloomPostFX::preProcess( %this )
@ -129,15 +141,12 @@ function BloomPostFX::preProcess( %this )
} }
} }
if($PostFX::BloomPostFX::dirtImage $= "") if(%this.dirtImage !$= $PostFX::BloomPostFX::dirtImage)
{
$PostFX::BloomPostFX::dirtImage = "core/postFX/images/lensDirt.png";
}
if($PostFX::BloomPostFX::dirtImage !$= "")
{ {
%this.dirtImage = $PostFX::BloomPostFX::dirtImage;
%final = %this->bloomFinal; %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; stateBlock = BloomPostFX_SampleStateBlock;
texture[0] = "#threshold"; texture[0] = "#threshold";
target = "#bloom_0"; target = "#bloom_0";
targetFormat = "GFXFormatR16G16B16A16F"; targetScale = "0.5 0.5";
targetFormat = %this.selTexFormat;
}; };
%textureName = "#bloom_0"; %textureName = "#bloom_0";
@ -169,7 +179,7 @@ function BloomPostFX::SetupBlurFX( %this )
texture[0] = %textureName; texture[0] = %textureName;
target = "#" @ %mipName; target = "#" @ %mipName;
targetScale = "0.5 0.5"; targetScale = "0.5 0.5";
targetFormat = "GFXFormatR16G16B16A16F"; targetFormat = %this.selTexFormat;
}; };
%blurFX.add(%mipFX); %blurFX.add(%mipFX);
@ -179,7 +189,7 @@ function BloomPostFX::SetupBlurFX( %this )
for (%idx = %this.mipsCount; %idx > 0; %idx--) for (%idx = %this.mipsCount; %idx > 0; %idx--)
{ {
%nxt = "#bloom_" @ (%idx - 1); %nxt = "#bloom_" @ (%idx - 1);
%mipName = "upsample_" @ (%idx - 1); %mipName = "upSample_" @ (%idx - 1);
echo(%mipName SPC %textureName SPC %nxt); echo(%mipName SPC %textureName SPC %nxt);
%mipFX = new PostEffect() %mipFX = new PostEffect()
@ -191,6 +201,8 @@ function BloomPostFX::SetupBlurFX( %this )
texture[0] = %nxt; texture[0] = %nxt;
texture[1] = %textureName; texture[1] = %textureName;
target = "#" @ %mipName; target = "#" @ %mipName;
targetScale = "1.0 1.0";
targetFormat = %this.selTexFormat;
}; };
%blurFX.add(%mipFX); %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::dirtEnabled", "Enable Dirt", "bool", "", $PostFX::BloomPostFX::dirtEnabled, "");
PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtScale", "Scale", "float", "", $PostFX::BloomPostFX::dirtScale, ""); PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtScale", "Scale", "float", "", $PostFX::BloomPostFX::dirtScale, "");
PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtIntensity", "Intensity", "float", "", $PostFX::BloomPostFX::dirtIntensity, ""); 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.addField("$PostFX::BloomPostFX::dirtImage", "Dirt Image", "image", "", $PostFX::BloomPostFX::dirtImage, "");
PostEffectEditorInspector.endGroup(); PostEffectEditorInspector.endGroup();
} }
@ -269,12 +284,18 @@ function BloomPostFX::savePresetSettings(%this)
PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtScale"); PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtScale");
PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtIntensity"); PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtIntensity");
PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtImage"); PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtImage");
PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMinDist");
PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMaxDist");
PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMinVal");
} }
//Our actual postFX //Our actual postFX
singleton PostEffect( BloomPostFX ) singleton PostEffect( BloomPostFX )
{ {
mipsCount = 4; mipsCount = 5;
selTexFormat = "GFXFormatR16G16B16A16F";
enabled = false; enabled = false;
allowReflectPass = false; allowReflectPass = false;
@ -287,8 +308,6 @@ singleton PostEffect( BloomPostFX )
texture[0] = "$backBuffer"; texture[0] = "$backBuffer";
target = "#threshold"; target = "#threshold";
targetFormat = "GFXFormatR16G16B16A16F"; targetFormat = "GFXFormatR16G16B16A16F";
targetClear = PFXTargetClear_OnDraw;
targetClearColor = "0 0 0 0";
new PostEffect() new PostEffect()
{ {
@ -296,7 +315,7 @@ singleton PostEffect( BloomPostFX )
allowReflectPass = false; allowReflectPass = false;
shader = PFX_BloomStrength_Shader; shader = PFX_BloomStrength_Shader;
stateBlock = BloomPostFX_Add_SampleStateBlock; stateBlock = BloomPostFX_Add_SampleStateBlock;
texture[0] = "#upsample_0"; texture[0] = "#upSample_0";
target = "$backBuffer"; target = "$backBuffer";
}; };
}; };

View file

@ -28,21 +28,25 @@ uniform float strength;
// XY: Dirt Texture Size/Scale // XY: Dirt Texture Size/Scale
// Z: Dirt Effect Strength // Z: Dirt Effect Strength
uniform float3 dirtParams; uniform float3 dirtParams;
// XY: Edge Min & Max Distance
// Z: Edge Min Value
uniform float3 edgeParams;
uniform float2 oneOverTargetSize; uniform float2 oneOverTargetSize;
float4 main(PFXVertToPix IN) : TORQUE_TARGET0 float4 main(PFXVertToPix IN) : TORQUE_TARGET0
{ {
#if defined(USE_DIRT) #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 #endif
float4 upSample = TORQUE_TEX2D(inputTex, IN.uv0); float4 upSample = TORQUE_TEX2D(inputTex, IN.uv0) * strength;
#if defined(USE_DIRT) #if defined(USE_DIRT)
upSample.rgb += upSample.rgb * dirt; upSample.rgb += upSample.rgb * dirt;
//upSample.rgb = dirt;
#endif #endif
upSample.rgb *= strength;
return upSample; return upSample;
} }

View file

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

View file

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

View file

@ -24,15 +24,15 @@
static const int KERNEL_SAMPLES = 9; static const int KERNEL_SAMPLES = 9;
static const float3 KERNEL[9] = { static const float3 KERNEL[9] = {
float3( 0.0000, 0.0000, 0.2500), float3( 0.0000f, 0.0000f, 0.5000f),
float3( 1.0000, 0.0000, 0.1250), float3( 1.0000f, 0.0000f, 0.0625f),
float3( 0.0000, 1.0000, 0.1250), float3( 0.0000f, 1.0000f, 0.0625f),
float3(-1.0000, 0.0000, 0.1250), float3(-1.0000f, 0.0000f, 0.0625f),
float3( 0.0000,-1.0000, 0.1250), float3( 0.0000f,-1.0000f, 0.0625f),
float3( 0.7070, 0.7070, 0.0625), float3( 0.7070f, 0.7070f, 0.0625f),
float3( 0.7070,-0.7070, 0.0625), float3( 0.7070f,-0.7070f, 0.0625f),
float3(-0.7070,-0.7070, 0.0625), float3(-0.7070f,-0.7070f, 0.0625f),
float3(-0.7070, 0.7070, 0.0625) float3(-0.7070f, 0.7070f, 0.0625f)
}; };
TORQUE_UNIFORM_SAMPLER2D(nxtTex, 0); TORQUE_UNIFORM_SAMPLER2D(nxtTex, 0);
@ -56,33 +56,7 @@ float4 main(PFXVertToPix IN) : TORQUE_TARGET0
upSample += sampleCol * weight; upSample += sampleCol * weight;
} }
upSample = TORQUE_TEX2D(nxtTex, IN.uv0) + upSample; upSample = (TORQUE_TEX2D(nxtTex, IN.uv0) + upSample) * 0.5f;
upSample.a = saturate(upSample.a);
return upSample; 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;
} }

View file

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