2016-03-23 23:35:44 +01:00
|
|
|
#version 450
|
|
|
|
|
2017-12-13 14:21:42 +01:00
|
|
|
#include "compiled.glsl"
|
|
|
|
#include "std/tonemap.glsl"
|
|
|
|
#include "std/math.glsl"
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CDOF
|
2017-12-13 14:21:42 +01:00
|
|
|
#include "std/dof.glsl"
|
2016-10-21 19:36:08 +02:00
|
|
|
#endif
|
2016-08-15 23:45:03 +02:00
|
|
|
|
2016-03-23 23:35:44 +01:00
|
|
|
uniform sampler2D tex;
|
2016-05-25 00:13:44 +02:00
|
|
|
uniform sampler2D gbufferD;
|
2016-04-29 11:11:45 +02:00
|
|
|
|
2017-02-25 17:13:22 +01:00
|
|
|
#ifdef _CLensTex
|
|
|
|
uniform sampler2D lensTexture;
|
|
|
|
#endif
|
|
|
|
|
2017-12-07 17:09:44 +01:00
|
|
|
#ifdef _CLUT
|
|
|
|
uniform sampler2D lutTexture;
|
|
|
|
#endif
|
|
|
|
|
2017-08-13 22:50:08 +02:00
|
|
|
#ifdef _Hist
|
2017-08-14 10:31:08 +02:00
|
|
|
uniform sampler2D histogram;
|
2017-08-13 22:50:08 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
// #ifdef _CPos
|
2016-10-23 15:32:26 +02:00
|
|
|
// uniform vec3 eye;
|
|
|
|
// uniform vec3 eyeLook;
|
|
|
|
// #endif
|
2016-04-01 19:44:53 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CGlare
|
2016-04-03 23:25:53 +02:00
|
|
|
uniform vec3 light;
|
2016-04-06 15:09:53 +02:00
|
|
|
uniform mat4 VP;
|
2016-10-23 15:32:26 +02:00
|
|
|
uniform vec3 eye;
|
|
|
|
uniform vec3 eyeLook;
|
|
|
|
uniform float aspectRatio;
|
2016-04-29 11:11:45 +02:00
|
|
|
#endif
|
2016-04-03 23:25:53 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CFXAA
|
2016-07-12 12:03:43 +02:00
|
|
|
uniform vec2 texStep;
|
2017-02-27 22:14:46 +01:00
|
|
|
#endif
|
2017-03-31 14:18:47 +02:00
|
|
|
#ifdef _CDOF // TODO: redefinition
|
2016-11-06 21:23:21 +01:00
|
|
|
uniform vec2 texStep;
|
|
|
|
#endif
|
2016-07-12 12:03:43 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CGrain
|
2016-08-15 23:45:03 +02:00
|
|
|
uniform float time;
|
|
|
|
#endif
|
2016-04-30 13:25:26 +02:00
|
|
|
|
2016-10-19 17:46:13 +02:00
|
|
|
#ifdef _DynRes
|
|
|
|
uniform float dynamicScale;
|
|
|
|
#endif
|
|
|
|
|
2017-11-04 18:35:34 +01:00
|
|
|
#ifdef _CFog
|
|
|
|
uniform vec2 cameraProj;
|
|
|
|
#endif
|
|
|
|
#ifdef _CDOF
|
|
|
|
uniform vec2 cameraProj;
|
|
|
|
#endif
|
|
|
|
#ifdef _CGlare
|
|
|
|
uniform vec2 cameraProj;
|
|
|
|
#endif
|
|
|
|
|
2016-03-23 23:35:44 +01:00
|
|
|
in vec2 texCoord;
|
2016-12-20 01:39:16 +01:00
|
|
|
// #ifdef _CPos
|
2016-10-23 15:32:26 +02:00
|
|
|
// in vec3 viewRay;
|
|
|
|
// #endif
|
2016-10-12 17:52:27 +02:00
|
|
|
out vec4 fragColor;
|
2016-03-23 23:35:44 +01:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CFog
|
2016-08-15 23:45:03 +02:00
|
|
|
// const vec3 compoFogColor = vec3(0.5, 0.6, 0.7);
|
|
|
|
// const float compoFogAmountA = 1.0; // b = 0.01
|
|
|
|
// const float compoFogAmountB = 1.0; // c = 0.1
|
2016-08-29 09:56:34 +02:00
|
|
|
// vec3 applyFog(vec3 rgb, // original color of the pixel
|
2016-10-17 17:39:40 +02:00
|
|
|
// float distance, // camera to point distance
|
|
|
|
// vec3 rayOri, // camera position
|
|
|
|
// vec3 rayDir) { // camera to point vector
|
|
|
|
// float fogAmount = compoFogAmountB * exp(-rayOri.y * compoFogAmountA) * (1.0 - exp(-distance * rayDir.y * compoFogAmountA)) / rayDir.y;
|
|
|
|
// return mix(rgb, compoFogColor, fogAmount);
|
2016-06-30 13:22:05 +02:00
|
|
|
// }
|
2016-08-29 09:56:34 +02:00
|
|
|
vec3 applyFog(vec3 rgb, float distance) {
|
2016-10-17 17:39:40 +02:00
|
|
|
// float fogAmount = 1.0 - exp(-distance * compoFogAmountA);
|
2017-12-20 22:56:22 +01:00
|
|
|
float fogAmount = 1.0 - exp(-distance * (compoFogAmountA / 100));
|
2016-10-17 17:39:40 +02:00
|
|
|
return mix(rgb, compoFogColor, fogAmount);
|
2016-08-29 09:56:34 +02:00
|
|
|
}
|
2016-08-15 23:45:03 +02:00
|
|
|
#endif
|
2016-05-06 11:13:46 +02:00
|
|
|
|
2017-12-07 17:09:44 +01:00
|
|
|
vec4 LUTlookup(in vec4 textureColor, in sampler2D lookupTable) {
|
|
|
|
|
|
|
|
//Clamp to prevent weird results
|
|
|
|
textureColor = clamp(textureColor, 0.0, 1.0);
|
|
|
|
|
|
|
|
mediump float blueColor = textureColor.b * 63.0;
|
|
|
|
mediump vec2 quad1;
|
|
|
|
|
|
|
|
quad1.y = floor(floor(blueColor) / 8.0);
|
|
|
|
quad1.x = floor(blueColor) - (quad1.y * 8.0);
|
|
|
|
|
|
|
|
mediump vec2 quad2;
|
|
|
|
quad2.y = floor(ceil(blueColor) / 8.0);
|
|
|
|
quad2.x = ceil(blueColor) - (quad2.y * 8.0);
|
|
|
|
|
|
|
|
highp vec2 texelPosition1;
|
|
|
|
texelPosition1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);
|
|
|
|
texelPosition1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);
|
|
|
|
|
|
|
|
highp vec2 texelPosition2;
|
|
|
|
texelPosition2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);
|
|
|
|
texelPosition2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);
|
|
|
|
|
|
|
|
lowp vec4 newColor1 = texture(lookupTable, texelPosition1);
|
|
|
|
lowp vec4 newColor2 = texture(lookupTable, texelPosition2);
|
|
|
|
|
|
|
|
lowp vec4 colorGradedResult = mix(newColor1, newColor2, fract(blueColor));
|
|
|
|
|
|
|
|
return colorGradedResult;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-04-01 12:37:46 +02:00
|
|
|
float vignette() {
|
2016-05-06 19:46:56 +02:00
|
|
|
// vignetting from iq
|
2016-10-17 17:39:40 +02:00
|
|
|
// return 0.4 + 0.6 * pow(16.0 * texCoord.x * texCoord.y * (1.0 - texCoord.x) * (1.0 - texCoord.y), 0.2);
|
|
|
|
return 0.3 + 0.7 * pow(16.0 * texCoord.x * texCoord.y * (1.0 - texCoord.x) * (1.0 - texCoord.y), 0.2);
|
2016-04-01 12:37:46 +02:00
|
|
|
}
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CGlare
|
2016-04-03 23:25:53 +02:00
|
|
|
// Based on lense flare implementation by musk
|
|
|
|
// https://www.shadertoy.com/view/4sX3Rs
|
|
|
|
vec3 lensflare(vec2 uv, vec2 pos) {
|
|
|
|
vec2 uvd = uv * (length(uv));
|
|
|
|
float f2 = max(1.0/(1.0+32.0*pow(length(uvd+0.8*pos),2.0)),0.0)*0.25;
|
|
|
|
float f22 = max(1.0/(1.0+32.0*pow(length(uvd+0.85*pos),2.0)),0.0)*0.23;
|
|
|
|
float f23 = max(1.0/(1.0+32.0*pow(length(uvd+0.9*pos),2.0)),0.0)*0.21;
|
|
|
|
|
|
|
|
vec2 uvx = mix(uv, uvd, -0.5);
|
|
|
|
float f4 = max(0.01-pow(length(uvx+0.4*pos),2.4),0.0)*6.0;
|
|
|
|
float f42 = max(0.01-pow(length(uvx+0.45*pos),2.4),0.0)*5.0;
|
|
|
|
float f43 = max(0.01-pow(length(uvx+0.5*pos),2.4),0.0)*3.0;
|
|
|
|
|
|
|
|
uvx = mix(uv, uvd, -0.4);
|
|
|
|
float f5 = max(0.01-pow(length(uvx+0.2*pos),5.5),0.0)*2.0;
|
|
|
|
float f52 = max(0.01-pow(length(uvx+0.4*pos),5.5),0.0)*2.0;
|
|
|
|
float f53 = max(0.01-pow(length(uvx+0.6*pos),5.5),0.0)*2.0;
|
|
|
|
|
|
|
|
uvx = mix(uv, uvd, -0.5);
|
|
|
|
float f6 = max(0.01-pow(length(uvx-0.3*pos),1.6),0.0)*6.0;
|
|
|
|
float f62 = max(0.01-pow(length(uvx-0.325*pos),1.6),0.0)*3.0;
|
|
|
|
float f63 = max(0.01-pow(length(uvx-0.35*pos),1.6),0.0)*5.0;
|
|
|
|
|
|
|
|
vec3 c = vec3(0.0);
|
|
|
|
c.r += f2 + f4 + f5 + f6;
|
2016-10-17 17:39:40 +02:00
|
|
|
c.g += f22 + f42 + f52 + f62;
|
|
|
|
c.b += f23 + f43 + f53 + f63;
|
2016-04-03 23:25:53 +02:00
|
|
|
return c;
|
|
|
|
}
|
2016-10-23 15:32:26 +02:00
|
|
|
#endif
|
2016-04-03 23:25:53 +02:00
|
|
|
|
2016-03-23 23:35:44 +01:00
|
|
|
void main() {
|
2016-08-15 23:45:03 +02:00
|
|
|
vec2 texCo = texCoord;
|
2016-10-19 17:46:13 +02:00
|
|
|
#ifdef _DynRes
|
|
|
|
texCo *= dynamicScale;
|
|
|
|
#endif
|
2016-10-21 19:36:08 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CFishEye
|
2016-08-15 23:45:03 +02:00
|
|
|
const float fishEyeStrength = -0.01;
|
|
|
|
const vec2 m = vec2(0.5, 0.5);
|
2016-10-19 17:46:13 +02:00
|
|
|
vec2 d = texCo - m;
|
2016-04-18 01:44:37 +02:00
|
|
|
float r = sqrt(dot(d, d));
|
|
|
|
float power = (2.0 * PI / (2.0 * sqrt(dot(m, m)))) * fishEyeStrength;
|
|
|
|
float bind;
|
|
|
|
if (power > 0.0) { bind = sqrt(dot(m, m)); }
|
2016-10-17 17:39:40 +02:00
|
|
|
else { bind = m.x; }
|
2016-04-18 01:44:37 +02:00
|
|
|
if (power > 0.0) {
|
2016-08-15 23:45:03 +02:00
|
|
|
texCo = m + normalize(d) * tan(r * power) * bind / tan(bind * power);
|
2016-04-18 01:44:37 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-08-15 23:45:03 +02:00
|
|
|
texCo = m + normalize(d) * atan(r * -power * 10.0) * bind / atan(-power * bind * 10.0);
|
2016-04-18 01:44:37 +02:00
|
|
|
}
|
2016-07-12 12:03:43 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CDepth
|
2017-03-11 01:50:47 +01:00
|
|
|
float depth = texture(gbufferD, texCo).r * 2.0 - 1.0;
|
2016-10-21 19:36:08 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CFXAA
|
2016-07-12 12:03:43 +02:00
|
|
|
const float FXAA_REDUCE_MIN = 1.0 / 128.0;
|
2016-10-17 17:39:40 +02:00
|
|
|
const float FXAA_REDUCE_MUL = 1.0 / 8.0;
|
|
|
|
const float FXAA_SPAN_MAX = 8.0;
|
|
|
|
|
2016-08-15 23:45:03 +02:00
|
|
|
vec2 tcrgbNW = (texCo + vec2(-1.0, -1.0) * texStep);
|
|
|
|
vec2 tcrgbNE = (texCo + vec2(1.0, -1.0) * texStep);
|
|
|
|
vec2 tcrgbSW = (texCo + vec2(-1.0, 1.0) * texStep);
|
|
|
|
vec2 tcrgbSE = (texCo + vec2(1.0, 1.0) * texStep);
|
|
|
|
vec2 tcrgbM = vec2(texCo);
|
2016-07-12 12:03:43 +02:00
|
|
|
|
|
|
|
vec3 rgbNW = texture(tex, tcrgbNW).rgb;
|
2016-10-17 17:39:40 +02:00
|
|
|
vec3 rgbNE = texture(tex, tcrgbNE).rgb;
|
|
|
|
vec3 rgbSW = texture(tex, tcrgbSW).rgb;
|
|
|
|
vec3 rgbSE = texture(tex, tcrgbSE).rgb;
|
2016-10-25 13:01:20 +02:00
|
|
|
vec3 rgbM = texture(tex, tcrgbM).rgb;
|
2016-10-17 17:39:40 +02:00
|
|
|
vec3 luma = vec3(0.299, 0.587, 0.114);
|
2016-07-12 12:03:43 +02:00
|
|
|
float lumaNW = dot(rgbNW, luma);
|
2016-10-17 17:39:40 +02:00
|
|
|
float lumaNE = dot(rgbNE, luma);
|
|
|
|
float lumaSW = dot(rgbSW, luma);
|
|
|
|
float lumaSE = dot(rgbSE, luma);
|
|
|
|
float lumaM = dot(rgbM, luma);
|
2016-07-12 12:03:43 +02:00
|
|
|
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
|
2016-10-17 17:39:40 +02:00
|
|
|
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
|
2016-07-12 12:03:43 +02:00
|
|
|
|
|
|
|
vec2 dir;
|
2016-10-17 17:39:40 +02:00
|
|
|
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
|
|
|
|
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
|
2016-07-12 12:03:43 +02:00
|
|
|
|
|
|
|
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) *
|
2016-10-17 17:39:40 +02:00
|
|
|
(0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN);
|
|
|
|
|
|
|
|
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
|
|
|
|
dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX),
|
|
|
|
max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX),
|
|
|
|
dir * rcpDirMin)) * texStep;
|
2016-07-12 12:03:43 +02:00
|
|
|
|
|
|
|
vec3 rgbA = 0.5 * (
|
2016-10-17 17:39:40 +02:00
|
|
|
texture(tex, texCo + dir * (1.0 / 3.0 - 0.5)).rgb +
|
|
|
|
texture(tex, texCo + dir * (2.0 / 3.0 - 0.5)).rgb);
|
|
|
|
vec3 rgbB = rgbA * 0.5 + 0.25 * (
|
|
|
|
texture(tex, texCo + dir * -0.5).rgb +
|
|
|
|
texture(tex, texCo + dir * 0.5).rgb);
|
2016-07-12 12:03:43 +02:00
|
|
|
|
|
|
|
float lumaB = dot(rgbB, luma);
|
2017-03-11 01:50:47 +01:00
|
|
|
if ((lumaB < lumaMin) || (lumaB > lumaMax)) fragColor.rgb = rgbA;
|
|
|
|
else fragColor.rgb = rgbB;
|
2016-08-15 23:45:03 +02:00
|
|
|
|
2016-10-21 19:36:08 +02:00
|
|
|
#else
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CDOF
|
2017-11-04 18:35:34 +01:00
|
|
|
fragColor.rgb = dof(texCo, depth, tex, gbufferD, texStep, cameraProj);
|
2016-10-21 19:36:08 +02:00
|
|
|
#else
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb = texture(tex, texCo).rgb;
|
2016-10-21 19:36:08 +02:00
|
|
|
#endif
|
2016-08-15 23:45:03 +02:00
|
|
|
|
|
|
|
#endif
|
2018-02-24 12:16:11 +01:00
|
|
|
|
|
|
|
#ifdef _CSharpen
|
|
|
|
vec3 col1 = texture(tex, texCo + vec2(-texStep.x, -texStep.y) * 1.5).rgb;
|
|
|
|
vec3 col2 = texture(tex, texCo + vec2(texStep.x, -texStep.y) * 1.5).rgb;
|
|
|
|
vec3 col3 = texture(tex, texCo + vec2(-texStep.x, texStep.y) * 1.5).rgb;
|
|
|
|
vec3 col4 = texture(tex, texCo + vec2(texStep.x, texStep.y) * 1.5).rgb;
|
|
|
|
vec3 colavg = (col1 + col2 + col3 + col4) * 0.25;
|
|
|
|
// const float sharpness = 0.5;
|
|
|
|
fragColor.rgb += (fragColor.rgb - colavg) * sharpness;
|
|
|
|
#endif
|
2016-08-15 23:45:03 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CFog
|
2016-08-29 09:56:34 +02:00
|
|
|
// if (depth < 1.0) {
|
2017-11-04 18:35:34 +01:00
|
|
|
// vec3 pos = getPos(depth, cameraProj);
|
2016-08-29 09:56:34 +02:00
|
|
|
// float dist = distance(pos, eye);
|
2017-11-04 18:35:34 +01:00
|
|
|
float dist = linearize(depth, cameraProj);
|
2016-08-29 09:56:34 +02:00
|
|
|
// vec3 eyedir = eyeLook;// normalize(eye + pos);
|
2017-03-11 01:50:47 +01:00
|
|
|
// fragColor.rgb = applyFog(fragColor.rgb, dist, eye, eyedir);
|
|
|
|
fragColor.rgb = applyFog(fragColor.rgb, dist);
|
2016-08-29 09:56:34 +02:00
|
|
|
// }
|
2016-08-15 23:45:03 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CGlare
|
2016-10-23 15:32:26 +02:00
|
|
|
if (dot(light, eyeLook) > 0.0) { // Facing light
|
|
|
|
vec4 lndc = VP * vec4(light, 1.0);
|
|
|
|
lndc.xy /= lndc.w;
|
|
|
|
vec2 lss = lndc.xy * 0.5 + 0.5;
|
2017-11-04 18:35:34 +01:00
|
|
|
float lssdepth = linearize(texture(gbufferD, lss).r * 2.0 - 1.0, cameraProj);
|
2016-10-23 15:32:26 +02:00
|
|
|
float lightDistance = distance(eye, light);
|
|
|
|
if (lightDistance <= lssdepth) {
|
|
|
|
vec2 lensuv = texCo * 2.0 - 1.0;
|
|
|
|
lensuv.x *= aspectRatio;
|
|
|
|
vec3 lensflarecol = vec3(1.4, 1.2, 1.0) * lensflare(lensuv, lndc.xy);
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb += lensflarecol;
|
2016-10-23 15:32:26 +02:00
|
|
|
}
|
2016-08-15 23:45:03 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CGrain
|
2016-08-15 23:45:03 +02:00
|
|
|
// const float compoGrainStrength = 4.0;
|
2016-10-23 15:32:26 +02:00
|
|
|
float x = (texCo.x + 4.0) * (texCo.y + 4.0) * (time * 10.0);
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb += vec3(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01) - 0.005) * compoGrainStrength;
|
2016-07-12 12:03:43 +02:00
|
|
|
#endif
|
2016-04-18 01:44:37 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CVignette
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb *= vignette();
|
2016-08-15 23:45:03 +02:00
|
|
|
#endif
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CExposure
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb *= compoExposureStrength;
|
2016-08-15 23:45:03 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-18 22:52:41 +01:00
|
|
|
#ifdef _AutoExposure
|
|
|
|
vec3 expo = textureLod(tex, vec2(0,0), 100).rgb;
|
|
|
|
fragColor.rgb *= vec3(1.0) - min(expo, vec3(autoExposureStrength));
|
|
|
|
#endif
|
2017-08-14 10:31:08 +02:00
|
|
|
#ifdef _Hist // Auto-exposure
|
|
|
|
if (texCoord.x < 0.1) fragColor.rgb = textureLod(histogram, vec2(0, 0), 9.0).rrr; // 512x512
|
|
|
|
// float minBrightness = 0.03f;
|
|
|
|
// float maxBrightness = 2.0f;
|
|
|
|
// float minAdaptation = 0.60f;
|
|
|
|
// float maxAdaptation = 0.9f;
|
|
|
|
// float minFractionSum = minAdaptation * sumValue;
|
|
|
|
// float maxFractionSum = maxAdaptation * sumValue;
|
|
|
|
// float sumWithoutOutliers = 0.0f;
|
|
|
|
// float sumWithoutOutliersRaw = 0.0f;
|
|
|
|
// for (int i = 0; i < numHistogramBuckets; ++i) {
|
|
|
|
// float localValue = luminanceHistogram[i];
|
|
|
|
// float vmin = min(localValue, minFractionSum);
|
|
|
|
// localValue -= vmin;
|
|
|
|
// localValue = localValue - vmin;
|
|
|
|
// minFractionSum -= vmin;
|
|
|
|
// maxFractionSum -= vmin;
|
|
|
|
// localValue = min(localValue, maxFractionSum);
|
|
|
|
// maxFractionSum -= localValue;
|
|
|
|
// float luminanceAtBucket = GetLuminanceAtBucket(i);
|
|
|
|
// sumWithoutOutliers += luminanceAtBucket * localValue;
|
|
|
|
// sumWithoutOutliersRaw += localValue;
|
|
|
|
// }
|
|
|
|
// float unclampedLuminance = sumWithoutOutliers / max(0.0001f, sumWithoutOutliersRaw);
|
|
|
|
// float clampedLuminace = clamp(unclampedLuminance, minBrightness, maxBrightness);
|
|
|
|
#endif
|
|
|
|
|
2017-02-25 00:57:13 +01:00
|
|
|
#ifdef _CToneFilmic
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb = tonemapFilmic(fragColor.rgb); // With gamma
|
2016-08-15 23:45:03 +02:00
|
|
|
#endif
|
2017-02-25 00:57:13 +01:00
|
|
|
#ifdef _CToneFilmic2
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb = acesFilm(fragColor.rgb);
|
|
|
|
fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));
|
2017-02-25 00:57:13 +01:00
|
|
|
#endif
|
|
|
|
#ifdef _CToneReinhard
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb = tonemapReinhard(fragColor.rgb);
|
|
|
|
fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2));
|
2017-02-25 00:57:13 +01:00
|
|
|
#endif
|
|
|
|
#ifdef _CToneUncharted
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb = tonemapUncharted2(fragColor.rgb);
|
|
|
|
fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2)); // To gamma
|
2017-02-25 00:57:13 +01:00
|
|
|
#endif
|
|
|
|
#ifdef _CToneNone
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb = pow(fragColor.rgb, vec3(1.0 / 2.2)); // To gamma
|
2017-02-25 00:57:13 +01:00
|
|
|
#endif
|
2016-04-08 21:55:07 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CBW
|
2017-03-11 01:50:47 +01:00
|
|
|
// fragColor.rgb = vec3(clamp(dot(fragColor.rgb, fragColor.rgb), 0.0, 1.0));
|
|
|
|
fragColor.rgb = vec3((fragColor.r * 0.3 + fragColor.g * 0.59 + fragColor.b * 0.11) / 3.0) * 2.5;
|
2016-06-22 12:21:15 +02:00
|
|
|
#endif
|
2016-09-16 01:11:34 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
// #ifdef _CContrast
|
2016-09-16 01:11:34 +02:00
|
|
|
// -0.5 - 0.5
|
2016-10-23 15:32:26 +02:00
|
|
|
// const float compoContrast = 0.2;
|
2017-03-11 01:50:47 +01:00
|
|
|
// fragColor.rgb = ((fragColor.rgb - 0.5) * max(compoContrast + 1.0, 0.0)) + 0.5;
|
2016-10-17 00:02:51 +02:00
|
|
|
// #endif
|
2016-09-16 01:11:34 +02:00
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
// #ifdef _CBrighness
|
2017-03-11 01:50:47 +01:00
|
|
|
// fragColor.rgb += compoBrightness;
|
2016-09-16 01:11:34 +02:00
|
|
|
// #endif
|
|
|
|
|
2017-02-25 17:13:22 +01:00
|
|
|
#ifdef _CLensTex
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb += texture(lensTexture, texCo).rgb;
|
2017-02-25 17:13:22 +01:00
|
|
|
#endif
|
|
|
|
|
2016-12-20 01:39:16 +01:00
|
|
|
#ifdef _CLetterbox
|
2016-08-15 23:45:03 +02:00
|
|
|
// const float compoLetterboxSize = 0.1;
|
2017-03-11 01:50:47 +01:00
|
|
|
fragColor.rgb *= 1.0 - step(0.5 - compoLetterboxSize, abs(0.5 - texCo.y));
|
2016-08-15 23:45:03 +02:00
|
|
|
#endif
|
2017-12-07 17:09:44 +01:00
|
|
|
|
|
|
|
//3D LUT Implementation from GPUGems 2 by Nvidia
|
|
|
|
//https://developer.nvidia.com/gpugems/GPUGems2/gpugems2_chapter24.html
|
|
|
|
|
|
|
|
#ifdef _CLUT
|
|
|
|
fragColor = LUTlookup(fragColor, lutTexture);
|
|
|
|
#endif
|
2016-03-23 23:35:44 +01:00
|
|
|
}
|