]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
CL_VM_GetLight: allow 2'nd optional parm which sets sampling mask: 1 lightmap (defaul...
authorvortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 20 Nov 2010 23:59:28 +0000 (23:59 +0000)
committervortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 20 Nov 2010 23:59:28 +0000 (23:59 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10619 d7cf8633-e32d-0410-b094-e92efae38249

clvm_cmds.c
dpdefs/csprogsdefs.qc
gl_rmain.c
r_shadow.c
r_shadow.h

index 62df4deefb6ecf2b5cefaa21d261adba7fb39442..f816eb35a7f6c1121fed8c2806fb11ee4bb1506a 100644 (file)
@@ -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
index 1a6847fc1e0aa3feefb27de90dada3738a8426a6..6c6ad5e59dd6bd9a43429cf8d35561c96060559b 100644 (file)
@@ -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;
index c3431f7dfaae7b42507e16b3ab94f5cfba102c0f..2ae94ca0b10750c2a74f4b49a2255950b5cf0747 100644 (file)
@@ -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);
index aca5afca6fdd99a6821f1f0ea4de87a893e32b01..279736d37fc42db58fa2cd36a881fab6f454745a 100644 (file)
@@ -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++)
                {
index 479d839e64bc187c0611b848cfaa9cdafac29dc7..b08f00c9c73d6eb16bdb8e1a2ac91679d51be72e 100644 (file)
@@ -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