| |
|
// MMJ's Simulated HDR Shader - v1.0
|
//
|
// Here's one to simulate (to some extent) the HDR effect used in some modern games.
|
// The Shader Level setting will increase the strength of the effect in increments of 25%.
|
//
|
// Try adjusting the m, cutoffL, and cutoffH values in the colorAdjust function to alter the effect.
|
//
|
// ------------------------
|
// MegaManJuno
|
|
uniform sampler2D OGL2Texture;
|
uniform vec4 OGL2Param;
|
|
vec3 RGB2HSL(in vec3 cRGB) {
|
float vH, vS, vL, cR, cG, cB, vMin, vMax, dMax, dR, dG, dB;
|
|
cR = cRGB[0]; cG = cRGB[1]; cB = cRGB[2];
|
|
vMin = min(min(cR, cG), cB); vMax = max(max(cR, cG), cB);
|
dMax = vMax - vMin;
|
|
vL = (vMax + vMin) / 2.0;
|
|
if(dMax == 0.0) { // gray, no chromatic data present
|
vH = 0.0; vS = 0.0;
|
|
} else { // chromatic data present
|
if(vL < 0.5) { vS = dMax / (vMax + vMin); }
|
else { vS = dMax / (2.0 - vMax - vMin); }
|
|
dR = (((vMax - cR) / 6.0) + (dMax / 2.0)) / dMax;
|
dG = (((vMax - cG) / 6.0) + (dMax / 2.0)) / dMax;
|
dB = (((vMax - cB) / 6.0) + (dMax / 2.0)) / dMax;
|
|
if (cR >= vMax) { vH = dB - dG; }
|
else if(cG >= vMax) { vH = (1.0 / 3.0) + dR - dB; }
|
else if(cB >= vMax) { vH = (2.0 / 3.0) + dG - dR; }
|
|
if (vH < 0.0) { vH += 1.0; }
|
else if(vH > 1.0) { vH -= 1.0; }
|
}
|
return vec3(vH, vS, vL);
|
}
|
|
vec3 colorAdjust(in vec3 co0, in vec3 co1, in vec3 co2, in vec3 co3, in vec3 co4, in vec3 co5, in vec3 co6, in vec3 co7, in vec3 co8) {
|
float m, m0, m1, m2, m3, m4, m5, m6, m7, m8, cutoffH, cutoffL;
|
|
// value to determine where we switch from brightening (overexposure) to darkening (underexposure) of the output color
|
m = 1.6; // default: 1.6
|
|
// cutoff value for increasing the "overexposure" brightness (don't multiply the brightness more than ~this~)
|
cutoffH = 1.125; // default: 1.125
|
|
// cutoff value for decreasing the "underexposure" brightness (don't multiply the brightness less than ~this~)
|
cutoffL = 0.875; // default: 0.875
|
|
// brightness adjustment calculations
|
m0 = 0.5 * clamp(m - (1.0 - RGB2HSL(co0)[2] ), cutoffL, cutoffH);
|
m1 = 1.0 * clamp(m - (1.0 - RGB2HSL(co1)[2] ), cutoffL, cutoffH);
|
m2 = 0.5 * clamp(m - (1.0 - RGB2HSL(co2)[2] ), cutoffL, cutoffH);
|
m3 = 1.0 * clamp(m - (1.0 - RGB2HSL(co3)[2] ), cutoffL, cutoffH);
|
m4 = 0.4 * clamp(m - (1.0 - RGB2HSL(co4)[2] ), cutoffL, cutoffH);
|
m5 = 1.0 * clamp(m - (1.0 - RGB2HSL(co5)[2] ), cutoffL, cutoffH);
|
m6 = 0.5 * clamp(m - (1.0 - RGB2HSL(co6)[2] ), cutoffL, cutoffH);
|
m7 = 1.0 * clamp(m - (1.0 - RGB2HSL(co7)[2] ), cutoffL, cutoffH);
|
m8 = 0.5 * clamp(m - (1.0 - RGB2HSL(co8)[2] ), cutoffL, cutoffH);
|
|
// return blended color with brightness adjustments applied
|
return (co0 * m0 + co1 * m1 + co2 * m2 + co3 * m3 + co4 * m4 + co5 * m5 + co6 * m6 + co7 * m7 + co8 * m8) / 6.4;
|
}
|
|
void main(void) {
|
vec3 c0, c1, c2, c3, c4, c5, c6, c7, c8, b;
|
|
b = (OGL2Param.z + 1.0) * 0.25;
|
|
c0 = texture2D(OGL2Texture, gl_TexCoord[3].xy).rgb;
|
c1 = texture2D(OGL2Texture, gl_TexCoord[2].xy).rgb;
|
c2 = texture2D(OGL2Texture, gl_TexCoord[3].zy).rgb;
|
c3 = texture2D(OGL2Texture, gl_TexCoord[1].xy).rgb;
|
c4 = texture2D(OGL2Texture, gl_TexCoord[0].xy).rgb;
|
c5 = texture2D(OGL2Texture, gl_TexCoord[1].zw).rgb;
|
c6 = texture2D(OGL2Texture, gl_TexCoord[3].xw).rgb;
|
c7 = texture2D(OGL2Texture, gl_TexCoord[2].zw).rgb;
|
c8 = texture2D(OGL2Texture, gl_TexCoord[3].zw).rgb;
|
|
gl_FragColor.rgb = mix(c4, colorAdjust(c0, c1, c2, c3, c4, c5, c6, c7, c8), b);
|
}
|
|