add tonemapping shaders

This commit is contained in:
2020-05-22 19:59:34 +08:00
parent eb0b29275e
commit 23685cd868
18 changed files with 606 additions and 59 deletions

View File

@@ -1,4 +1,4 @@
/*
/*
This shader experiments the effect of different tone mapping operators.
This is still a work in progress.
@@ -17,69 +17,44 @@ Zavie
*/
vec3 linearToneMapping(vec3 color)
{
float exposure = 1.;
color = clamp(exposure * color, 0., 1.);
color = pow(color, vec3(1. / gamma));
return color;
}
uniform float u_Exposure;
vec3 simpleReinhardToneMapping(vec3 color)
{
float exposure = 1.5;
color *= exposure/(1. + color / exposure);
color = pow(color, vec3(1. / gamma));
return color;
}
vec3 lumaBasedReinhardToneMapping(vec3 color)
vec3 toneMap(vec3 color)
{
float luma = dot(color, vec3(0.2126, 0.7152, 0.0722));
float toneMappedLuma = luma / (1. + luma);
color *= toneMappedLuma / luma;
color = pow(color, vec3(1. / gamma));
return color;
}
color *= u_Exposure;
vec3 whitePreservingLumaBasedReinhardToneMapping(vec3 color)
{
float white = 2.;
float luma = dot(color, vec3(0.2126, 0.7152, 0.0722));
float toneMappedLuma = luma * (1. + luma / (white*white)) / (1. + luma);
color *= toneMappedLuma / luma;
color = pow(color, vec3(1. / gamma));
return color;
}
#ifdef TONEMAP_UNCHARTED
return toneMapUncharted(color);
#endif
vec3 RomBinDaHouseToneMapping(vec3 color)
{
color = exp( -1.0 / ( 2.72*color + 0.15 ) );
color = pow(color, vec3(1. / gamma));
return color;
}
#ifdef TONEMAP_HEJLRICHARD
return toneMapHejlRichard(color);
#endif
vec3 filmicToneMapping(vec3 color)
{
color = max(vec3(0.), color - vec3(0.004));
color = (color * (6.2 * color + .5)) / (color * (6.2 * color + 1.7) + 0.06);
return color;
}
#ifdef TONEMAP_ACES
return toneMapACES(color);
#endif
vec3 Uncharted2ToneMapping(vec3 color)
{
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;
float exposure = 2.;
color *= exposure;
color = ((color * (A * color + C * B) + D * E) / (color * (A * color + B) + D * F)) - E / F;
float white = ((W * (A * W + C * B) + D * E) / (W * (A * W + B) + D * F)) - E / F;
color /= white;
color = pow(color, vec3(1. / gamma));
return color;
#ifdef TONEMAP_LINEAR
return linearToneMapping(color);
#endif//TONEMAP_LINEAR
#ifdef TONEMAP_SIMPLE_REINHARD
return simpleReinhardToneMapping(color)
#endif//TONEMAP_SIMPLE_REINHARD
#ifdef TONEMAP_LUMA_BASED_REINHARD
return lumaBasedReinhardToneMapping(color)
#endif//TONE_MAP_LUMA_BASED_REINHARD
#ifdef TONEMAP_WHITE_PRESERVING_LUMA_BASED_REINHARD
return whitePreservingLumaBasedReinhardToneMapping(color)
#endif//TONEMAP_WHITE_PRESERVING_LUMA_BASED_REINHARD
#ifdef TONEMAP_ROM_BIN_DA_HOUSE
return RomBinDaHouseToneMapping(color)
#endif//TONEMAP_ROM_BIN_DA_HOUSE
return linearTosRGB(color);
}