new shader parameter "dppolygonoffset <factor> <offset>"; new cvars mod_q3shader_defa...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 7 Nov 2010 13:09:01 +0000 (13:09 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 7 Nov 2010 13:09:01 +0000 (13:09 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10582 d7cf8633-e32d-0410-b094-e92efae38249

darkplaces.txt
model_brush.c
model_shared.c
model_shared.h

index e8dab2d..4e05073 100644 (file)
@@ -1368,7 +1368,8 @@ Shader parameters for DP's own features:
   then align it in Radiant so only one of the animation frames can be seen on
   the surface, and specify "tcmod page 4 2 0.1". DP will then display the frames
   in order and the cycle will repeat every 0.8 seconds.
-
+- dppolygonoffset <factor> <offset>
+  This surface gets glPolygonOffset(factor, offset); useful for decals
 
 
 Thanks to:
index 70cd3b3..0a68d60 100644 (file)
@@ -46,6 +46,8 @@ cvar_t mod_q3bsp_lightmapmergepower = {CVAR_SAVE, "mod_q3bsp_lightmapmergepower"
 cvar_t mod_q3bsp_nolightmaps = {CVAR_SAVE, "mod_q3bsp_nolightmaps", "0", "do not load lightmaps in Q3BSP maps (to save video RAM, but be warned: it looks ugly)"};
 cvar_t mod_q3bsp_tracelineofsight_brushes = {0, "mod_q3bsp_tracelineofsight_brushes", "0", "enables culling of entities behind detail brushes, curves, etc"};
 cvar_t mod_q3shader_default_offsetmapping = {CVAR_SAVE, "mod_q3shader_default_offsetmapping", "1", "use offsetmapping by default on all surfaces"};
+cvar_t mod_q3shader_default_polygonfactor = {0, "mod_q3shader_default_polygonfactor", "0", "biases depth values of 'polygonoffset' shaders to prevent z-fighting artifacts"};
+cvar_t mod_q3shader_default_polygonoffset = {0, "mod_q3shader_default_polygonoffset", "-2", "biases depth values of 'polygonoffset' shaders to prevent z-fighting artifacts"};
 
 cvar_t mod_q1bsp_polygoncollisions = {0, "mod_q1bsp_polygoncollisions", "0", "disables use of precomputed cliphulls and instead collides with polygons (uses Bounding Interval Hierarchy optimizations)"};
 cvar_t mod_collision_bih = {0, "mod_collision_bih", "1", "enables use of generated Bounding Interval Hierarchy tree instead of compiled bsp tree in collision code"};
@@ -79,6 +81,8 @@ void Mod_BrushInit(void)
        Cvar_RegisterVariable(&mod_q3bsp_nolightmaps);
        Cvar_RegisterVariable(&mod_q3bsp_tracelineofsight_brushes);
        Cvar_RegisterVariable(&mod_q3shader_default_offsetmapping);
+       Cvar_RegisterVariable(&mod_q3shader_default_polygonfactor);
+       Cvar_RegisterVariable(&mod_q3shader_default_polygonoffset);
        Cvar_RegisterVariable(&mod_q1bsp_polygoncollisions);
        Cvar_RegisterVariable(&mod_collision_bih);
        Cvar_RegisterVariable(&mod_recalculatenodeboxes);
index f221f08..74af7c5 100644 (file)
@@ -1603,6 +1603,8 @@ static void Q3Shader_AddToHash (q3shaderinfo_t* shader)
 }
 
 extern cvar_t mod_q3shader_default_offsetmapping;
+extern cvar_t mod_q3shader_default_polygonoffset;
+extern cvar_t mod_q3shader_default_polygonfactor;
 void Mod_LoadQ3Shaders(void)
 {
        int j;
@@ -1693,6 +1695,8 @@ void Mod_LoadQ3Shaders(void)
                        shader.offsetscale = 1;
                        shader.specularscalemod = 1;
                        shader.specularpowermod = 1;
+                       shader.biaspolygonoffset = mod_q3shader_default_polygonoffset.value;
+                       shader.biaspolygonfactor = mod_q3shader_default_polygonfactor.value;
 
                        strlcpy(shader.name, com_token, sizeof(shader.name));
                        if (!COM_ParseToken_QuakeC(&text, false) || strcasecmp(com_token, "{"))
@@ -2093,6 +2097,18 @@ void Mod_LoadQ3Shaders(void)
                                        shader.textureflags |= Q3TEXTUREFLAG_NOPICMIP;
                                else if (!strcasecmp(parameter[0], "polygonoffset"))
                                        shader.textureflags |= Q3TEXTUREFLAG_POLYGONOFFSET;
+                               else if (!strcasecmp(parameter[0], "dppolygonoffset"))
+                               {
+                                       shader.textureflags |= Q3TEXTUREFLAG_POLYGONOFFSET;
+                                       if(numparameters >= 2)
+                                       {
+                                               shader.biaspolygonfactor = atof(parameter[1]);
+                                               if(numparameters >= 3)
+                                                       shader.biaspolygonoffset = atof(parameter[2]);
+                                               else
+                                                       shader.biaspolygonoffset = 0;
+                                       }
+                               }
                                else if (!strcasecmp(parameter[0], "dprefract") && numparameters >= 5)
                                {
                                        shader.textureflags |= Q3TEXTUREFLAG_REFRACTION;
@@ -2298,7 +2314,10 @@ qboolean Mod_LoadTextureFromQ3Shader(texture_t *texture, const char *name, qbool
                if (shader->textureflags & Q3TEXTUREFLAG_TWOSIDED)
                        texture->basematerialflags |= MATERIALFLAG_NOSHADOW | MATERIALFLAG_NOCULLFACE;
                if (shader->textureflags & Q3TEXTUREFLAG_POLYGONOFFSET)
-                       texture->biaspolygonoffset -= 2;
+               {
+                       texture->biaspolygonoffset += shader->biaspolygonoffset;
+                       texture->biaspolygonfactor += shader->biaspolygonfactor;
+               }
                if (shader->textureflags & Q3TEXTUREFLAG_REFRACTION)
                        texture->basematerialflags |= MATERIALFLAG_REFRACTION;
                if (shader->textureflags & Q3TEXTUREFLAG_REFLECTION)
index 918f8b7..cc350e1 100644 (file)
@@ -477,6 +477,9 @@ typedef struct q3shaderinfo_s
        dpoffsetmapping_technique_t offsetmapping;
        float offsetscale;
 
+       // polygonoffset (only used if Q3TEXTUREFLAG_POLYGONOFFSET)
+       float biaspolygonoffset, biaspolygonfactor;
+
        // gloss
        float specularscalemod;
        float specularpowermod;