Jump to content

Tone mapping for LE3


YouGroove
 Share

Recommended Posts

Let's start witha good article showing HDR and tone mapping :

 

http://frictionalgames.blogspot.fr/2012/09/tech-feature-hdr-lightning.html

 

Code from Uncharted 2 tone mapping , before trying to port it to LE3 :

 

float A = 0.15;

float B = 0.50;

float C = 0.10;

float D = 0.20;

float E = 0.02;

float F = 0.30;

float W = 11.2;

 

float3 Uncharted2Tonemap(float3 x)

{

return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;

}

 

float4 ps_main( float2 texCoord : TEXCOORD0 ) : COLOR

{

float3 texColor = tex2D(Texture0, texCoord );

texColor *= 16; // Hardcoded Exposure Adjustment

float ExposureBias = 2.0f;

float3 curr = Uncharted2Tonemap(ExposureBias*texColor);

float3 whiteScale = 1.0f/Uncharted2Tonemap(W);

float3 color = curr*whiteScale;

float3 retColor = pow(color,1/2.2);

return float4(retColor,1);

}

 

 

LE3 final working version smile.png


#version 400

uniform sampler2D texture1;
uniform bool isbackbuffer;
uniform vec2 buffersize;

out vec4 fragData0;

const float A = 0.15;
const float B = 0.50;
const float C = 0.10;
const float D = 0.20;
const float E = 0.02;
const float F = 0.30;
const float W = 11.2;	  

vec3 Uncharted2Tonemap(vec3 x)
{
return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}

void main(void)
{
   vec2 icoord = vec2(gl_FragCoord.xy/buffersize);
   if (isbackbuffer) icoord.y = 1.0 - icoord.y;
   vec4 c = texture(texture1,icoord);

   vec3 texColor = c.rgb ;     
   texColor *= 3;     
   float ExposureBias = 1.3;

   vec3 curr = Uncharted2Tonemap(ExposureBias*texColor);
   vec3 Wvec =  vec3(W,W,W);
   vec3 Wtonemap =  Uncharted2Tonemap(Wvec);
   vec3 oneVec = vec3(1,1,1);
 vec3 whiteScale = oneVec / Wtonemap;
   vec3 color = curr*whiteScale;
   float powerV = 1/2.2;
   vec3 powerVal = vec3 (powerV,powerV,powerV);
   vec3 retColor = pow(color,powerVal);

   vec4 cfinal = c ;
   cfinal.rgb = retColor;

   fragData0 = cfinal ;
}

  • Upvote 1

Stop toying and make games

Link to comment
Share on other sites

Let's port to LE3 a simple tone mapping shader this time :

https://github.com/pixelpusher/CreativeCode/blob/master/HarmonicSineDrawingGlow/data/ToneMap.glsl

And the working LE3 version :

 

 

 

#version 400

 

uniform sampler2D texture1;

uniform bool isbackbuffer;

uniform vec2 buffersize;

 

 

 

out vec4 fragData0;

 

 

 

void main(void)

{

 

vec2 icoord = vec2(gl_FragCoord.xy/buffersize);

if (isbackbuffer) icoord.y = 1.0 - icoord.y;

vec4 c = texture(texture1,icoord);

 

float exposure = 1.5;

float bright = 1.3;

 

vec4 c2 = c ;

float Y = dot(vec4(0.30, 0.59, 0.11, 0.0), c2);

float YD = exposure * (exposure / bright + 1.0) / (exposure + 1.0);

c2 *= YD;

 

fragData0 = c2 ;

 

}

 

You must play with exposure and brightness to adjust as you want the shader.

 

Before tone mapping :

tone.jpg

 

With tone mapping with same directionanl light values : it looks better, the colors are more vibrant

tone2.jpg

 

 

 

Another test with no ambient, low directionnal light and a spot light :

No tone mapping

no_Tone3.jpg

 

Tone mapping with same values as before

tone3.jpg

 

 

Shader download :

http://www.leadwerks.com/werkspace/files/file/573-simple-tone-mapping/

Stop toying and make games

Link to comment
Share on other sites

Question :

How to force sRGB conversion in LE3 ?

if(g_useGammaDisplay)
glEnable(GL_FRAMEBUFFER_SRGB);
else
glDisable(GL_FRAMEBUFFER_SRGB);

http://www.arcsynthesis.org/gltut/Texturing/Tut16%20Free%20Gamma%20Correction.html

 

Because trying Uncharted 2 tone mapping in LE3 is heavy saturated and some guys said it could come from sRGB ? (I don't know a lot about shaders).

Stop toying and make games

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...