From 7164f549843898736fdbf4dd461e0c59d5911143 Mon Sep 17 00:00:00 2001 From: vortex Date: Sat, 19 Mar 2011 20:26:54 +0000 Subject: [PATCH] Add "Both Alphas" technique for VertexTextureBlend (use both layer alpha's for microblending), toggled globally by "r_glsl_vertextextureblend_usebothalphas" cvar. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10937 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=129b7033f5fc1864d34031fcb35044409587a24f --- gl_rmain.c | 9 ++++++++- shader_glsl.h | 6 ++++++ shader_hlsl.h | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/gl_rmain.c b/gl_rmain.c index 6638a3a0..fbeb3b2e 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -207,6 +207,8 @@ cvar_t r_overheadsprites_scaley = {CVAR_SAVE, "r_overheadsprites_scaley", "1", " cvar_t r_glsl_saturation = {CVAR_SAVE, "r_glsl_saturation", "1", "saturation multiplier (only working in glsl!)"}; cvar_t r_glsl_saturation_redcompensate = {CVAR_SAVE, "r_glsl_saturation_redcompensate", "0", "a 'vampire sight' addition to desaturation effect, does compensation for red color, r_glsl_restart is required"}; +cvar_t r_glsl_vertextextureblend_usebothalphas = {CVAR_SAVE, "r_glsl_vertextextureblend_usebothalphas", "0", "use both alpha layers on vertex blended surfaces, each alpha layer sets amount of 'blend leak' on another layer."}; + cvar_t r_framedatasize = {CVAR_SAVE, "r_framedatasize", "0.5", "size of renderer data cache used during one frame (for skeletal animation caching, light processing, etc)"}; extern cvar_t v_glslgamma; @@ -845,7 +847,8 @@ enum SHADERSTATICPARM_POSTPROCESS_USERVEC1 = 2, ///< postprocess uservec1 is enabled SHADERSTATICPARM_POSTPROCESS_USERVEC2 = 3, ///< postprocess uservec2 is enabled SHADERSTATICPARM_POSTPROCESS_USERVEC3 = 4, ///< postprocess uservec3 is enabled - SHADERSTATICPARM_POSTPROCESS_USERVEC4 = 5 ///< postprocess uservec4 is enabled + SHADERSTATICPARM_POSTPROCESS_USERVEC4 = 5, ///< postprocess uservec4 is enabled + SHADERSTATICPARM_VERTEXTEXTUREBLEND_USEBOTHALPHAS = 6 // use both alpha layers while blending materials, allows more advanced microblending }; #define SHADERSTATICPARMS_COUNT 6 @@ -863,6 +866,8 @@ qboolean R_CompileShader_CheckStaticParms(void) // detect all if (r_glsl_saturation_redcompensate.integer) R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_SATURATION_REDCOMPENSATE); + if (r_glsl_vertextextureblend_usebothalphas.integer) + R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_VERTEXTEXTUREBLEND_USEBOTHALPHAS); if (r_shadow_glossexact.integer) R_COMPILESHADER_STATICPARM_ENABLE(SHADERSTATICPARM_EXACTSPECULARMATH); if (r_glsl_postprocess.integer) @@ -895,6 +900,7 @@ void R_CompileShader_AddStaticParms(unsigned int mode, unsigned int permutation) R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_POSTPROCESS_USERVEC2, "USERVEC2"); R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_POSTPROCESS_USERVEC3, "USERVEC3"); R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_POSTPROCESS_USERVEC4, "USERVEC4"); + R_COMPILESHADER_STATICPARM_EMIT(SHADERSTATICPARM_VERTEXTEXTUREBLEND_USEBOTHALPHAS, "USEBOTHALPHAS"); } /// information about each possible shader permutation @@ -4135,6 +4141,7 @@ void GL_Main_Init(void) Cvar_RegisterVariable(&r_test); Cvar_RegisterVariable(&r_glsl_saturation); Cvar_RegisterVariable(&r_glsl_saturation_redcompensate); + Cvar_RegisterVariable(&r_glsl_vertextextureblend_usebothalphas); Cvar_RegisterVariable(&r_framedatasize); if (gamemode == GAME_NEHAHRA || gamemode == GAME_TENEBRAE) Cvar_SetValue("r_fullbrights", 0); diff --git a/shader_glsl.h b/shader_glsl.h index d8513c5d..0d4d3b5f 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -1087,10 +1087,16 @@ " color.rgb += myhalf3(offsetMappedTexture2D(Texture_Pants)) * Color_Pants + myhalf3(offsetMappedTexture2D(Texture_Shirt)) * Color_Shirt;\n" "#endif\n" "#ifdef USEVERTEXTEXTUREBLEND\n" +"#ifdef USEBOTHALPHAS\n" +" myhalf4 color2 = myhalf4(dp_texture2D(Texture_SecondaryColor, TexCoord2));\n" +" myhalf terrainblend = clamp(myhalf(VertexColor.a) * color.a, myhalf(1.0 - color2.a), myhalf(1.0));\n" +" color.rgb = mix(color2.rgb, color.rgb, terrainblend);\n" +"#else\n" " myhalf terrainblend = clamp(myhalf(VertexColor.a) * color.a * 2.0 - 0.5, myhalf(0.0), myhalf(1.0));\n" " //myhalf terrainblend = min(myhalf(VertexColor.a) * color.a * 2.0, myhalf(1.0));\n" " //myhalf terrainblend = myhalf(VertexColor.a) * color.a > 0.5;\n" " color.rgb = mix(myhalf3(dp_texture2D(Texture_SecondaryColor, TexCoord2)), color.rgb, terrainblend);\n" +"#endif\n" " color.a = 1.0;\n" " //color = mix(myhalf4(1, 0, 0, 1), color, terrainblend);\n" "#endif\n" diff --git a/shader_hlsl.h b/shader_hlsl.h index f5d1dd8a..67824e75 100644 --- a/shader_hlsl.h +++ b/shader_hlsl.h @@ -1250,6 +1250,11 @@ " color.rgb += half3(offsetMappedTexture2D(Texture_Pants).rgb) * Color_Pants + half3(offsetMappedTexture2D(Texture_Shirt).rgb) * Color_Shirt;\n" "#endif\n" "#ifdef USEVERTEXTEXTUREBLEND\n" +"#ifdef USEBOTHALPHAS\n" +" half4 color2 = half4(tex2D(Texture_SecondaryColor, TexCoord2));\n" +" half terrainblend = clamp(half(gl_FrontColor.a) * color.a, half(1.0 - color2.a), half(1.0));\n" +" color.rgb = lerp(color2.rgb, color.rgb, terrainblend);\n" +"#else\n" " half terrainblend = clamp(half(gl_FrontColor.a) * color.a * 2.0 - 0.5, half(0.0), half(1.0));\n" " //half terrainblend = min(half(gl_FrontColor.a) * color.a * 2.0, half(1.0));\n" " //half terrainblend = half(gl_FrontColor.a) * color.a > 0.5;\n" @@ -1257,6 +1262,7 @@ " color.a = 1.0;\n" " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n" "#endif\n" +"#endif\n" "\n" " // get the surface normal\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -- 2.39.2