From: divverent Date: Fri, 6 Nov 2009 07:00:06 +0000 (+0000) Subject: entity light equalization as an alternative rendering of EF_FULLBRIGHT entities.... X-Git-Tag: xonotic-v0.1.0preview~1217 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e5608d2f09a2cf9ef8c076e495fb893921c13b9f;p=xonotic%2Fdarkplaces.git entity light equalization as an alternative rendering of EF_FULLBRIGHT entities. Enable with r_equalize_entities_fullbright 1. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9425 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_main.c b/cl_main.c index 5e31b368..055573e9 100644 --- a/cl_main.c +++ b/cl_main.c @@ -88,6 +88,8 @@ cvar_t cl_deathnoviewmodel = {0, "cl_deathnoviewmodel", "1", "hides gun model wh cvar_t cl_locs_enable = {CVAR_SAVE, "locs_enable", "1", "enables replacement of certain % codes in chat messages: %l (location), %d (last death location), %h (health), %a (armor), %x (rockets), %c (cells), %r (rocket launcher status), %p (powerup status), %w (weapon status), %t (current time in level)"}; cvar_t cl_locs_show = {0, "locs_show", "0", "shows defined locations for editing purposes"}; +extern cvar_t r_equalize_entities_fullbright; + client_static_t cls; client_state_t cl; @@ -1080,8 +1082,13 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat if (e->state_current.number == cl.viewentity) e->render.flags |= RENDER_EXTERIORMODEL; // either fullbright or lit - if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer) - e->render.flags |= RENDER_LIGHT; + if(!r_fullbright.integer) + { + if (!(e->render.effects & EF_FULLBRIGHT)) + e->render.flags |= RENDER_LIGHT; + else if(r_equalize_entities_fullbright.integer) + e->render.flags |= RENDER_LIGHT | RENDER_EQUALIZE; + } // hide player shadow during intermission or nehahra movie if (!(e->render.effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST)) && (e->render.alpha >= 1) @@ -1491,8 +1498,13 @@ static void CL_RelinkStaticEntities(void) // need to re-fetch the model pointer e->render.model = cl.model_precache[e->state_baseline.modelindex]; // either fullbright or lit - if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer) - e->render.flags |= RENDER_LIGHT; + if(!r_fullbright.integer) + { + if (!(e->render.effects & EF_FULLBRIGHT)) + e->render.flags |= RENDER_LIGHT; + else if(r_equalize_entities_fullbright.integer) + e->render.flags |= RENDER_LIGHT | RENDER_EQUALIZE; + } // hide player shadow during intermission or nehahra movie if (!(e->render.effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST)) && (e->render.alpha >= 1)) e->render.flags |= RENDER_SHADOW; diff --git a/clvm_cmds.c b/clvm_cmds.c index f11251bc..206c39bc 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -21,6 +21,7 @@ //4 feature darkplaces csqc: add builtins to clientside qc for gl calls extern cvar_t v_flipped; +extern cvar_t r_equalize_entities_fullbright; sfx_t *S_FindName(const char *name); int Sbar_GetSortedPlayerIndex (int index); @@ -1461,8 +1462,13 @@ static void VM_CL_makestatic (void) Matrix4x4_CreateFromQuakeEntity(&staticent->render.matrix, ent->fields.client->origin[0], ent->fields.client->origin[1], ent->fields.client->origin[2], ent->fields.client->angles[0], ent->fields.client->angles[1], ent->fields.client->angles[2], staticent->render.scale); // either fullbright or lit - if (!(staticent->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer) - staticent->render.flags |= RENDER_LIGHT; + if(!r_fullbright.integer) + { + if (!(staticent->render.effects & EF_FULLBRIGHT)) + staticent->render.flags |= RENDER_LIGHT; + else if(r_equalize_entities_fullbright.integer) + staticent->render.flags |= RENDER_LIGHT | RENDER_EQUALIZE; + } // turn off shadows from transparent objects if (!(staticent->render.effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST)) && (staticent->render.alpha >= 1)) staticent->render.flags |= RENDER_SHADOW; diff --git a/csprogs.c b/csprogs.c index 1f774fa4..899c7dca 100644 --- a/csprogs.c +++ b/csprogs.c @@ -153,6 +153,7 @@ void CSQC_Think (prvm_edict_t *ed) } extern cvar_t cl_noplayershadow; +extern cvar_t r_equalize_entities_fullbright; qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) { int renderflags; @@ -268,8 +269,13 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) entrender->flags &= ~(RENDER_SHADOW | RENDER_LIGHT | RENDER_NOSELFSHADOW); // either fullbright or lit - if (!(entrender->effects & EF_FULLBRIGHT) && !r_fullbright.integer) - entrender->flags |= RENDER_LIGHT; + if(!r_fullbright.integer) + { + if (!(entrender->effects & EF_FULLBRIGHT)) + entrender->flags |= RENDER_LIGHT; + else if(r_equalize_entities_fullbright.integer) + entrender->flags |= RENDER_LIGHT | RENDER_EQUALIZE; + } // hide player shadow during intermission or nehahra movie if (!(entrender->effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST)) && (entrender->alpha >= 1) diff --git a/gl_rmain.c b/gl_rmain.c index d4041367..887b4ad5 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -44,6 +44,11 @@ cvar_t r_motionblur_vcoeff = {CVAR_SAVE, "r_motionblur_vcoeff", "0.05", "sliding cvar_t r_motionblur_maxblur = {CVAR_SAVE, "r_motionblur_maxblur", "0.88", "cap for motionblur alpha value"}; cvar_t r_motionblur_randomize = {CVAR_SAVE, "r_motionblur_randomize", "0.1", "randomizing coefficient to workaround ghosting"}; +// TODO do we want a r_equalize_entities cvar that works on all ents, or would that be a cheat? +cvar_t r_equalize_entities_fullbright = {CVAR_SAVE, "r_equalize_entities_fullbright", "0", "render fullbright entities by equalizing their lightness, not by not rendering light"}; +cvar_t r_equalize_entities_by = {CVAR_SAVE, "r_equalize_entities_by", "0.7", "equalize entity lighting (exponent)"}; +cvar_t r_equalize_entities_to = {CVAR_SAVE, "r_equalize_entities_to", "0.8", "equalize entity lighting (level)"}; + cvar_t r_animcache = {CVAR_SAVE, "r_animcache", "1", "cache animation frames to save CPU usage, primarily optimizes shadows and reflections"}; cvar_t r_depthfirst = {CVAR_SAVE, "r_depthfirst", "0", "renders a depth-only version of the scene before normal rendering begins to eliminate overdraw, values: 0 = off, 1 = world depth, 2 = world and model depth"}; @@ -2826,6 +2831,9 @@ void GL_Main_Init(void) Cvar_RegisterVariable(&r_motionblur_vcoeff); Cvar_RegisterVariable(&r_motionblur_randomize); Cvar_RegisterVariable(&r_damageblur); + Cvar_RegisterVariable(&r_equalize_entities_fullbright); + Cvar_RegisterVariable(&r_equalize_entities_by); + Cvar_RegisterVariable(&r_equalize_entities_to); Cvar_RegisterVariable(&r_animcache); Cvar_RegisterVariable(&r_depthfirst); Cvar_RegisterVariable(&r_useinfinitefarclip); @@ -3224,7 +3232,8 @@ static void R_View_UpdateEntityLighting (void) { int i; entity_render_t *ent; - vec3_t tempdiffusenormal; + vec3_t tempdiffusenormal, avg; + vec_t f; for (i = 0;i < r_refdef.scene.numentities;i++) { @@ -3253,6 +3262,17 @@ static void R_View_UpdateEntityLighting (void) vec3_t org; Matrix4x4_OriginFromMatrix(&ent->matrix, org); r_refdef.scene.worldmodel->brush.LightPoint(r_refdef.scene.worldmodel, org, ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal); + if(r_equalize_entities_by.value != 0 && r_equalize_entities_to.value != 0 && (ent->flags & RENDER_EQUALIZE)) + { + VectorMA(ent->modellight_ambient, 0.25f, ent->modellight_diffuse, avg); + f = 0.299f * avg[0] + 0.587f * avg[1] + 0.114f * avg[2]; + if(f > 0) + { + f = pow(f / r_equalize_entities_to.value, -r_equalize_entities_by.value); + VectorScale(ent->modellight_ambient, f, ent->modellight_ambient); + VectorScale(ent->modellight_diffuse, f, ent->modellight_diffuse); + } + } } else // highly rare VectorSet(ent->modellight_ambient, 1, 1, 1); diff --git a/protocol.h b/protocol.h index 9fdd636b..2b9fd2b6 100644 --- a/protocol.h +++ b/protocol.h @@ -338,6 +338,7 @@ void Protocol_Names(char *buffer, size_t buffersize); #define RENDER_LIGHT 131072 // receive light #define RENDER_NOSELFSHADOW 262144 // render lighting on this entity before its own shadow is added to the scene // (note: all RENDER_NOSELFSHADOW entities are grouped together and rendered in a batch before their shadows are rendered, so they can not shadow eachother either) +#define RENDER_EQUALIZE 524288 // (subflag of RENDER_LIGHT) equalize the light from the light grid hitting this ent (less invasive EF_FULLBRIGHT implementation) typedef enum entity_state_active_e {