]> 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)
committerRudolf Polzer <divverent@alientrap.org>
Sun, 7 Nov 2010 13:08:56 +0000 (14:08 +0100)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10582 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=44615233a17f7866d1c0f84e242802484f7a8c99

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 532d9db3145a50d2ab1f28c18e7ab2b3c9bcfef8..13970b3008b3e424f0efd4800ea2bf20364921f3 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 400dfc574e7defa7685f64d0d9570da280a416e6..d8760aff2e1c1db05b4ab56591dfb3f55017b340 100644 (file)
@@ -1553,6 +1553,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;
@@ -1643,6 +1645,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, "{"))
@@ -2043,6 +2047,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;
@@ -2248,7 +2264,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 2f8cc01f2bb5ef2058b13cadc51451c20c02a474..3dbedd5e2305e7fa7f7ab4941a40078c1df0c8ba 100644 (file)
@@ -425,6 +425,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;