]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
r_stereo_desaturate - improve anaglyph stere experience
authorRudolf Polzer <divverent@xonotic.org>
Tue, 11 Feb 2014 10:46:39 +0000 (11:46 +0100)
committerRudolf Polzer <divverent@xonotic.org>
Tue, 11 Feb 2014 11:04:02 +0000 (12:04 +0100)
cl_screen.c
dpsoftrast.h
gl_rmain.c
screen.h
shader_glsl.h
shader_hlsl.h

index f476d3c09e6d94a0d8c3a908f1013b52d17b4e02..3d437099fe95332bb484c1f1b678c1bf8f595288 100644 (file)
@@ -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);
index 5bda9f36198e40879ebecaacdc7c94c4e1ba7a40..efc689750a368b68b85a547e21dede9724d20954 100644 (file)
@@ -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
index 1ebe76c788c9bf66384b804262d6edcdc8a2a8bd..d8872f4222cf328acee1c15d57a72f91ddaaf42b 100644 (file)
@@ -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);}
index 4d473244db46f261e0cc80843c3a4487e5ac5e03..c41010fe18a37dede8379f8df0e889466843f152 100644 (file)
--- 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;
 
index 1c6cb906768149fce8126ff71705baf75a5ec494..6b98c8fa668983daf5ef16b374a55fffb9eb14c9 100644 (file)
 "#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",
 "      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",
index e81e603990d4912e3bb1d7545f4c875eb5fcce64..3ea74ef657835aa42545116f7b9fa7a01442d09a 100644 (file)
 "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",
 "      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",