From 1a447eb06ae83d154a085bb6c9f15e6e33031d0b Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Sat, 28 Dec 2013 09:15:12 -0500 Subject: [PATCH] Begin adding border shading (vignette) postprocessing effect --- gl_rmain.c | 8 ++++++-- shader_glsl.h | 12 ++++++++++++ shader_hlsl.h | 12 ++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index 338950aa..0bac7f36 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -881,9 +881,10 @@ enum SHADERSTATICPARM_SHADOWSAMPLER = 10, ///< sampler SHADERSTATICPARM_CELSHADING = 11, ///< celshading (alternative diffuse and specular math) SHADERSTATICPARM_CELOUTLINES = 12, ///< celoutline (depth buffer analysis to produce outlines) - SHADERSTATICPARM_FXAA = 13 ///< fast approximate anti aliasing + SHADERSTATICPARM_FXAA = 13, ///< fast approximate anti aliasing + SHADERSTATICPARM_BORDERSHADING = 14 ///< darken edges of screen with shaded gradient }; -#define SHADERSTATICPARMS_COUNT 14 +#define SHADERSTATICPARMS_COUNT 15 static const char *shaderstaticparmstrings_list[SHADERSTATICPARMS_COUNT]; static int shaderstaticparms_count = 0; @@ -933,6 +934,8 @@ qboolean R_CompileShader_CheckStaticParms(void) if (r_celoutlines.integer) R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_CELOUTLINES); + R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_BORDERSHADING); + return memcmp(r_compileshader_staticparms, r_compileshader_staticparms_save, sizeof(r_compileshader_staticparms)) != 0; } @@ -960,6 +963,7 @@ static void R_CompileShader_AddStaticParms(unsigned int mode, unsigned int permu R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_CELSHADING, "USECELSHADING"); R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_CELOUTLINES, "USECELOUTLINES"); R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_FXAA, "USEFXAA"); + R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_BORDERSHADING, "USEBORDERSHADING"); } /// information about each possible shader permutation diff --git a/shader_glsl.h b/shader_glsl.h index 1c6cb906..8eb4c0c9 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -342,6 +342,18 @@ " dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + vec3(max(0.0, sobel - UserVec2.z))*UserVec2.y;\n", "#endif\n", "\n", +"#ifdef USEBORDERSHADING\n", +" // scaled simple border shading\n", +" // todo: replace the following with cvarred settings\n", +" float vertpad = 0.15;\n", +" float horipad = 0.1;\n", +" float multiplier = 4.0;\n", +" float dist = min(horipad + TexCoord1.x, min(vertpad + TexCoord1.y, min((1.0 + horipad) - TexCoord1.x, (1.0 + vertpad) - TexCoord1.y)));\n", +"\n", +" dist = clamp(dist * multiplier, 0.0, 1.0);\n", +" dp_FragColor.xyz *= dist;\n", +"#endif\n", +"\n", "#ifdef USEBLOOM\n", " dp_FragColor += max(vec4(0,0,0,0), dp_texture2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n", "#endif\n", diff --git a/shader_hlsl.h b/shader_hlsl.h index e81e6039..34ebee6c 100644 --- a/shader_hlsl.h +++ b/shader_hlsl.h @@ -246,6 +246,18 @@ " dp_FragColor.rgb = dp_FragColor.rgb * (1.0 + UserVec2.x) + float3(1,1,1)*max(0.0, sobel - UserVec2.z)*UserVec2.y;\n", "#endif\n", "\n", +"#ifdef USEBORDERSHADING\n", +" // scaled simple border shading\n", +" // todo: replace the following with cvarred settings\n", +" float vertpad = 0.15;\n", +" float horipad = 0.1;\n", +" float multiplier = 4.0;\n", +" float dist = min(horipad + TexCoord1.x, min(vertpad + TexCoord1.y, min((1.0 + horipad) - TexCoord1.x, (1.0 + vertpad) - TexCoord1.y)));\n", +"\n", +" dist = clamp(dist * multiplier, 0.0, 1.0);\n", +" dp_FragColor.xyz *= dist;\n", +"#endif\n", +"\n", "#ifdef USEBLOOM\n", " dp_FragColor += max(float4(0,0,0,0), tex2D(Texture_Second, TexCoord2) - BloomColorSubtract);\n", "#endif\n", -- 2.39.2