From: vortex Date: Sat, 19 Mar 2011 20:26:54 +0000 (+0000) Subject: Add "Both Alphas" technique for VertexTextureBlend (use both layer alpha's for microb... X-Git-Tag: xonotic-v0.6.0~163^2~609 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=129b7033f5fc1864d34031fcb35044409587a24f;p=xonotic%2Fdarkplaces.git 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 --- diff --git a/gl_rmain.c b/gl_rmain.c index a2ab80ea..2cc3d857 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -206,6 +206,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; @@ -844,7 +846,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 @@ -862,6 +865,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) @@ -894,6 +899,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 @@ -4133,6 +4139,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 515556ae..955d49e2 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"