From 7995f9f34c59e9f4a33a549d5bee58c5af43ea11 Mon Sep 17 00:00:00 2001 From: vortex Date: Sun, 21 Feb 2010 01:52:02 +0000 Subject: [PATCH] Offsetmapping now could be customized on per-texture basis. Added mod_q3shader_default_offsetmapping cvar which is 1 by default (offsetmapping is on by default on all surfs), and 0 (only shader-set). New q3shader keyword "dp_offsetmapping ". Typical example: "dp_offsetmapping default 2". Types are "off", "default" (legacy cvar-based behavior), "linear" and "relief". Linear/relief is forced modes that ignores r_glsl_offsetmapping_reliefmapping. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9993 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_rmain.c | 82 ++++++++++++++++++++++++++++++++++++++------------ model_alias.c | 2 ++ model_brush.c | 5 +++ model_shared.c | 24 +++++++++++++-- model_shared.h | 19 +++++++++++- model_sprite.c | 2 ++ 6 files changed, 112 insertions(+), 22 deletions(-) diff --git a/gl_rmain.c b/gl_rmain.c index b10677be..1ba07e70 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -4454,9 +4454,16 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, { if (r_glsl_offsetmapping.integer) { - permutation |= SHADERPERMUTATION_OFFSETMAPPING; - if (r_glsl_offsetmapping_reliefmapping.integer) - permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + if (rsurface.texture->offsetmapping == OFFSETMAPPING_LINEAR) + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + else if (rsurface.texture->offsetmapping == OFFSETMAPPING_RELIEF) + permutation |= SHADERPERMUTATION_OFFSETMAPPING | SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + else if (rsurface.texture->offsetmapping != OFFSETMAPPING_OFF) + { + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + if (r_glsl_offsetmapping_reliefmapping.integer) + permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + } } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; @@ -4482,9 +4489,16 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, { if (r_glsl_offsetmapping.integer) { - permutation |= SHADERPERMUTATION_OFFSETMAPPING; - if (r_glsl_offsetmapping_reliefmapping.integer) - permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + if (rsurface.texture->offsetmapping == OFFSETMAPPING_LINEAR) + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + else if (rsurface.texture->offsetmapping == OFFSETMAPPING_RELIEF) + permutation |= SHADERPERMUTATION_OFFSETMAPPING | SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + else if (rsurface.texture->offsetmapping != OFFSETMAPPING_OFF) + { + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + if (r_glsl_offsetmapping_reliefmapping.integer) + permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + } } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; @@ -4551,9 +4565,16 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, { if (r_glsl_offsetmapping.integer) { - permutation |= SHADERPERMUTATION_OFFSETMAPPING; - if (r_glsl_offsetmapping_reliefmapping.integer) - permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + if (rsurface.texture->offsetmapping == OFFSETMAPPING_LINEAR) + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + else if (rsurface.texture->offsetmapping == OFFSETMAPPING_RELIEF) + permutation |= SHADERPERMUTATION_OFFSETMAPPING | SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + else if (rsurface.texture->offsetmapping != OFFSETMAPPING_OFF) + { + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + if (r_glsl_offsetmapping_reliefmapping.integer) + permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + } } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; @@ -4610,9 +4631,16 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, { if (r_glsl_offsetmapping.integer) { - permutation |= SHADERPERMUTATION_OFFSETMAPPING; - if (r_glsl_offsetmapping_reliefmapping.integer) - permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + if (rsurface.texture->offsetmapping == OFFSETMAPPING_LINEAR) + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + else if (rsurface.texture->offsetmapping == OFFSETMAPPING_RELIEF) + permutation |= SHADERPERMUTATION_OFFSETMAPPING | SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + else if (rsurface.texture->offsetmapping != OFFSETMAPPING_OFF) + { + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + if (r_glsl_offsetmapping_reliefmapping.integer) + permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + } } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; @@ -4674,9 +4702,16 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, { if (r_glsl_offsetmapping.integer) { - permutation |= SHADERPERMUTATION_OFFSETMAPPING; - if (r_glsl_offsetmapping_reliefmapping.integer) - permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + if (rsurface.texture->offsetmapping == OFFSETMAPPING_LINEAR) + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + else if (rsurface.texture->offsetmapping == OFFSETMAPPING_RELIEF) + permutation |= SHADERPERMUTATION_OFFSETMAPPING | SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + else if (rsurface.texture->offsetmapping != OFFSETMAPPING_OFF) + { + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + if (r_glsl_offsetmapping_reliefmapping.integer) + permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + } } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; @@ -4731,9 +4766,16 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, { if (r_glsl_offsetmapping.integer) { - permutation |= SHADERPERMUTATION_OFFSETMAPPING; - if (r_glsl_offsetmapping_reliefmapping.integer) - permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + if (rsurface.texture->offsetmapping == OFFSETMAPPING_LINEAR) + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + else if (rsurface.texture->offsetmapping == OFFSETMAPPING_RELIEF) + permutation |= SHADERPERMUTATION_OFFSETMAPPING | SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + else if (rsurface.texture->offsetmapping != OFFSETMAPPING_OFF) + { + permutation |= SHADERPERMUTATION_OFFSETMAPPING; + if (r_glsl_offsetmapping_reliefmapping.integer) + permutation |= SHADERPERMUTATION_OFFSETMAPPING_RELIEFMAPPING; + } } if (rsurface.texture->currentmaterialflags & MATERIALFLAG_VERTEXTEXTUREBLEND) permutation |= SHADERPERMUTATION_VERTEXTEXTUREBLEND; @@ -4922,7 +4964,7 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting, if (r_glsl_permutation->loc_FogPlaneViewDist >= 0) qglUniform1fARB(r_glsl_permutation->loc_FogPlaneViewDist, rsurface.fogplaneviewdist); if (r_glsl_permutation->loc_FogRangeRecip >= 0) qglUniform1fARB(r_glsl_permutation->loc_FogRangeRecip, rsurface.fograngerecip); if (r_glsl_permutation->loc_FogHeightFade >= 0) qglUniform1fARB(r_glsl_permutation->loc_FogHeightFade, rsurface.fogheightfade); - if (r_glsl_permutation->loc_OffsetMapping_Scale >= 0) qglUniform1fARB(r_glsl_permutation->loc_OffsetMapping_Scale, r_glsl_offsetmapping_scale.value); + if (r_glsl_permutation->loc_OffsetMapping_Scale >= 0) qglUniform1fARB(r_glsl_permutation->loc_OffsetMapping_Scale, r_glsl_offsetmapping_scale.value*rsurface.texture->offsetscale); if (r_glsl_permutation->loc_ScreenToDepth >= 0) qglUniform2fARB(r_glsl_permutation->loc_ScreenToDepth, r_refdef.view.viewport.screentodepth[0], r_refdef.view.viewport.screentodepth[1]); if (r_glsl_permutation->loc_PixelToScreenTexCoord >= 0) qglUniform2fARB(r_glsl_permutation->loc_PixelToScreenTexCoord, 1.0f/vid.width, 1.0f/vid.height); @@ -12512,6 +12554,8 @@ void R_DrawCustomSurface(skinframe_t *skinframe, const matrix4x4_t *texmatrix, i texture.basematerialflags = materialflags | MATERIALFLAG_CUSTOMSURFACE | MATERIALFLAG_WALL; texture.currentskinframe = skinframe; texture.currenttexmatrix = *texmatrix; // requires MATERIALFLAG_CUSTOMSURFACE + texture.offsetmapping = OFFSETMAPPING_OFF; + texture.offsetscale = 1; texture.specularscalemod = 1; texture.specularpowermod = 1; diff --git a/model_alias.c b/model_alias.c index d3082288..9ab4295e 100644 --- a/model_alias.c +++ b/model_alias.c @@ -934,6 +934,8 @@ static void Mod_BuildAliasSkinFromSkinFrame(texture_t *texture, skinframe_t *ski if (texture->currentskinframe->hasalpha) texture->basematerialflags |= MATERIALFLAG_ALPHA | MATERIALFLAG_BLENDED | MATERIALFLAG_NOSHADOW; texture->currentmaterialflags = texture->basematerialflags; + texture->offsetmapping = OFFSETMAPPING_OFF; + texture->offsetscale = 1; texture->specularscalemod = 1; texture->specularpowermod = 1; texture->surfaceflags = 0; diff --git a/model_brush.c b/model_brush.c index 6df5d31c..0503d2eb 100644 --- a/model_brush.c +++ b/model_brush.c @@ -46,6 +46,8 @@ cvar_t mod_q3bsp_debugtracebrush = {0, "mod_q3bsp_debugtracebrush", "0", "select cvar_t mod_q3bsp_lightmapmergepower = {CVAR_SAVE, "mod_q3bsp_lightmapmergepower", "4", "merges the quake3 128x128 lightmap textures into larger lightmap group textures to speed up rendering, 1 = 256x256, 2 = 512x512, 3 = 1024x1024, 4 = 2048x2048, 5 = 4096x4096, ..."}; 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_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"}; cvar_t mod_recalculatenodeboxes = {0, "mod_recalculatenodeboxes", "1", "enables use of generated node bounding boxes based on BSP tree portal reconstruction, rather than the node boxes supplied by the map compiler"}; @@ -78,6 +80,7 @@ void Mod_BrushInit(void) Cvar_RegisterVariable(&mod_q3bsp_lightmapmergepower); Cvar_RegisterVariable(&mod_q3bsp_nolightmaps); Cvar_RegisterVariable(&mod_q3bsp_tracelineofsight_brushes); + Cvar_RegisterVariable(&mod_q3shader_default_offsetmapping); Cvar_RegisterVariable(&mod_q1bsp_polygoncollisions); Cvar_RegisterVariable(&mod_collision_bih); Cvar_RegisterVariable(&mod_recalculatenodeboxes); @@ -1465,6 +1468,8 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l) tx->reflectfactor = 1; Vector4Set(tx->reflectcolor4f, 1, 1, 1, 1); tx->r_water_wateralpha = 1; + tx->offsetmapping = OFFSETMAPPING_OFF; + tx->offsetscale = 1; tx->specularscalemod = 1; tx->specularpowermod = 1; } diff --git a/model_shared.c b/model_shared.c index 603571e5..4bf93638 100644 --- a/model_shared.c +++ b/model_shared.c @@ -1540,6 +1540,7 @@ static void Q3Shader_AddToHash (q3shaderinfo_t* shader) } extern cvar_t r_picmipworld; +extern cvar_t mod_q3shader_default_offsetmapping; void Mod_LoadQ3Shaders(void) { int j; @@ -1580,6 +1581,8 @@ void Mod_LoadQ3Shaders(void) shader.reflectfactor = 1; Vector4Set(shader.reflectcolor4f, 1, 1, 1, 1); shader.r_water_wateralpha = 1; + shader.offsetmapping = (mod_q3shader_default_offsetmapping.value) ? OFFSETMAPPING_DEFAULT : OFFSETMAPPING_OFF; + shader.offsetscale = 1; shader.specularscalemod = 1; shader.specularpowermod = 1; @@ -1998,6 +2001,18 @@ void Mod_LoadQ3Shaders(void) { shader.specularpowermod = atof(parameter[1]); } + else if (!strcasecmp(parameter[0], "dpoffsetmapping") && numparameters >= 3) + { + if (!strcasecmp(parameter[1], "disable") || !strcasecmp(parameter[1], "none") || !strcasecmp(parameter[1], "off")) + shader.offsetmapping = OFFSETMAPPING_OFF; + else if (!strcasecmp(parameter[1], "default")) + shader.offsetmapping = OFFSETMAPPING_DEFAULT; + else if (!strcasecmp(parameter[1], "linear")) + shader.offsetmapping = OFFSETMAPPING_LINEAR; + else if (!strcasecmp(parameter[1], "relief")) + shader.offsetmapping = OFFSETMAPPING_RELIEF; + shader.offsetscale = atof(parameter[2]); + } else if (!strcasecmp(parameter[0], "deformvertexes") && numparameters >= 2) { int i, deformindex; @@ -2106,8 +2121,11 @@ qboolean Mod_LoadTextureFromQ3Shader(texture_t *texture, const char *name, qbool texflagsmask &= ~TEXF_PICMIP; if(!(defaulttexflags & TEXF_COMPRESS)) texflagsmask &= ~TEXF_COMPRESS; - texture->specularscalemod = 1; // unless later loaded from the shader - texture->specularpowermod = 1; // unless later loaded from the shader + // unless later loaded from the shader + texture->offsetmapping = (mod_q3shader_default_offsetmapping.value) ? OFFSETMAPPING_DEFAULT : OFFSETMAPPING_OFF; + texture->offsetscale = 1; + texture->specularscalemod = 1; + texture->specularpowermod = 1; // WHEN ADDING DEFAULTS HERE, REMEMBER TO SYNC TO SHADER LOADING ABOVE // HERE, AND Q1BSP LOADING // JUST GREP FOR "specularscalemod = 1". @@ -2245,6 +2263,8 @@ nothing GL_ZERO GL_ONE texture->reflectfactor = shader->reflectfactor; Vector4Copy(shader->reflectcolor4f, texture->reflectcolor4f); texture->r_water_wateralpha = shader->r_water_wateralpha; + texture->offsetmapping = shader->offsetmapping; + texture->offsetscale = shader->offsetscale; texture->specularscalemod = shader->specularscalemod; texture->specularpowermod = shader->specularpowermod; if (shader->dpreflectcube[0]) diff --git a/model_shared.h b/model_shared.h index bcb34f1b..61e833c4 100644 --- a/model_shared.h +++ b/model_shared.h @@ -371,6 +371,15 @@ typedef struct q3shaderinfo_deform_s } q3shaderinfo_deform_t; +typedef enum dpoffsetmapping_technique_s +{ + OFFSETMAPPING_OFF, // none + OFFSETMAPPING_DEFAULT, // cvar-set + OFFSETMAPPING_LINEAR, // linear + OFFSETMAPPING_RELIEF // relief +}dpoffsetmapping_technique_t; + + typedef struct q3shaderinfo_s { char name[Q3PATHLENGTH]; @@ -404,6 +413,10 @@ typedef struct q3shaderinfo_s vec4_t reflectcolor4f; // color tint of reflection (including alpha factor) float r_water_wateralpha; // additional wateralpha to apply when r_water is active + // offsetmapping + dpoffsetmapping_technique_t offsetmapping; + float offsetscale; + // gloss float specularscalemod; float specularpowermod; @@ -536,11 +549,15 @@ typedef struct texture_s vec4_t reflectcolor4f; // color tint of reflection (including alpha factor) float r_water_wateralpha; // additional wateralpha to apply when r_water is active + // offsetmapping + dpoffsetmapping_technique_t offsetmapping; + float offsetscale; + // gloss float specularscalemod; float specularpowermod; } -texture_t; + texture_t; typedef struct mtexinfo_s { diff --git a/model_sprite.c b/model_sprite.c index a33fa9f3..3827ab2d 100644 --- a/model_sprite.c +++ b/model_sprite.c @@ -47,6 +47,8 @@ static void Mod_SpriteSetupTexture(texture_t *texture, skinframe_t *skinframe, q { if (!skinframe) skinframe = R_SkinFrame_LoadMissing(); + texture->offsetmapping = OFFSETMAPPING_OFF; + texture->offsetscale = 1; texture->specularscalemod = 1; texture->specularpowermod = 1; texture->basematerialflags = MATERIALFLAG_WALL; -- 2.39.2