Skip to content

Commit

Permalink
#86 Expose bloom intensity param
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 8, 2020
1 parent 36bc6f5 commit cbac57d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions Assets/BuiltIn/Shader/PostProcessing/Bloom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<fs>
<uniform name="uSourceTex" type="DEFAULT_VALUE" value="0" float="1" directX="false"/>
<uniform name="uBlurTex" type="DEFAULT_VALUE" value="1" float="1" directX="false"/>
<uniform name="uBloomIntensity" type="MATERIAL_PARAM" valueIndex="0" value="1.0" float="1"/>
</fs>
</uniforms>
<shader type="GLSL" vs="GLSL/BloomVS.glsl" fs="GLSL/BloomFS.glsl"/>
Expand Down
7 changes: 3 additions & 4 deletions Assets/BuiltIn/Shader/PostProcessing/GLSL/BloomFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ precision mediump float;
uniform sampler2D uSourceTex;
uniform sampler2D uBlurTex;

uniform vec2 uTexelSize;
uniform float uBloomIntensity;

in vec2 varTexCoord0;

Expand All @@ -16,9 +16,8 @@ void main(void)

// blur color
vec3 blur = texture(uBlurTex, varTexCoord0).rgb;

float intensity = 1.0;
vec3 m = base + blur * intensity;

vec3 m = base + blur * uBloomIntensity;

FragColor = vec4(m, 1.0);
}
7 changes: 3 additions & 4 deletions Assets/BuiltIn/Shader/PostProcessing/HLSL/BloomFS.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct PS_INPUT

cbuffer cbPerFrame
{
float2 uTexelSize;
float uBloomIntensity;
};

float4 main(PS_INPUT input) : SV_TARGET
Expand All @@ -23,9 +23,8 @@ float4 main(PS_INPUT input) : SV_TARGET

// blur color
float3 blur = uBlurTex.Sample(uBlurTexSampler, input.tex0).rgb;

float intensity = 1.0;
float3 m = base + blur * intensity;

float3 m = base + blur * uBloomIntensity;

return float4(m, 1.0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ namespace Skylicht
m_bloomFilter(NULL),
m_fxaaFilter(NULL),
m_numTarget(0),
m_bloomThreshold(0.9f)
m_bloomThreshold(0.9f),
m_bloomIntensity(1.0f)
{
m_luminance[0] = NULL;
m_luminance[1] = NULL;
Expand Down Expand Up @@ -234,6 +235,8 @@ namespace Skylicht
m_bloomFilter->setTexture(1, m_rtt[2]);
m_bloomFilter->applyMaterial(m_effectPass);

m_bloomFilter->setUniform("uBloomIntensity", m_bloomIntensity);

CShaderMaterial::setMaterial(m_bloomFilter);

colorID = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace Skylicht
SMaterial m_effectPass;

float m_bloomThreshold;
float m_bloomIntensity;

bool m_autoExposure;
bool m_bloomEffect;
Expand Down Expand Up @@ -103,6 +104,11 @@ namespace Skylicht
m_bloomThreshold = f;
}

inline void setBloomIntensity(float f)
{
m_bloomIntensity = f;
}

protected:

void renderEffect(int fromTarget, int toTarget, CMaterial *material);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ void SampleParticlesMagicSkill::onInitApp()

m_postProcessorRP = new CPostProcessorRP();
m_postProcessorRP->setBloomThreshold(0.7f);
m_postProcessorRP->setBloomIntensity(2.0f);
m_postProcessorRP->initRender(w, h);
m_forwardRP->setPostProcessor(m_postProcessorRP);
}
Expand Down

0 comments on commit cbac57d

Please sign in to comment.