1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-07 03:13:49 +00:00

Rewrite glowShader.

This commit is contained in:
Sergey Lipskiy 2015-02-02 14:57:15 +06:00
parent 501e8a44b0
commit 8f69e6cfa9

View File

@ -128,36 +128,45 @@ static const char* glowShader =
" lowp vec4 dst = texture2D(Sample0, vTexCoord); // rendered scene \n"
" lowp vec4 src = texture2D(Sample1, vTexCoord); // glowmap \n"
" \n"
" if ( BlendMode == 0 ) \n"
" { \n"
" // Additive blending (strong result, high overexposure) \n"
" fragColor = min(src + dst, 1.0); \n"
" } \n"
" else if ( BlendMode == 1 ) \n"
" { \n"
" // Screen blending (mild result, medium overexposure) \n"
" fragColor = clamp((src + dst) - (src * dst), 0.0, 1.0); \n"
" fragColor.a = 1.0; \n"
" } \n"
" else if ( BlendMode == 2 ) \n"
" { \n"
" // Softlight blending (light result, no overexposure) \n"
" // Due to the nature of soft lighting, we need to bump the black region of the glowmap \n"
" // to 0.5, otherwise the blended result will be dark (black soft lighting will darken \n"
" // the image). \n"
" src = (src * 0.5) + 0.5; \n"
" \n"
" fragColor.rgb = vec3((src.x <= 0.5) ? (dst.x - (1.0 - 2.0 * src.x) * dst.x * (1.0 - dst.x)) : (((src.x > 0.5) && (dst.x <= 0.25)) ? (dst.x + (2.0 * src.x - 1.0) * (4.0 * dst.x * (4.0 * dst.x + 1.0) * (dst.x - 1.0) + 7.0 * dst.x)) : (dst.x + (2.0 * src.x - 1.0) * (sqrt(dst.x) - dst.x))), \n"
" (src.y <= 0.5) ? (dst.y - (1.0 - 2.0 * src.y) * dst.y * (1.0 - dst.y)) : (((src.y > 0.5) && (dst.y <= 0.25)) ? (dst.y + (2.0 * src.y - 1.0) * (4.0 * dst.y * (4.0 * dst.y + 1.0) * (dst.y - 1.0) + 7.0 * dst.y)) : (dst.y + (2.0 * src.y - 1.0) * (sqrt(dst.y) - dst.y))), \n"
" (src.z <= 0.5) ? (dst.z - (1.0 - 2.0 * src.z) * dst.z * (1.0 - dst.z)) : (((src.z > 0.5) && (dst.z <= 0.25)) ? (dst.z + (2.0 * src.z - 1.0) * (4.0 * dst.z * (4.0 * dst.z + 1.0) * (dst.z - 1.0) + 7.0 * dst.z)) : (dst.z + (2.0 * src.z - 1.0) * (sqrt(dst.z) - dst.z))));\n"
" fragColor.a = 1.0; \n"
" } \n"
" else \n"
" { \n"
" // Show just the glow map \n"
" fragColor = src; \n"
" } \n"
"} \n"
" switch (BlendMode) { \n"
" case 0: \n"
" // Additive blending (strong result, high overexposure) \n"
" fragColor = min(src + dst, 1.0); \n"
" fragColor.a = 1.0; \n"
" break; \n"
" case 1: \n"
" fragColor = clamp((src + dst) - (src * dst), 0.0, 1.0); \n"
" fragColor.a = 1.0; \n"
" break; \n"
" case 2: \n"
" src = (src * 0.5) + 0.5; \n"
" \n"
" if (src.x <= 0.5) \n"
" fragColor.x = dst.x - (1.0 - 2.0 * src.x) * dst.x * (1.0 - dst.x); \n"
" else if ((src.x > 0.5) && (dst.x <= 0.25)) \n"
" fragColor.x = dst.x + (2.0 * src.x - 1.0) * (4.0 * dst.x * (4.0 * dst.x + 1.0) * (dst.x - 1.0) + 7.0 * dst.x);\n"
" else \n"
" fragColor.x = dst.x + (2.0 * src.x - 1.0) * (sqrt(dst.x) - dst.x); \n"
" if (src.y <= 0.5) \n"
" fragColor.y = dst.y - (1.0 - 2.0 * src.y) * dst.y * (1.0 - dst.y); \n"
" else if ((src.y > 0.5) && (dst.y <= 0.25)) \n"
" fragColor.y = dst.y + (2.0 * src.y - 1.0) * (4.0 * dst.y * (4.0 * dst.y + 1.0) * (dst.y - 1.0) + 7.0 * dst.y);\n"
" else \n"
" fragColor.y = dst.y + (2.0 * src.y - 1.0) * (sqrt(dst.y) - dst.y); \n"
" if (src.z <= 0.5) \n"
" fragColor.z = dst.z - (1.0 - 2.0 * src.z) * dst.z * (1.0 - dst.z); \n"
" else if ((src.z > 0.5) && (dst.z <= 0.25)) \n"
" fragColor.z = dst.z + (2.0 * src.z - 1.0) * (4.0 * dst.z * (4.0 * dst.z + 1.0) * (dst.z - 1.0) + 7.0 * dst.z);\n"
" else \n"
" fragColor.z = dst.z + (2.0 * src.z - 1.0) * (sqrt(dst.z) - dst.z); \n"
" fragColor.a = 1.0; \n"
" break; \n"
" default: \n"
" // Show just the glow map \n"
" fragColor = src; \n"
" break; \n"
" } \n"
"} \n"
;
static const char* simpleBloomShader =