From 44615233a17f7866d1c0f84e242802484f7a8c99 Mon Sep 17 00:00:00 2001 From: divverent Date: Sun, 7 Nov 2010 13:09:01 +0000 Subject: [PATCH] new shader parameter "dppolygonoffset "; new cvars mod_q3shader_default_polygonoffset and mod_q3shader_default_polygonfactor git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10582 d7cf8633-e32d-0410-b094-e92efae38249 --- darkplaces.txt | 3 ++- model_brush.c | 4 ++++ model_shared.c | 21 ++++++++++++++++++++- model_shared.h | 3 +++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/darkplaces.txt b/darkplaces.txt index e8dab2d3..4e050738 100644 --- a/darkplaces.txt +++ b/darkplaces.txt @@ -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 + This surface gets glPolygonOffset(factor, offset); useful for decals Thanks to: diff --git a/model_brush.c b/model_brush.c index 70cd3b38..0a68d605 100644 --- a/model_brush.c +++ b/model_brush.c @@ -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); diff --git a/model_shared.c b/model_shared.c index f221f08c..74af7c59 100644 --- a/model_shared.c +++ b/model_shared.c @@ -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) diff --git a/model_shared.h b/model_shared.h index 918f8b78..cc350e12 100644 --- a/model_shared.h +++ b/model_shared.h @@ -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; -- 2.39.2