From: vortex Date: Sat, 20 Nov 2010 23:59:28 +0000 (+0000) Subject: CL_VM_GetLight: allow 2'nd optional parm which sets sampling mask: 1 lightmap (defaul... X-Git-Tag: xonotic-v0.5.0~438^2~222 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e5bd7b58a64bc25738028180da3c1990824d75ec;p=xonotic%2Fdarkplaces.git CL_VM_GetLight: allow 2'nd optional parm which sets sampling mask: 1 lightmap (default one), 2 worldrtlight, 4 - dlight. Added getlights2 to the csprogdefs.qc. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10619 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/clvm_cmds.c b/clvm_cmds.c index 62df4dee..f816eb35 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -667,24 +667,25 @@ static void VM_CL_ambientsound (void) S_StaticSound (s, f, PRVM_G_FLOAT(OFS_PARM2), PRVM_G_FLOAT(OFS_PARM3)*64); } -// #92 vector(vector org) getlight (DP_QC_GETLIGHT) +// #92 vector(vector org[, float lpflag]) getlight (DP_QC_GETLIGHT) static void VM_CL_getlight (void) { vec3_t ambientcolor, diffusecolor, diffusenormal; vec_t *p; - VM_SAFEPARMCOUNT(1, VM_CL_getlight); + VM_SAFEPARMCOUNTRANGE(1, 2, VM_CL_getlight); p = PRVM_G_VECTOR(OFS_PARM0); VectorClear(ambientcolor); VectorClear(diffusecolor); VectorClear(diffusenormal); - if (cl.worldmodel && cl.worldmodel->brush.LightPoint) + if (prog->argc >= 2) + R_CompleteLightPoint(ambientcolor, diffusecolor, diffusenormal, p, PRVM_G_FLOAT(OFS_PARM1)); + else if (cl.worldmodel && cl.worldmodel->brush.LightPoint) cl.worldmodel->brush.LightPoint(cl.worldmodel, p, ambientcolor, diffusecolor, diffusenormal); VectorMA(ambientcolor, 0.5, diffusecolor, PRVM_G_VECTOR(OFS_RETURN)); } - //============================================================================ //[515]: SCENE MANAGER builtins extern qboolean CSQC_AddRenderEdict (prvm_edict_t *ed, int edictnum);//csprogs.c diff --git a/dpdefs/csprogsdefs.qc b/dpdefs/csprogsdefs.qc index 1a6847fc..6c6ad5e5 100644 --- a/dpdefs/csprogsdefs.qc +++ b/dpdefs/csprogsdefs.qc @@ -394,9 +394,16 @@ string(string s) precache_file2 = #77; float(string s) stof = #81; + void(vector v1, vector min, vector max, vector v2, float nomonsters, entity forent) tracebox = #90; vector() randomvec = #91; vector(vector org) getlight = #92; +vector(vector org, float lpflags) getlight2 = #92; +const float LP_LIGHTMAP = 1; +const float LP_RTWORLD = 2; +const float LP_DYNLIGHT = 4; +const float LP_COMPLETE = 7; + float(string name, string value) registercvar = #93; float( float a, ... ) min = #94; float( float b, ... ) max = #95; diff --git a/gl_rmain.c b/gl_rmain.c index c3431f7d..2ae94ca0 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -7909,7 +7909,7 @@ static void R_View_UpdateEntityLighting (void) { if (ent->model->sprite.sprnum_type == SPR_OVERHEAD) // apply offset for overhead sprites org[2] = org[2] + r_overheadsprites_pushback.value; - R_CompleteLightPoint(ent->modellight_ambient, ent->modellight_diffuse, ent->modellight_lightdir, org, true, true); + R_CompleteLightPoint(ent->modellight_ambient, ent->modellight_diffuse, ent->modellight_lightdir, org, LP_LIGHTMAP | LP_RTWORLD | LP_DYNLIGHT); } else r_refdef.scene.worldmodel->brush.LightPoint(r_refdef.scene.worldmodel, org, ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal); diff --git a/r_shadow.c b/r_shadow.c index aca5afca..279736d3 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -6004,55 +6004,55 @@ LIGHT SAMPLING ============================================================================= */ -void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, qboolean dynamic, qboolean rtworld) +void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, const int flags) { + int i, numlights, flag; + float f, relativepoint[3], dist, dist2, lightradius2; + rtlight_t *light; + dlight_t *dlight; + VectorClear(diffusecolor); VectorClear(diffusenormal); - if (!r_fullbright.integer && r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.LightPoint) + if (flags & LP_LIGHTMAP) { - ambientcolor[0] = ambientcolor[1] = ambientcolor[2] = r_refdef.scene.ambient; - r_refdef.scene.worldmodel->brush.LightPoint(r_refdef.scene.worldmodel, p, ambientcolor, diffusecolor, diffusenormal); + if (!r_fullbright.integer && r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.LightPoint) + { + ambientcolor[0] = ambientcolor[1] = ambientcolor[2] = r_refdef.scene.ambient; + r_refdef.scene.worldmodel->brush.LightPoint(r_refdef.scene.worldmodel, p, ambientcolor, diffusecolor, diffusenormal); + } + else + VectorSet(ambientcolor, 1, 1, 1); } - else - VectorSet(ambientcolor, 1, 1, 1); - - if (dynamic) + if (flags & LP_RTWORLD) { - int i, numlights, flag; - float f, relativepoint[3], dist, dist2, lightradius2; - rtlight_t *light; - dlight_t *dlight; - - // sample rtlights - if (rtworld) + flag = r_refdef.scene.rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE; + numlights = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); + for (i = 0; i < numlights; i++) { - flag = r_refdef.scene.rtworld ? LIGHTFLAG_REALTIMEMODE : LIGHTFLAG_NORMALMODE; - numlights = Mem_ExpandableArray_IndexRange(&r_shadow_worldlightsarray); - for (i = 0; i < numlights; i++) - { - dlight = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, i); - if (!dlight) - continue; - light = &dlight->rtlight; - if (!(light->flags & flag)) - continue; - // sample - lightradius2 = light->radius * light->radius; - VectorSubtract(light->shadoworigin, p, relativepoint); - dist2 = VectorLength2(relativepoint); - if (dist2 >= lightradius2) - continue; - dist = sqrt(dist2) / light->radius; - f = dist < 1 ? (r_shadow_lightintensityscale.value * ((1.0f - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist))) : 0; - if (f <= 0) - continue; - // todo: add to both ambient and diffuse - if (!light->shadow || CL_TraceLine(p, light->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction == 1) - VectorMA(ambientcolor, f, light->currentcolor, ambientcolor); - } + dlight = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, i); + if (!dlight) + continue; + light = &dlight->rtlight; + if (!(light->flags & flag)) + continue; + // sample + lightradius2 = light->radius * light->radius; + VectorSubtract(light->shadoworigin, p, relativepoint); + dist2 = VectorLength2(relativepoint); + if (dist2 >= lightradius2) + continue; + dist = sqrt(dist2) / light->radius; + f = dist < 1 ? (r_shadow_lightintensityscale.value * ((1.0f - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist))) : 0; + if (f <= 0) + continue; + // todo: add to both ambient and diffuse + if (!light->shadow || CL_TraceLine(p, light->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction == 1) + VectorMA(ambientcolor, f, light->currentcolor, ambientcolor); } - + } + if (flags & LP_DYNLIGHT) + { // sample dlights for (i = 0;i < r_refdef.scene.numlights;i++) { diff --git a/r_shadow.h b/r_shadow.h index 479d839e..b08f00c9 100644 --- a/r_shadow.h +++ b/r_shadow.h @@ -92,6 +92,9 @@ void R_Shadow_PrepareShadowSides(int numtris); void R_Shadow_PrepareModelShadows(void); -void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, qboolean dynamic, qboolean rtworld); +#define LP_LIGHTMAP 1 +#define LP_RTWORLD 2 +#define LP_DYNLIGHT 4 +void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, const int flags); #endif