From: Rudolf Polzer Date: Tue, 11 Feb 2014 10:46:39 +0000 (+0100) Subject: r_stereo_desaturate - improve anaglyph stere experience X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8c74398f9853953f39a0da2265dcd11bb85b9deb;p=xonotic%2Fdarkplaces.git r_stereo_desaturate - improve anaglyph stere experience --- diff --git a/cl_screen.c b/cl_screen.c index f476d3c0..3d437099 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -81,6 +81,7 @@ cvar_t r_stereo_vertical = {0, "r_stereo_vertical", "0", "aspect skewed top and cvar_t r_stereo_redblue = {0, "r_stereo_redblue", "0", "red/blue anaglyph stereo glasses (note: most of these glasses are actually red/cyan, try that one too)"}; cvar_t r_stereo_redcyan = {0, "r_stereo_redcyan", "0", "red/cyan anaglyph stereo glasses, the kind given away at drive-in movies like Creature From The Black Lagoon In 3D"}; cvar_t r_stereo_redgreen = {0, "r_stereo_redgreen", "0", "red/green anaglyph stereo glasses (for those who don't mind yellow)"}; +cvar_t r_stereo_desaturate = {0, "r_stereo_desaturate", "0", "when using anaglyph stereo glasses, desaturate the image for less irritation by the given factor"}; cvar_t r_stereo_angle = {0, "r_stereo_angle", "0", "separation angle of eyes (makes the views look different directions, as an example, 90 gives a 90 degree separation where the views are 45 degrees left and 45 degrees right)"}; cvar_t scr_stipple = {0, "scr_stipple", "0", "interlacing-like stippling of the display"}; cvar_t scr_refresh = {0, "scr_refresh", "1", "allows you to completely shut off rendering for benchmarking purposes"}; @@ -1385,6 +1386,7 @@ void CL_Screen_Init(void) Cvar_RegisterVariable(&r_stereo_redblue); Cvar_RegisterVariable(&r_stereo_redcyan); Cvar_RegisterVariable(&r_stereo_redgreen); + Cvar_RegisterVariable(&r_stereo_desaturate); Cvar_RegisterVariable(&r_stereo_angle); Cvar_RegisterVariable(&scr_stipple); Cvar_RegisterVariable(&scr_refresh); diff --git a/dpsoftrast.h b/dpsoftrast.h index 5bda9f36..efc68975 100644 --- a/dpsoftrast.h +++ b/dpsoftrast.h @@ -307,6 +307,7 @@ typedef enum DPSOFTRAST_UNIFORM_e DPSOFTRAST_UNIFORM_ShadowMapMatrixM4, DPSOFTRAST_UNIFORM_BloomColorSubtract, DPSOFTRAST_UNIFORM_NormalmapScrollBlend, + DPSOFTRAST_UNIFORM_StereoDesaturate, DPSOFTRAST_UNIFORM_OffsetMapping_LodDistance, DPSOFTRAST_UNIFORM_OffsetMapping_Bias, DPSOFTRAST_UNIFORM_TOTAL diff --git a/gl_rmain.c b/gl_rmain.c index 1ebe76c7..d8872f42 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -852,6 +852,7 @@ typedef struct r_glsl_permutation_s int loc_ShadowMapMatrix; int loc_BloomColorSubtract; int loc_NormalmapScrollBlend; + int loc_StereoDesaturate; int loc_BounceGridMatrix; int loc_BounceGridIntensity; /// uniform block bindings @@ -881,9 +882,11 @@ 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_STEREODESATURATE = 14, ///< stereo desaturation + SHADERSTATICPARM_STEREODESATURATE_REDCYAN = 15 ///< red/cyan stereo desaturation (set in addition to the previous one) }; -#define SHADERSTATICPARMS_COUNT 14 +#define SHADERSTATICPARMS_COUNT 16 static const char *shaderstaticparmstrings_list[SHADERSTATICPARMS_COUNT]; static int shaderstaticparms_count = 0; @@ -933,6 +936,14 @@ qboolean R_CompileShader_CheckStaticParms(void) if (r_celoutlines.integer) R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_CELOUTLINES); + if (r_stereo_desaturate.value != 0) + if (r_stereo_redblue.integer || r_stereo_redcyan.integer || r_stereo_redgreen.integer) + { + R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_STEREODESATURATE); + if (r_stereo_redcyan.integer) + R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_STEREODESATURATE_REDCYAN); + } + return memcmp(r_compileshader_staticparms, r_compileshader_staticparms_save, sizeof(r_compileshader_staticparms)) != 0; } @@ -960,6 +971,8 @@ 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_STEREODESATURATE, "USESTEREODESATURATE"); + R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_STEREODESATURATE_REDCYAN, "USESTEREODESATURATE_REDCYAN"); } /// information about each possible shader permutation @@ -1271,6 +1284,7 @@ static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode p->loc_ShadowMapMatrix = qglGetUniformLocation(p->program, "ShadowMapMatrix"); p->loc_BloomColorSubtract = qglGetUniformLocation(p->program, "BloomColorSubtract"); p->loc_NormalmapScrollBlend = qglGetUniformLocation(p->program, "NormalmapScrollBlend"); + p->loc_StereoDesaturate = qglGetUniformLocation(p->program, "StereoDesaturate"); p->loc_BounceGridMatrix = qglGetUniformLocation(p->program, "BounceGridMatrix"); p->loc_BounceGridIntensity = qglGetUniformLocation(p->program, "BounceGridIntensity"); // initialize the samplers to refer to the texture units we use @@ -1498,7 +1512,8 @@ typedef enum D3DPSREGISTER_e D3DPSREGISTER_NormalmapScrollBlend = 52, D3DPSREGISTER_OffsetMapping_LodDistance = 53, D3DPSREGISTER_OffsetMapping_Bias = 54, - // next at 54 + D3DPSREGISTER_StereoDesaturate = 55, + // next at 56 } D3DPSREGISTER_t; @@ -2659,6 +2674,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, if (mode == SHADERMODE_WATER) hlslPSSetParameter2f(D3DPSREGISTER_NormalmapScrollBlend, rsurface.texture->r_water_waterscroll[0], rsurface.texture->r_water_waterscroll[1]); } + hlslPSSetParameter1f(D3DPSREGISTER_StereoDesaturate, r_stereo_desaturate.value); hlslPSSetParameter2f(D3DPSREGISTER_ShadowMap_TextureScale, r_shadow_shadowmap_texturescale[0], r_shadow_shadowmap_texturescale[1]); hlslPSSetParameter4f(D3DPSREGISTER_ShadowMap_Parameters, r_shadow_shadowmap_parameters[0], r_shadow_shadowmap_parameters[1], r_shadow_shadowmap_parameters[2], r_shadow_shadowmap_parameters[3]); hlslPSSetParameter3f(D3DPSREGISTER_Color_Glow, rsurface.glowmod[0], rsurface.glowmod[1], rsurface.glowmod[2]); @@ -2819,6 +2835,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, if (r_glsl_permutation->loc_SpecularPower >= 0) qglUniform1f(r_glsl_permutation->loc_SpecularPower, rsurface.texture->specularpower * (r_shadow_glossexact.integer ? 0.25f : 1.0f) - 1.0f); if (r_glsl_permutation->loc_NormalmapScrollBlend >= 0) qglUniform2f(r_glsl_permutation->loc_NormalmapScrollBlend, rsurface.texture->r_water_waterscroll[0], rsurface.texture->r_water_waterscroll[1]); } + if (r_glsl_permutation->loc_StereoDesaturate >= 0) qglUniform1f(r_glsl_permutation->loc_StereoDesaturate, r_stereo_desaturate.value); if (r_glsl_permutation->loc_TexMatrix >= 0) {Matrix4x4_ToArrayFloatGL(&rsurface.texture->currenttexmatrix, m16f);qglUniformMatrix4fv(r_glsl_permutation->loc_TexMatrix, 1, false, m16f);} if (r_glsl_permutation->loc_BackgroundTexMatrix >= 0) {Matrix4x4_ToArrayFloatGL(&rsurface.texture->currentbackgroundtexmatrix, m16f);qglUniformMatrix4fv(r_glsl_permutation->loc_BackgroundTexMatrix, 1, false, m16f);} if (r_glsl_permutation->loc_ShadowMapMatrix >= 0) {Matrix4x4_ToArrayFloatGL(&r_shadow_shadowmapmatrix, m16f);qglUniformMatrix4fv(r_glsl_permutation->loc_ShadowMapMatrix, 1, false, m16f);} @@ -2965,6 +2982,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_SpecularPower, rsurface.texture->specularpower * (r_shadow_glossexact.integer ? 0.25f : 1.0f) - 1.0f); DPSOFTRAST_Uniform2f(DPSOFTRAST_UNIFORM_NormalmapScrollBlend, rsurface.texture->r_water_waterscroll[0], rsurface.texture->r_water_waterscroll[1]); } + DPSOFTRAST_Uniform1f(DPSOFTRAST_UNIFORM_StereoDesaturate, r_stereo_desaturate.value); {Matrix4x4_ToArrayFloatGL(&rsurface.texture->currenttexmatrix, m16f);DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_TexMatrixM1, 1, false, m16f);} {Matrix4x4_ToArrayFloatGL(&rsurface.texture->currentbackgroundtexmatrix, m16f);DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_BackgroundTexMatrixM1, 1, false, m16f);} {Matrix4x4_ToArrayFloatGL(&r_shadow_shadowmapmatrix, m16f);DPSOFTRAST_UniformMatrix4fv(DPSOFTRAST_UNIFORM_ShadowMapMatrixM1, 1, false, m16f);} diff --git a/screen.h b/screen.h index 4d473244..c41010fe 100644 --- a/screen.h +++ b/screen.h @@ -68,6 +68,10 @@ extern cvar_t scr_stipple; extern cvar_t r_stereo_separation; extern cvar_t r_stereo_angle; +extern cvar_t r_stereo_redblue; +extern cvar_t r_stereo_redcyan; +extern cvar_t r_stereo_redgreen; +extern cvar_t r_stereo_desaturate; qboolean R_Stereo_Active(void); extern int r_stereo_side; diff --git a/shader_glsl.h b/shader_glsl.h index 1c6cb906..6b98c8fa 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -1431,6 +1431,9 @@ "#ifdef USENORMALMAPSCROLLBLEND\n", "uniform highp vec2 NormalmapScrollBlend;\n", "#endif\n", +"#ifdef USESTEREODESATURATE\n", +"uniform myhalf StereoDesaturate;\n", +"#endif\n", "void main(void)\n", "{\n", "#ifdef USEOFFSETMAPPING\n", @@ -1737,6 +1740,29 @@ " color.rgb = mix(color.rgb, cast_myhalf3(dp_texture2D(Texture_Reflection, ScreenTexCoord)) * ReflectColor.rgb, ReflectColor.a);\n", "#endif\n", "\n", +"#ifdef USESTEREODESATURATE\n", +"#ifdef USESTEREODESATURATE_REDCYAN\n", +" // Goal of this transformation:\n", +" // Keep brightness of R and GB proportional to each other and to\n", +" // original brightness.\n", +" // Retain some coloring (keep G-B invariant except for a factor).\n", +" // Screw sRGB, BT.709 Luma is good enough.\n", +" color.rgb = mix(color.rgb, cast_myhalf3(\n", +" 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b,\n", +" 0.2126 * color.r + 0.7874 * color.g,\n", +" 0.2126 * color.r + 0.7874 * color.b\n", +" ), StereoDesaturate);\n", +"#else\n", +" // Goal of this transformation:\n", +" // Keep brightness of R and G (or B) proportional to each other and to\n", +" // original brightness.\n", +" // Screw sRGB, BT.709 Luma is good enough.\n", +" color.rgb = mix(color.rgb, cast_myhalf3(\n", +" 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b\n", +" ), StereoDesaturate);\n", +"#endif\n", +"#endif\n", +"\n", " dp_FragColor = vec4(color);\n", "}\n", "#endif // FRAGMENT_SHADER\n", diff --git a/shader_hlsl.h b/shader_hlsl.h index e81e6039..3ea74ef6 100644 --- a/shader_hlsl.h +++ b/shader_hlsl.h @@ -1303,6 +1303,10 @@ "uniform float OffsetMapping_Bias : register(c54),\n", "#endif\n", "\n", +"#ifdef USESTEREODESATURATE\n", +"uniform float StereoDesaturate : register(c55),\n", +"#endif\n", +"\n", "#ifdef USEDEFERREDLIGHTMAP\n", "uniform half2 PixelToScreenTexCoord : register(c42),\n", "uniform half3 DeferredMod_Diffuse : register(c12),\n", @@ -1615,6 +1619,29 @@ " color.rgb = lerp(color.rgb, half3(tex2D(Texture_Reflection, ScreenTexCoord).rgb) * ReflectColor.rgb, ReflectColor.a);\n", "#endif\n", "\n", +"#ifdef USESTEREODESATURATE\n", +"#ifdef USESTEREODESATURATE_REDCYAN\n", +" // Goal of this transformation:\n", +" // Keep brightness of R and GB proportional to each other and to\n", +" // original brightness.\n", +" // Retain some coloring (keep G-B invariant except for a factor).\n", +" // Screw sRGB, BT.709 Luma is good enough.\n", +" color.rgb = lerp(color.rgb, half3(\n", +" 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b,\n", +" 0.2126 * color.r + 0.7874 * color.g,\n", +" 0.2126 * color.r + 0.7874 * color.b\n", +" ), StereoDesaturate);\n", +"#else\n", +" // Goal of this transformation:\n", +" // Keep brightness of R and G (or B) proportional to each other and to\n", +" // original brightness.\n", +" // Screw sRGB, BT.709 Luma is good enough.\n", +" color.rgb = lerp(color.rgb, half3(\n", +" 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b\n", +" ), StereoDesaturate);\n", +"#endif\n", +"#endif\n", +"\n", " dp_FragColor = float4(color);\n", "}\n", "#endif // FRAGMENT_SHADER\n",