mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-20 04:34:48 +00:00
OpenGL fixes for HDR post effect
This commit is contained in:
parent
7f18baa345
commit
cde584253d
|
|
@ -552,10 +552,10 @@ function HDRPostFX::SetupBloomFX( %this )
|
|||
%textureName = "#" @ %mipName;
|
||||
}
|
||||
|
||||
for (%idx = %this.mipsCount; %idx > 0; %idx--)
|
||||
for (%idx = %this.mipsCount - 1; %idx >= 0; %idx--)
|
||||
{
|
||||
%nxt = "#hdrbloom_" @ (%idx - 1);
|
||||
%mipName = "hdrbloom_up_" @ (%idx - 1);
|
||||
%nxt = "#hdrbloom_" @ %idx;
|
||||
%mipName = "hdrbloom_up_" @ %idx;
|
||||
|
||||
%mipFX = new PostEffect()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@ void main()
|
|||
switch (mipId)
|
||||
{
|
||||
case 0:
|
||||
group[0] = (a+b+d+e) * (0.125f/4.0f);
|
||||
group[1] = (b+c+e+f) * (0.125f/4.0f);
|
||||
group[2] = (d+e+g+h) * (0.125f/4.0f);
|
||||
group[3] = (e+f+h+i) * (0.125f/4.0f);
|
||||
group[4] = (j+k+l+m) * (0.5f/4.0f);
|
||||
group[0] = (a+b+d+e) * (0.125/4.0);
|
||||
group[1] = (b+c+e+f) * (0.125/4.0);
|
||||
group[2] = (d+e+g+h) * (0.125/4.0);
|
||||
group[3] = (e+f+h+i) * (0.125/4.0);
|
||||
group[4] = (j+k+l+m) * (0.5/4.0);
|
||||
group[0] *= KarisAverage(group[0]);
|
||||
group[1] *= KarisAverage(group[1]);
|
||||
group[2] *= KarisAverage(group[2]);
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ void main()
|
|||
vec3 e = texture(mipTex, vec2(IN_uv1.x, IN_uv1.y)).rgb;
|
||||
vec3 f = texture(mipTex, vec2(IN_uv1.x + x, IN_uv1.y)).rgb;
|
||||
|
||||
vec3 g = texture(mipTex, vec2(IN_uv1.x - x, IN_uv1 - y)).rgb;
|
||||
vec3 h = texture(mipTex, vec2(IN_uv1.x, IN_uv1 - y)).rgb;
|
||||
vec3 i = texture(mipTex, vec2(IN_uv1.x + x, IN_uv1 - y)).rgb;
|
||||
vec3 g = texture(mipTex, vec2(IN_uv1.x - x, IN_uv1.y - y)).rgb;
|
||||
vec3 h = texture(mipTex, vec2(IN_uv1.x, IN_uv1.y - y)).rgb;
|
||||
vec3 i = texture(mipTex, vec2(IN_uv1.x + x, IN_uv1.y - y)).rgb;
|
||||
|
||||
upSample.rgb = e*4.0;
|
||||
upSample.rgb += (b+d+f+h)*2.0;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ uniform vec2 oneOverTargetSize;
|
|||
uniform float brightPassThreshold;
|
||||
uniform float g_fMiddleGray;
|
||||
|
||||
const vec3 LUMINANCE_VECTOR = vec3(0.3125f, 0.6154f, 0.0721f);
|
||||
const vec3 LUMINANCE_VECTOR = vec3(0.3125, 0.6154, 0.0721);
|
||||
|
||||
out vec4 OUT_col;
|
||||
|
||||
|
|
@ -44,21 +44,21 @@ const vec2 gTapOffsets[4] = vec2[]
|
|||
|
||||
void main()
|
||||
{
|
||||
vec4 average = vec4( 0.0f, 0.0f, 0.0f, 0.0f );
|
||||
vec4 average = vec4( 0.0, 0.0, 0.0, 0.0 );
|
||||
|
||||
// Combine and average 4 samples from the source HDR texture.
|
||||
for( int i = 0; i < 4; i++ )
|
||||
average += hdrDecode( texture( inputTex, IN_uv0 + ( gTapOffsets[i] * oneOverTargetSize ) ) );
|
||||
average *= 0.25f;
|
||||
average *= 0.25;
|
||||
|
||||
// Determine the brightness of this particular pixel.
|
||||
float adaptedLum = texture( luminanceTex, vec2( 0.5f, 0.5f ) ).r;
|
||||
float adaptedLum = texture( luminanceTex, vec2( 0.5, 0.5 ) ).r;
|
||||
float lum = (g_fMiddleGray / (adaptedLum + 0.0001)) * hdrLuminance( average.rgb );
|
||||
//float lum = hdrLuminance( average.rgb );
|
||||
|
||||
// Determine whether this pixel passes the test...
|
||||
if ( lum < brightPassThreshold )
|
||||
average = vec4( 0.0f, 0.0f, 0.0f, 1.0f );
|
||||
average = vec4( 0.0, 0.0, 0.0, 1.0 );
|
||||
|
||||
// Write the colour to the bright-pass render target
|
||||
OUT_col = hdrEncode( saturate(average) );
|
||||
|
|
|
|||
|
|
@ -61,12 +61,12 @@ out vec4 OUT_col;
|
|||
vec3 Tonemap(vec3 x)
|
||||
{
|
||||
//ACES
|
||||
if(g_fTonemapMode == 1.0f)
|
||||
if(g_fTonemapMode == 1.0)
|
||||
{
|
||||
x = ACESFitted(x, whitePoint); //ACES is crushing our blacks, need to pre-expose!
|
||||
}
|
||||
//Filmic Helji
|
||||
if(g_fTonemapMode == 2.0f)
|
||||
if(g_fTonemapMode == 2.0)
|
||||
{
|
||||
x = TO_Hejl(x, whitePoint);
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ vec3 Tonemap(vec3 x)
|
|||
void main()
|
||||
{
|
||||
vec4 _sample = hdrDecode( texture( sceneTex, IN_uv0 ) );
|
||||
float adaptedLum = texture( luminanceTex, vec2( 0.5f, 0.5f ) ).r;
|
||||
float adaptedLum = texture( luminanceTex, vec2( 0.5, 0.5 ) ).r;
|
||||
vec4 bloom = texture( bloomTex, IN_uv2 );
|
||||
|
||||
// Add the bloom effect.
|
||||
|
|
@ -109,7 +109,7 @@ void main()
|
|||
_sample.rgb = TO_Saturation(_sample.rgb, saturationValue);
|
||||
|
||||
// Apply contrast
|
||||
_sample.rgb = ((_sample.rgb - 0.5f) * Contrast) + 0.5f;
|
||||
_sample.rgb = ((_sample.rgb - 0.5) * Contrast) + 0.5;
|
||||
|
||||
// Apply brightness
|
||||
//_sample.rgb += Brightness;
|
||||
|
|
@ -120,15 +120,15 @@ void main()
|
|||
_sample.b = TO_LogContrast(_sample.b, logContrast);
|
||||
|
||||
//tonemapping - TODO fix up eye adaptation
|
||||
if ( g_fEnableToneMapping > 0.0f )
|
||||
if ( g_fEnableToneMapping > 0.0 )
|
||||
{
|
||||
float adapation = 1.0;
|
||||
|
||||
if( g_fEnableAutoExposure > 0.0f )
|
||||
if( g_fEnableAutoExposure > 0.0 )
|
||||
{
|
||||
adaptedLum = saturate(adaptedLum);
|
||||
float linearExposure = (g_fMiddleGray / adaptedLum);
|
||||
adapation = log2(max(linearExposure, 0.0001f));
|
||||
adapation = log2(max(linearExposure, 0.0001));
|
||||
|
||||
_sample.rgb = Tonemap(exposureValue * _sample.rgb *exp2(adapation));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue