From ac06747ee6947f193afc671a8457869ea85dcf40 Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 13 Dec 2011 20:44:37 +0000 Subject: [PATCH] support alphaGen vertex git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11615 d7cf8633-e32d-0410-b094-e92efae38249 --- dpsoftrast.h | 3 ++- gl_rmain.c | 11 +++++++++++ model_brush.h | 2 ++ model_shared.c | 2 ++ shader_glsl.h | 5 ++++- shader_hlsl.h | 7 +++++-- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/dpsoftrast.h b/dpsoftrast.h index c30f69a6..69228ef8 100644 --- a/dpsoftrast.h +++ b/dpsoftrast.h @@ -195,7 +195,8 @@ typedef enum shaderpermutation_e SHADERPERMUTATION_BOUNCEGRIDDIRECTIONAL = 1<<26, ///< (lightmap) use 16-component pixels in bouncegrid texture for directional lighting rather than standard 4-component SHADERPERMUTATION_TRIPPY = 1<<27, ///< use trippy vertex shader effect SHADERPERMUTATION_DEPTHRGB = 1<<28, ///< read/write depth values in RGB color coded format for older hardware without depth samplers - SHADERPERMUTATION_COUNT = 29 ///< size of shaderpermutationinfo array + SHADERPERMUTATION_ALPHAGEN_VERTEX = 1<<29, ///< alphaGen vertex + SHADERPERMUTATION_COUNT = 30 ///< size of shaderpermutationinfo array } shaderpermutation_t; diff --git a/gl_rmain.c b/gl_rmain.c index 3f1123fb..4b0ca40c 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -655,6 +655,7 @@ shaderpermutationinfo_t shaderpermutationinfo[SHADERPERMUTATION_COUNT] = {"#define USEBOUNCEGRIDDIRECTIONAL\n", " bouncegriddirectional"}, // TODO make this a static parm {"#define USETRIPPY\n", " trippy"}, {"#define USEDEPTHRGB\n", " depthrgb"}, + {"#define USEALPHAGENVERTEX\n", "alphagenvertex"} }; // NOTE: MUST MATCH ORDER OF SHADERMODE_* ENUMS! @@ -2209,6 +2210,8 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; + if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX) + permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX; // light source mode = SHADERMODE_LIGHTSOURCE; if (rsurface.rtlight->currentcubemap != r_texture_whitecube) @@ -2251,6 +2254,8 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; + if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX) + permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX; // unshaded geometry (fullbright or ambient model lighting) mode = SHADERMODE_FLATCOLOR; ambientscale = diffusescale = specularscale = 0; @@ -2300,6 +2305,8 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; + if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX) + permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX; // directional model lighting mode = SHADERMODE_LIGHTDIRECTION; if (rsurface.texture->glowtexture && r_hdr_glowintensity.value > 0 && !gl_lightmaps.integer) @@ -2359,6 +2366,8 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; + if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX) + permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX; // ambient model lighting mode = SHADERMODE_LIGHTDIRECTION; if (rsurface.texture->glowtexture && r_hdr_glowintensity.value > 0 && !gl_lightmaps.integer) @@ -2415,6 +2424,8 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; + if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHAGEN_VERTEX) + permutation |= SHADERPERMUTATION_ALPHAGEN_VERTEX; // lightmapped wall if (rsurface.texture->glowtexture && r_hdr_glowintensity.value > 0 && !gl_lightmaps.integer) permutation |= SHADERPERMUTATION_GLOW; diff --git a/model_brush.h b/model_brush.h index f1b60e0e..8020d14a 100644 --- a/model_brush.h +++ b/model_brush.h @@ -118,6 +118,8 @@ mplane_t; #define MATERIALFLAG_CAMERA 67108864 // disable rtlight on surface, use R_LightPoint instead #define MATERIALFLAG_NORTLIGHT 134217728 +// alphagen vertex +#define MATERIALFLAG_ALPHAGEN_VERTEX 268435456 // combined mask of all attributes that require depth sorted rendering #define MATERIALFLAGMASK_DEPTHSORTED (MATERIALFLAG_BLENDED | MATERIALFLAG_NODEPTHTEST) // combined mask of all attributes that cause some sort of transparency diff --git a/model_shared.c b/model_shared.c index 92cf45a5..54632114 100644 --- a/model_shared.c +++ b/model_shared.c @@ -2572,6 +2572,8 @@ nothing GL_ZERO GL_ONE texture->basematerialflags |= MATERIALFLAG_NOSHADOW; if (shader->dpnortlight) texture->basematerialflags |= MATERIALFLAG_NORTLIGHT; + if (shader->vertexalpha) + texture->basematerialflags |= MATERIALFLAG_ALPHAGEN_VERTEX; memcpy(texture->deforms, shader->deforms, sizeof(texture->deforms)); texture->reflectmin = shader->reflectmin; texture->reflectmax = shader->reflectmax; diff --git a/shader_glsl.h b/shader_glsl.h index 8c13a2a6..aa962c85 100644 --- a/shader_glsl.h +++ b/shader_glsl.h @@ -1096,7 +1096,7 @@ "#endif\n" "void main(void)\n" "{\n" -"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR)\n" +"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n" " VertexColor = Attrib_Color;\n" "#endif\n" " // copy the surface texcoord\n" @@ -1265,6 +1265,9 @@ " color.a = 1.0;\n" " //color = mix(cast_myhalf4(1, 0, 0, 1), color, terrainblend);\n" "#endif\n" +"#ifdef USEALPHAGENVERTEX\n" +" color.a *= VertexColor.a;\n" +"#endif\n" "\n" " // get the surface normal\n" "#ifdef USEVERTEXTEXTUREBLEND\n" diff --git a/shader_hlsl.h b/shader_hlsl.h index f20f8329..78f291c6 100644 --- a/shader_hlsl.h +++ b/shader_hlsl.h @@ -1007,7 +1007,7 @@ "#ifdef USESHADOWMAPORTHO\n" "uniform float4x4 ShadowMapMatrix : register(c16),\n" "#endif\n" -"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n" +"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n" "out float4 gl_FrontColor : COLOR,\n" "#endif\n" "out float4 TexCoordBoth : TEXCOORD0,\n" @@ -1040,7 +1040,7 @@ "out float4 gl_Position : POSITION\n" ")\n" "{\n" -"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND)\n" +"#if defined(MODE_VERTEXCOLOR) || defined(USEVERTEXTEXTUREBLEND) || defined(MODE_LIGHTDIRECTIONMAP_FORCED_VERTEXCOLOR) || defined(USEALPHAGENVERTEX)\n" " gl_FrontColor = gl_Color;\n" "#endif\n" " // copy the surface texcoord\n" @@ -1308,6 +1308,9 @@ " //color = half4(lerp(float4(1, 0, 0, 1), color, terrainblend));\n" "#endif\n" "#endif\n" +"#ifdef USEALPHAGENVERTEX\n" +" color.a *= gl_FrontColor.a;\n" +"#endif\n" "\n" " // get the surface normal\n" "#ifdef USEVERTEXTEXTUREBLEND\n" -- 2.39.2