]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
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 e8dab2d3df9734d081b8022b9a04f9cd457f8bb8..4e0507385c5d5287064a5e09ea90b3cbf98f61d4 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 70cd3b38d29d7839e22ea014894961c6c9efc48f..0a68d6051a9aa02e4cf92358f032487f15390afa 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 f221f08c2320e29c47022093aa05458da37a3e0d..74af7c5975a982412dc68f663cddac656c2fbb07 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 918f8b788ffb5284593c67b235b37250ca5679cf..cc350e121ffe20c673d8e9384068435cb7bcd714 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;