#version 150 #extension GL_ARB_shader_image_load_store : enable #define ATTRIN in #define ATTROUT out #define VARYIN centroid in #define VARYOUT centroid out #define float2 vec2 #define float3 vec3 #define float4 vec4 #define frac fract #define lerp mix #define texture2DRect texture #define COLOROUT(name) out vec4 name; /*===============================================================================*\ |######################## [DOLPHIN FX 1.00] #########################| |######################## [BY ASMODEAN@PCSX2] #########################| || || || This program is free software; you can redistribute it and/or || || modify it under the terms of the GNU General Public License || || as published by the Free Software Foundation; either version 2 || || of the License, or (at your option) any later version. || || || || This program is distributed in the hope that it will be useful, || || but WITHOUT ANY WARRANTY; without even the implied warranty of || || MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the || || GNU General Public License for more details. || || || |#################################################################################| \*===============================================================================*/ #extension GL_NV_gpu_shader5 : enable #extension GL_ARB_gpu_shader5 : enable #extension GL_NV_draw_buffers : enable #extension GL_ARB_draw_buffers : enable #extension GL_ARB_sample_shading : enable #extension GL_ARB_shader_precision : enable #extension GL_ARB_texture_rectangle : enable #extension GL_ARB_shader_texture_lod : enable #extension GL_ARB_texture_multisample : enable #extension GL_ARB_vertex_attrib_64bit : enable #extension GL_NV_explicit_multisample : enable #extension GL_ARB_uniform_buffer_object : enable #ifdef GL_FRAGMENT_PRECISION_HIGH precision highp int; precision highp float; precision highp sampler2D; #endif /*------------------------------------------------------------------------------ [DEFINITIONS & ON/OFF OPTIONS] ------------------------------------------------------------------------------*/ //---------------------------#[CHOOSE EFFECTS]#--------------------------------\\ //-#[ANTIALIASING TECHNIQUES] [1=ON|0=OFF] #READ: For best results, only enable one type of AA at one time. #define NFAA_PASS 0 //#Normal Filter Anti Aliasing (Subtle AA, with good edge detection). #define FXAA_PASS 1 //#Fast Approximate Anti Aliasing. Jaggies begone!(fps hit). //-#[TEXTURE FILTERING] [1=ON|0=OFF] #READ: For best results, don't use this with AA, use the built-in AA filter option. Only enable one type of filtering at one time. #define BICUBIC_FILTERING 0 //#Bezier Spline BiCubic Texture Filtering. Use an AA method or this. Not both. //-#[LIGHTING & COLOUR] [1=ON|0=OFF] #READ: These can all be turned on & off independently of each other. (HDR = Bloom, Tonemapping, & Gamma Correction used together) #define BLOOM_PASS 1 //#HQ Bloom high pass [For best results: use bloom, gamma & tone mapping together](lower-end gpu fps hit). #define SCENE_TONEMAPPING 1 //#Scene Color Correction & Tonemapping [For best results: use bloom, gamma & tone mapping together]. #define GAMMA_CORRECTION 1 //#Per-Channel Post Inverse Gamma Correction [For best results: use bloom, gamma & tone mapping together]. #define S_CURVE_CONTRAST 1 //#S-Curve Scene Contrast Enhancement. Naturally adjusts contrast using S-curves. #define TEXTURE_SHARPENING 1 //#HQ Luma-Based Texture Sharpen, looks similar to a negative mip LOD Bias, enhances texture fidelity. Can interfere with Bloom's glow blur. #define TOON_SHADING 0 //#Cartoon-Style look, I'm still working on improving this, but it works fine for now. /*------------------------------------------------------------------------------ [SHADER FX CONFIG OPTIONS] ------------------------------------------------------------------------------*/ //-[NFAA OPTIONS] #if (NFAA_PASS == 1) #define FilterStrength 15.0f; //Anti aliasing strength. The overall strength of the effect. Rule of thumb when changing this: (lower strength->higher spread : higher strength->lower spread) #define FilterSpread 0.25f; //Filter spread width. For best results, keep a good balance between the strength and spread. #define BilinearNFAA 0 //Uses Bilinear texture filtering in the NFAA texture sampling.(Extra filtering.) bool UseColor = false; //Uses color detection, instead of luma edge detection (more coverage, less accuracy). bool debug = false; //Visualize the edge detection. #endif //-[FXAA OPTIONS] #if (FXAA_PASS == 1) #define FXAASubpixMax (8.0) //Amount of subpixel aliasing removal. Higher values = (softer). Lower values = (sharper) #define FXAAEdgeThreshold (0.125f) //FXAA edge reduction threshold. The minimum amount of local contrast required to apply algorithm. #define FXAAEdgeThresholdMin (0.0078f) //FXAA edge reduction threshold min. Trims the algorithm from processing darks. #define BilinearFXAA 0 //Uses Bilinear texture filtering in the FXAA texture sampling.(Extra filtering.) #endif //-[BLOOM OPTIONS] #if (BLOOM_PASS == 1) #define BloomType BlendScreen //The type of blend for the bloom -[BlendScreen, BlendOverlay, BlendAddLight] (Default: BlendScreen) #define BloomPower 0.500f //[0.000 to 1.000] Strength of the bloom. blooms naturally, per environment. You will need to adjust for each bloom type. #define BlurSpread 2.000f //[0.000 to 8.000] Width of the blooms' 'glow' offset. 0.000 = off. Default is 2.000 with BlendPower 2, and 4.000 with BlendPower 1. #define BlendPower 2 //[1 or 2] Strength of the blend glow. This only applies to the BlendScreen Bloom type. 1 is light, 2 is strong. At 2, you may want to reduce BlurSpread to compensate eg: to 2.000. #endif //-[TONEMAP OPTIONS] #if (SCENE_TONEMAPPING == 1) #define ToneAmount 0.80f //[0.10 to 1.00] Gamma levels (Tonemapping/Shadow correction) lower: darker tones, higher: lighter tones. #define Luma 100.00f //Luma Correction(luma correction) Higher values = lower luma, lower = higher luma. Adjust by small amounts, eg: increments of 1 #define Exposure 100.00f //White Correction (brightness correction) Higher values = more exposure, lower = less exposure. Adjust by small amounts, eg: increments of 1 #define WhitePoint 1.00f //Whitepoint Avg (fog correction) Adjust by small amounts, eg: increments of 0.01 #endif //-[CONTRAST OPTIONS] #if (S_CURVE_CONTRAST == 1) #define CurveType 0 //[0|1|2] Choose what to apply contrast to. 0 = Luma, 1 = Chroma, 2 = both Luma and Chroma. Default is 0 (Luma) #define CurvesContrast 0.50f //[-1.00 to 2.00] The amount of contrast you want #define CurvesFormula 2 //[1|2] The contrast s-curve you want to use. 1 is a harsher type. 2 is a softer type. #endif //-[SHARPEN OPTIONS] #if (TEXTURE_SHARPENING == 1) #define SharpenStrength 0.45f //[0.10 to 1.00] Strength of the sharpening effect. #define SharpenClamp 0.035f //[0.000 to 1.000] Clamps maximum amount of sharpening each pixel recieves. #define OffsetBias 4.00f //[1.00 to 6.00] Offset bias. Use 1.0 for clean crisp sharpen, higher (eg: 6.0) for a deeper textured sharpen. #endif //-[TOON SHADER OPTIONS] #if (TOON_SHADING == 1) #define ToonVibrance 0.10f //[-1.00 to 1.00] Vibrance adjustment. Higher values increase pixel vibrance, lower values reduce it. #define ToonStrength 2.00f //[0.10 to 10.00] Strength of the toon outline effect. #define ToonEdgeSlope 0.68f //[0.10 to 2.00] Raise this to filter out fainter edges. You might need to increase the power to compensate. #endif //-[GAMMA OPTIONS] #if (GAMMA_CORRECTION == 1) #define Gamma 2.2f //Lower values for more Gamma toning(darker), higher Values for brighter (2.2 correction is generally recommended) #endif //-END OF USER OPTIONS. /*------------------------------------------------------------------------------ [GLOBAL VARIABLES] ------------------------------------------------------------------------------*/ uniform sampler2D samp9; uniform sampler2D samp7; uniform vec4 resolution; smooth in vec2 uv0; smooth out vec4 ocol0; float RGBLuminance(vec3 color) { vec3 lumCoeff = vec3(0.212656f, 0.715158f, 0.072186f); return dot(color.rgb, lumCoeff); } #define GammaCorrection(color, gamma) pow(color, gamma) #define InverseGammaCorrection(color, gamma) pow(color, 1.0f/gamma) float BSpline(float x) { float f = abs(x); if(f <= 1.0 ) return (( 2.0 / 3.0 ) + ( 0.5 ) * ( f * f * f ) - (f * f)); else { f = 2.0 - f; return (1.0 / 6.0 * f * f * f); } } /*------------------------------------------------------------------------------ [TEXTURE FILTERING CODE SECTION] ------------------------------------------------------------------------------*/ #if (BICUBIC_FILTERING == 1) vec4 BiCubicFilter(sampler2D tex, vec2 TexCoord) { float fx = fract(TexCoord.x); float fy = fract(TexCoord.y); TexCoord.x -= fx; TexCoord.y -= fy; vec4 xcubic = vec4(BSpline(- 1 - fx), BSpline(-fx), BSpline(1 - fx), BSpline(2 - fx)); vec4 ycubic = vec4(BSpline(- 1 - fy), BSpline(-fy), BSpline(1 - fy), BSpline(2 - fy)); vec4 c = vec4(TexCoord.x - 0.5f, TexCoord.x + 1.5f, TexCoord.y - 0.5f, TexCoord.y + 1.5f); vec4 s = vec4(xcubic.x + xcubic.y, xcubic.z + xcubic.w, ycubic.x + ycubic.y, ycubic.z + ycubic.w); vec4 offset = c + vec4(xcubic.y, xcubic.w, ycubic.y, ycubic.w) / s; vec4 sample0 = texture(tex, vec2(offset.x, offset.z) / resolution.xy); vec4 sample1 = texture(tex, vec2(offset.y, offset.z) / resolution.xy); vec4 sample2 = texture(tex, vec2(offset.x, offset.w) / resolution.xy); vec4 sample3 = texture(tex, vec2(offset.y, offset.w) / resolution.xy); float sx = s.x / (s.x + s.y); float sy = s.z / (s.z + s.w); return mix(mix(sample3, sample2, sx), mix(sample1, sample0, sx), sy); } vec4 BiCubicPass(vec4 color, vec2 TexCoord) { color = BiCubicFilter(samp9, TexCoord * resolution.xy); return color; } #endif vec4 textureBiLinear(sampler2D tex, vec2 TexCoord) { float texelSizeX = (1.0 / resolution.x); //size of one texel float texelSizeY = (1.0 / resolution.y); //size of one texel int nX = int( TexCoord.x * resolution.x ); int nY = int( TexCoord.y * resolution.y ); vec2 texCoord_New = vec2( ( float( nX ) + 0.5 ) / resolution.x, ( float( nY ) + 0.5 ) / resolution.y ); // Take nearest two data in current row. vec4 p0q0 = texture(tex, texCoord_New); vec4 p1q0 = texture(tex, texCoord_New + vec2(texelSizeX, 0)); // Take nearest two data in bottom row. vec4 p0q1 = texture(tex, texCoord_New + vec2(0, texelSizeY)); vec4 p1q1 = texture(tex, texCoord_New + vec2(texelSizeX , texelSizeY)); float a = fract(TexCoord.x * resolution.x); // Get Interpolation factor for X direction. // Interpolation in X direction. vec4 pInterp_q0 = mix( p0q0, p1q0, a ); // Interpolates top row in X direction. vec4 pInterp_q1 = mix( p0q1, p1q1, a ); // Interpolates bottom row in X direction. float b = fract(TexCoord.y * resolution.y); // Get Interpolation factor for Y direction. return mix(pInterp_q0, pInterp_q1, b); // Interpolate in Y direction. } /*------------------------------------------------------------------------------ [NFAA CODE SECTION] ------------------------------------------------------------------------------*/ #if (NFAA_PASS == 1) vec2 rcpres = vec2(resolution.z, resolution.w); float filterStrength = FilterStrength; float filterSpread = FilterSpread; float GetColorLuminance(vec3 color) { vec3 lumCoeff = vec3(0.212656f, 0.715158f, 0.072186f); return dot(color.rgb, lumCoeff); } vec2 findContrastByLuminance(vec2 TexCoord) { // Normal offsets, scale by filter spread vec2 upOffset = vec2( 0, rcpres.y ) * filterSpread; vec2 rightOffset = vec2( rcpres.x, 0 ) * filterSpread; float topHeight = GetColorLuminance( texture( samp9, TexCoord + upOffset ).rgb ); float bottomHeight = GetColorLuminance( texture( samp9, TexCoord - upOffset ).rgb ); float rightHeight = GetColorLuminance( texture( samp9, TexCoord + rightOffset ).rgb ); float leftHeight = GetColorLuminance( texture( samp9, TexCoord - rightOffset ).rgb ); float leftTopHeight = GetColorLuminance( texture( samp9, TexCoord - rightOffset + upOffset).rgb ); float leftBottomHeight = GetColorLuminance( texture( samp9, TexCoord - rightOffset - upOffset).rgb ); float rightBottomHeight = GetColorLuminance( texture( samp9, TexCoord + rightOffset + upOffset).rgb ); float rightTopHeight = GetColorLuminance( texture( samp9, TexCoord + rightOffset - upOffset).rgb ); // Normal map creation float sum0 = rightTopHeight + bottomHeight + leftTopHeight; float sum1 = leftBottomHeight + topHeight + rightBottomHeight; float sum2 = leftTopHeight + rightHeight + leftBottomHeight; float sum3 = rightBottomHeight + leftHeight + rightTopHeight; // Subtract the opposite sample set for final vectors float vector1 = (sum0 - sum1) * filterStrength; float vector2 = (sum3 - sum2) * filterStrength; vec2 Vectors = vec2(vector1, vector2); return Vectors; } vec2 findContrastByColor(vec2 TexCoord) { // Normal offsets, scale by filter spread vec2 upOffset = vec2( 0, rcpres.y ) * filterSpread; vec2 rightOffset = vec2( rcpres.x, 0 ) * filterSpread; vec3 topHeight = texture( samp9, TexCoord + upOffset ).rgb; vec3 bottomHeight = texture( samp9, TexCoord - upOffset ).rgb; vec3 rightHeight = texture( samp9, TexCoord + rightOffset ).rgb; vec3 leftHeight = texture( samp9, TexCoord - rightOffset ).rgb; vec3 leftTopHeight = texture( samp9, TexCoord - rightOffset + upOffset).rgb; vec3 leftBottomHeight = texture( samp9, TexCoord - rightOffset - upOffset).rgb; vec3 rightBottomHeight = texture( samp9, TexCoord + rightOffset + upOffset).rgb; vec3 rightTopHeight = texture( samp9, TexCoord + rightOffset - upOffset).rgb; // Normal map creation vec3 sum0 = rightTopHeight + bottomHeight + leftTopHeight; vec3 sum1 = leftBottomHeight + topHeight + rightBottomHeight; vec3 sum2 = leftTopHeight + rightHeight + leftBottomHeight; vec3 sum3 = rightBottomHeight + leftHeight + rightTopHeight; // Subtract the opposite sample set for final vectors float vector1 = length(sum0 - sum1) * filterStrength; float vector2 = length(sum3 - sum2) * filterStrength; vec2 Vectors = vec2(vector1, vector2); return Vectors; } vec4 NFAAPass(vec4 o_Color, vec2 Vectors) { filterStrength += (filterSpread/2); if (UseColor) { Vectors = findContrastByColor(uv0.xy); } else { Vectors = findContrastByLuminance(uv0.xy); } float filterClamp = filterStrength/filterSpread; Vectors.xy = clamp(Vectors, -vec2(filterClamp,filterClamp), vec2(filterClamp,filterClamp)); vec2 Normal = vec2(Vectors.x, Vectors.y) * rcpres; #if (BilinearNFAA == 1) vec4 Scene0 = textureBiLinear(samp9, uv0.xy); vec4 Scene1 = textureBiLinear(samp9, uv0.xy + Normal.xy); vec4 Scene2 = textureBiLinear(samp9, uv0.xy - Normal.xy); vec4 Scene3 = textureBiLinear(samp9, uv0.xy + vec2(Normal.x, -Normal.y)); vec4 Scene4 = textureBiLinear(samp9, uv0.xy - vec2(Normal.x, -Normal.y)); #else vec4 Scene0 = texture(samp9, uv0.xy, 0.0); vec4 Scene1 = texture(samp9, uv0.xy + Normal.xy, 0.0); vec4 Scene2 = texture(samp9, uv0.xy - Normal.xy, 0.0); vec4 Scene3 = texture(samp9, uv0.xy + vec2(Normal.x, -Normal.y), 0.0); vec4 Scene4 = texture(samp9, uv0.xy - vec2(Normal.x, -Normal.y), 0.0); #endif // Final color o_Color = (Scene0 + Scene1 + Scene2 + Scene3 + Scene4) * 0.2f; o_Color.a = RGBLuminance(o_Color.rgb); // Debug Output if (debug) { o_Color.xyz = normalize(vec3(Vectors.x, Vectors.y, 1.0) * 0.5 + 0.5); } return o_Color; } #endif /*------------------------------------------------------------------------------ [FXAA CODE SECTION] ------------------------------------------------------------------------------*/ #if (FXAA_PASS == 1) vec4 applyFXAA(vec2 TexCoord, sampler2D tex) { vec4 color; vec2 inverseVP = resolution.zw; vec3 rgbNW = texture(tex, (TexCoord + vec2(-1.0, -1.0)) * inverseVP).xyz; vec3 rgbNE = texture(tex, (TexCoord + vec2(1.0, -1.0)) * inverseVP).xyz; vec3 rgbSW = texture(tex, (TexCoord + vec2(-1.0, 1.0)) * inverseVP).xyz; vec3 rgbSE = texture(tex, (TexCoord + vec2(1.0, 1.0)) * inverseVP).xyz; vec3 rgbM = texture(tex, TexCoord * inverseVP).xyz; vec3 luma = vec3(0.2125, 0.7154, 0.0721); float lumaNW = dot(rgbNW, luma); float lumaNE = dot(rgbNE, luma); float lumaSW = dot(rgbSW, luma); float lumaSE = dot(rgbSE, luma); float lumaM = dot(rgbM, luma); float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); vec2 dir; dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAAEdgeThreshold), FXAAEdgeThresholdMin); float rcpDirMin = 1.0f / (min(abs(dir.x), abs(dir.y)) + dirReduce); dir = min(vec2(FXAASubpixMax, FXAASubpixMax), max(vec2(-FXAASubpixMax, -FXAASubpixMax), dir * rcpDirMin)) * inverseVP; #if (BilinearFXAA == 1) vec3 rgbA = 0.5f * ( textureBiLinear(tex, TexCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + textureBiLinear(tex, TexCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz); vec3 rgbB = rgbA * 0.5f + 0.25f * ( textureBiLinear(tex, TexCoord * inverseVP + dir * -0.5).xyz + textureBiLinear(tex, TexCoord * inverseVP + dir * 0.5).xyz); #else vec3 rgbA = 0.5f * ( texture(tex, TexCoord * inverseVP + dir * (1.0 / 3.0 - 0.5)).xyz + texture(tex, TexCoord * inverseVP + dir * (2.0 / 3.0 - 0.5)).xyz); vec3 rgbB = rgbA * 0.5f + 0.25f * ( texture(tex, TexCoord * inverseVP + dir * -0.5).xyz + texture(tex, TexCoord * inverseVP + dir * 0.5).xyz); #endif float lumaB = dot(rgbB, luma); if ((lumaB < lumaMin) || (lumaB > lumaMax)) color = vec4(rgbA, RGBLuminance(color.rgb)); else color = vec4(rgbB, RGBLuminance(color.rgb)); return color; } vec4 DoFXAA(sampler2D FxaaTex, vec2 TexCoord) { vec4 FxaaColor = texture(samp9, TexCoord); vec2 rcpFrame = vec2(resolution.x, resolution.y); FxaaColor = applyFXAA(TexCoord * rcpFrame, FxaaTex); FxaaColor.a = dot(FxaaColor.rgb, vec3(0.212656, 0.715158, 0.072186)); return FxaaColor; } vec4 FXAAPass(vec4 FxaaColor, vec2 TexCoord) { FxaaColor = DoFXAA(samp9, TexCoord); return FxaaColor; } #endif /*------------------------------------------------------------------------------ [GAMMA CORRECTION CODE SECTION] ------------------------------------------------------------------------------*/ #if (GAMMA_CORRECTION == 1) vec4 GammaPass(vec4 colorInput, vec2 TexCoord) { float gamma = Gamma; vec3 correctedGamma; correctedGamma.r = InverseGammaCorrection(colorInput.r, (gamma/2.2f)); correctedGamma.g = InverseGammaCorrection(colorInput.g, (gamma/2.2f)); correctedGamma.b = InverseGammaCorrection(colorInput.b, (gamma/2.2f)); colorInput.rgb = correctedGamma.rgb; colorInput.a = RGBLuminance(colorInput.rgb); return colorInput; } #endif /*------------------------------------------------------------------------------ [LUMA SHARPEN CODE SECTION] ------------------------------------------------------------------------------*/ #if (TEXTURE_SHARPENING == 1) #define px resolution.z #define py resolution.w #define CoefLuma vec3(0.212656, 0.715158, 0.072186) #define sharp_strength_luma (CoefLuma * SharpenStrength) vec4 TextureSharpen(vec4 color, vec2 TexCoord) { vec3 ori = texture(samp9, TexCoord).rgb; vec3 blur_ori = texture(samp9, TexCoord + vec2(-px,py) * OffsetBias).rgb; blur_ori += texture(samp9, TexCoord + vec2(px,-py) * OffsetBias).rgb; blur_ori += texture(samp9, TexCoord + vec2(-px,-py) * OffsetBias).rgb; blur_ori += texture(samp9, TexCoord + vec2(px,py) * OffsetBias).rgb; blur_ori += ori.rgb; blur_ori += texture(samp9, TexCoord + vec2(0,py) * OffsetBias).rgb; blur_ori += texture(samp9, TexCoord + vec2(0,-py) * OffsetBias).rgb; blur_ori += texture(samp9, TexCoord + vec2(-px,0) * OffsetBias).rgb; blur_ori += texture(samp9, TexCoord + vec2(px,0) * OffsetBias).rgb; blur_ori /= 9.0f; vec3 sharp = ori - blur_ori; float sharp_luma = dot(sharp, sharp_strength_luma); sharp_luma = clamp(sharp_luma, -SharpenClamp, SharpenClamp); color.rgb = color.rgb + sharp_luma; color.a = RGBLuminance(color.rgb); //color = (0.5f + (sharp_luma * 4)).rrrr; //visualise sharpening (for debugging) return clamp(color, 0.0, 1.0); } #endif /*------------------------------------------------------------------------------ [BLOOM PASS CODE SECTION] ------------------------------------------------------------------------------*/ #if (BLOOM_PASS == 1) const float blurspread = BlurSpread; const float bloomPower = BloomPower; vec3 BlendScreen(vec3 base, vec3 blend) { if (BlendPower == 1) return (base + blend) - (base * blend); else return (blend + blend) - (blend * blend); } vec3 BlendAddLight(vec3 base, vec3 blend) { return base + blend; } vec3 BlendOverlay(vec3 base, vec3 blend) { return vec3((blend.x <= 0.5) ? (2.0 * base.x * blend.x) : (1.0 - 2.0 * (1.0 - blend.x) * (1.0 - base.x)), (blend.y <= 0.5) ? (2.0 * base.y * blend.y) : (1.0 - 2.0 * (1.0 - blend.y) * (1.0 - base.y)), (blend.z <= 0.5) ? (2.0 * base.z * blend.z) : (1.0 - 2.0 * (1.0 - blend.z) * (1.0 - base.z))); } vec4 BloomPass(vec4 color, vec2 TexCoord) { vec4 blur = texture(samp9, TexCoord); blur = color * 0.22520613262190495; vec2 dx = vec2(resolution.z * blurspread, 0.0); vec2 dy = vec2(0.0, resolution.w * 2.0 * blurspread); vec2 dx2 = 2 * dx; vec2 dy2 = 2 * dy; vec4 colorU = texture(samp9, TexCoord + dy); blur += 0.002589001911021066 * texture(samp9, TexCoord -dx2 +dy2); blur += 0.010778807494659370 * texture(samp9, TexCoord -dx +dy2); blur += 0.024146616900339800 * texture(samp9, TexCoord +dy2); blur += 0.010778807494659370 * texture(samp9, TexCoord +dx +dy2); blur += 0.002589001911021066 * texture(samp9, TexCoord +dx2 +dy2); blur += 0.010778807494659370 * texture(samp9, TexCoord -dx2 +dy); blur += 0.044875475183061630 * texture(samp9, TexCoord -dx +dy); blur += 0.100529757860782610 * texture(samp9, TexCoord +dy); blur += 0.044875475183061630 * texture(samp9, TexCoord +dx +dy); blur += 0.010778807494659370 * texture(samp9, TexCoord +dx2 +dy); blur += 0.024146616900339800 * texture(samp9, TexCoord -dx2); blur += 0.100529757860782610 * texture(samp9, TexCoord -dx); blur += 0.100529757860782610 * texture(samp9, TexCoord +dx); blur += 0.024146616900339800 * texture(samp9, TexCoord +dx2); blur += 0.010778807494659370 * texture(samp9, TexCoord -dx2 -dy); blur += 0.044875475183061630 * texture(samp9, TexCoord -dx -dy); blur += 0.100529757860782610 * texture(samp9, TexCoord -dy); blur += 0.044875475183061630 * texture(samp9, TexCoord +dx -dy); blur += 0.010778807494659370 * texture(samp9, TexCoord +dx2 -dy); blur += 0.002589001911021066 * texture(samp9, TexCoord -dx2 -dy2); blur += 0.010778807494659370 * texture(samp9, TexCoord -dx -dy2); blur += 0.024146616900339800 * texture(samp9, TexCoord -dy2); blur += 0.010778807494659370 * texture(samp9, TexCoord +dx -dy2); blur += 0.002589001911021066 * texture(samp9, TexCoord +dx2 -dy2); vec4 newcolor; newcolor.rgb = BloomType(color.rgb, blur.rgb); newcolor.a = RGBLuminance(newcolor.rgb); color.a = RGBLuminance(color.rgb); color = mix(color, newcolor, bloomPower); return color; } #endif /*------------------------------------------------------------------------------ [COLOR CORRECTION PASS CODE SECTION] ------------------------------------------------------------------------------*/ #if (SCENE_TONEMAPPING == 1) vec4 TonemapPass(vec4 colorInput, vec2 TexCoord) { // Average scene luminance is stored in R channel float avgLuminance = Luma; float exposure = Exposure; float whitePoint = WhitePoint; float blackLevel = ToneAmount; //TEXCOORD mapping swap vec2 colorTexel = vec2(0,0); //Scene tone mapping vec4 ColorTone = texture(samp7, TexCoord); // Detect dark areas, depending on mapping type if(ColorTone.r < 0.3f && ColorTone.g < 0.3f && ColorTone.b < 0.3f) { colorTexel = TexCoord; colorInput.r = InverseGammaCorrection(colorInput.r, (blackLevel)); colorInput.g = InverseGammaCorrection(colorInput.g, (blackLevel)); colorInput.b = InverseGammaCorrection(colorInput.b, (blackLevel)); } vec3 lumCoeff = vec3(0.212656f, 0.715158f, 0.072186f); // RGB -> XYZ conversion const mat3 RGB2XYZ = mat3(0.4124564f, 0.3575761f, 0.1804375f, 0.2126729f, 0.7151522f, 0.0721750f, 0.0193339f, 0.1191920f, 0.9503041f); vec3 XYZ = (colorInput.rgb*RGB2XYZ); // XYZ -> Yxy conversion vec3 Yxy = lumCoeff; Yxy.r = XYZ.g; // copy luminance Y Yxy.g = XYZ.r / (XYZ.r + XYZ.g + XYZ.b ); // x = X / (X + Y + Z) Yxy.b = XYZ.g / (XYZ.r + XYZ.g + XYZ.b ); // y = Y / (X + Y + Z) // (Lp) Map average luminance to the middlegrey zone by scaling pixel luminance float Lp = Yxy.r * exposure / avgLuminance; // (Ld) Scale all luminance within a displayable range of 0 to 1 Yxy.r = (Lp * (1.0f + Lp/(whitePoint * whitePoint)))/(1.0f + Lp); // Yxy -> XYZ conversion XYZ.r = Yxy.r * Yxy.g / Yxy. b; // X = Y * x / y XYZ.g = Yxy.r; // copy luminance Y XYZ.b = Yxy.r * (1 - Yxy.g - Yxy.b) / Yxy.b; // Z = Y * (1-x-y) / y // XYZ -> RGB conversion const mat3 XYZ2RGB = mat3(3.2404542f, -1.5371385f, -0.4985314f, -0.9692660f, 1.8760108f, 0.0415560f, 0.0556434f, -0.2040259f, 1.0572252f); colorInput.rgb = (XYZ*XYZ2RGB); colorInput.a = RGBLuminance(colorInput.rgb); return colorInput; } #endif /*------------------------------------------------------------------------------ [S_CURVE CONTRAST CODE SECTION] ------------------------------------------------------------------------------*/ #if (S_CURVE_CONTRAST == 1) vec4 CurvesPass(vec4 colorInput, vec2 TexCoord) { vec3 lumCoeff = vec3(0.212656, 0.715158, 0.072186); float Curves_contrast_blend = CurvesContrast; float PI = acos(-1); //3.1415926589 #if (CurveType != 2) float luma = dot(colorInput.rgb, lumCoeff); vec3 chroma = colorInput.rgb - luma; #endif #if (CurveType == 2) vec3 x = colorInput.rgb; #elif (CurveType == 1) vec3 x = chroma; x = x * 0.5 + 0.5; #else float x = luma; #endif // -- Curve 1 -- Cubic Bezier spline #if (CurvesFormula == 1) float a = 0.00; //start point float b = 0.00; //control point 1 float c = 1.00; //control point 2 float d = 1.00; //endpoint float r = (1-x); float r2 = r*r; float r3 = r2 * r; float x2 = x*x; float x3 = x2*x; x = a*(1-x)*(1-x)*(1-x) + 3*b*(1-x)*(1-x)*x + 3*c*(1-x)*x*x + d*x*x*x; #endif // -- Curve 2 -- Cubic Bezier spline II #if (CurvesFormula == 2) vec3 a = vec3(0.00f,0.00f,0.00f); //start point vec3 b = vec3(0.25f,0.15f,0.85f); //control point 1 vec3 c = vec3(0.75f,0.85f,0.15f); //control point 2 vec3 d = vec3(1.00f,1.00f,1.00f); //endpoint vec3 ab = mix(a,b,x); // point between a and b (green) vec3 bc = mix(b,c,x); // point between b and c (green) vec3 cd = mix(c,d,x); // point between c and d (green) vec3 abbc = mix(ab,bc,x); // point between ab and bc (blue) vec3 bccd = mix(bc,cd,x); // point between bc and cd (blue) vec3 dest = mix(abbc,bccd,x); // point on the bezier-curve (black) x = dest; #endif #if (CurveType == 2) //Both Luma and Chroma vec3 color = x; colorInput.rgb = mix(colorInput.rgb, color, Curves_contrast_blend); #elif (CurveType == 1) //Only Chroma x = x * 2 - 1; vec3 color = luma + x; //Luma + Chroma colorInput.rgb = mix(colorInput.rgb, color, Curves_contrast_blend); #else // CurveType == 0 //Only Luma x = mix(luma, x, Curves_contrast_blend); colorInput.rgb = x + chroma; //Luma + Chroma colorInput.a = RGBLuminance(colorInput.rgb); #endif return colorInput; } #endif #if (TOON_SHADING == 1) vec4 CelPass(vec4 colorInput, vec2 TexCoord) { #define pixel vec2(resolution.z,resolution.w) vec3 ToonLumaCoef = vec3(0.2126, 0.7152, 0.0722); float Tluma = dot(colorInput.rgb, ToonLumaCoef); float Tmax_color = max(colorInput.r, max(colorInput.g,colorInput.b)); float Tmin_color = min(colorInput.r, min(colorInput.g,colorInput.b)); float Tcolor_saturation = Tmax_color - Tmin_color; colorInput.rgb = mix(vec3(Tluma), colorInput.rgb, (1.0 + (ToonVibrance * (1.0-(sign(ToonVibrance) * Tcolor_saturation))))); float diff1 = dot(ToonLumaCoef, texture(samp9, TexCoord + pixel).rgb); diff1 = dot(vec4(ToonLumaCoef, -1.0), vec4(texture(samp9, TexCoord - pixel).rgb, diff1)); float diff2 = dot(ToonLumaCoef, texture(samp9, TexCoord +vec2(pixel.x,-pixel.y)).rgb); diff2 = dot(vec4(ToonLumaCoef, -1.0), vec4(texture(samp9, TexCoord +vec2(-pixel.x,pixel.y)).rgb, diff2)); float edge = dot(vec2(diff1, diff2), vec2(diff1, diff2)); colorInput.rgb = pow(edge,ToonEdgeSlope) * -ToonStrength + colorInput.rgb; colorInput.a = RGBLuminance(colorInput.rgb); return colorInput; } #endif /*------------------------------------------------------------------------------ [MAIN() & COMBINE PASS CODE SECTION] ------------------------------------------------------------------------------*/ void main() { #if (NFAA_PASS == 0 && FXAA_PASS == 0 && BICUBIC_FILTERING == 0) ocol0 = texture(samp9, uv0); ocol0.a = RGBLuminance(ocol0.rgb); #endif #if (BICUBIC_FILTERING) ocol0 = BiCubicPass(ocol0, uv0); #endif #if (NFAA_PASS == 1) ocol0 = NFAAPass(ocol0, uv0); #endif #if (FXAA_PASS == 1) ocol0 = FXAAPass(ocol0, uv0); #endif #if (GAMMA_CORRECTION == 1) ocol0 = GammaPass(ocol0, uv0); #endif #if (TEXTURE_SHARPENING == 1) ocol0 = TextureSharpen(ocol0, uv0); #endif #if (BLOOM_PASS == 1) ocol0 = BloomPass(ocol0, uv0); #endif #if (SCENE_TONEMAPPING == 1) ocol0 = TonemapPass(ocol0, uv0); #endif #if (S_CURVE_CONTRAST == 1) ocol0 = CurvesPass(ocol0, uv0); #endif #if (TOON_SHADING == 1) ocol0 = CelPass(ocol0, uv0); #endif } Fragment shader failed to compile with the following errors: WARNING: 1:18: warning(#62) enable/warn/disable extension is not found. Extension "GL_NV_gpu_shader5" is not supported WARNING: 1:20: warning(#62) enable/warn/disable extension is not found. Extension "GL_NV_draw_buffers" is not supported WARNING: 1:27: warning(#62) enable/warn/disable extension is not found. Extension "GL_ARB_vertex_attrib_64bit" is not supported ERROR: 1:690: error(#160) Cannot convert from: "highp 3-component vector of vec3" to: "highp float" ERROR: error(#273) 1 compilation errors. No code generated