]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
R_CompleteLightPoint bugfixed, dynamic lights actually matter for lit particles,...
authorvortex <vortex@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 18 Oct 2010 00:47:19 +0000 (00:47 +0000)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 18 Oct 2010 07:31:20 +0000 (09:31 +0200)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10546 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=382fbf2843f62c94752e809de977d0b4a2a2a113

cl_particles.c
gl_rmain.c
r_shadow.c
r_shadow.h
r_sprites.c

index 3448959704d239328ea055fb7b7425ac7861fa3a..79b0cf4fccd2afc6e3aa53218c118f9c78217a52 100644 (file)
@@ -2543,7 +2543,7 @@ void R_DrawParticle_TransparentCallback(const entity_render_t *ent, const rtligh
                        // note: lighting is not cheap!
                        if (particletype[p->typeindex].lighting)
                        {
-                               R_CompleteLightPoint(ambient, diffuse, diffusenormal, p->org, true);
+                               R_CompleteLightPoint(ambient, diffuse, diffusenormal, p->org, true, false);
                                c4f[0] *= (ambient[0] + 0.5 * diffuse[0]);
                                c4f[1] *= (ambient[1] + 0.5 * diffuse[1]);
                                c4f[2] *= (ambient[2] + 0.5 * diffuse[2]);
index 1b8dc37ea72f9dae2b157bed467d773a137ac6f1..9dd6a5327ab2f232d07781ac025a482990dea982 100644 (file)
@@ -7155,7 +7155,18 @@ 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);
+
+                       // complete lightning for lit sprites
+                       // todo: make a EF_ field so small ents could be lit purely by modellight and skipping real rtlight pass (like EF_NORTLIGHT)?
+                       if (ent->model->type == mod_sprite && !(ent->model->data_textures[0].basematerialflags & MATERIALFLAG_FULLBRIGHT))
+                       {
+                               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);
+                       }
+                       else
+                               r_refdef.scene.worldmodel->brush.LightPoint(r_refdef.scene.worldmodel, org, ent->modellight_ambient, ent->modellight_diffuse, tempdiffusenormal);
+
                        if(ent->flags & RENDER_EQUALIZE)
                        {
                                // first fix up ambient lighting...
@@ -13400,7 +13411,6 @@ void R_DrawCustomSurface_Texture(texture_t *texture, const matrix4x4_t *texmatri
        const msurface_t *surfacelist = &surface;
 
        // fake enough texture and surface state to render this geometry
-
        surface.texture = texture;
        surface.num_triangles = numtriangles;
        surface.num_firsttriangle = firsttriangle;
index 2908fb04e0c01caf2f68dbaa185dab336b47718e..ea0f2fce6f632f76e9a4c33974ae0e8b2f8750b8 100644 (file)
@@ -6007,7 +6007,7 @@ LIGHT SAMPLING
 =============================================================================
 */
 
-void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, int dynamic)
+void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, qboolean dynamic, qboolean rtworld)
 {
        VectorClear(diffusecolor);
        VectorClear(diffusenormal);
@@ -6022,16 +6022,41 @@ void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffu
 
        if (dynamic)
        {
-               int i;
+               int i, numlights, flag;
                float f, v[3];
                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++)
+                       {
+                               dlight = (dlight_t *) Mem_ExpandableArray_RecordAtIndex(&r_shadow_worldlightsarray, i);
+                               light = &dlight->rtlight;
+                               if (!(light->flags & flag))
+                                       continue;
+                               Matrix4x4_Transform(&light->matrix_worldtolight, p, v);
+                               f = 1 - VectorLength2(v);
+                               if (f <= 0)
+                                       continue;
+                               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);
+                       }
+               }
+
+               // sample dlights
                for (i = 0;i < r_refdef.scene.numlights;i++)
                {
                        light = r_refdef.scene.lights[i];
                        Matrix4x4_Transform(&light->matrix_worldtolight, p, v);
-                       f = 1 - VectorLength2(v);
-                       if (f > 0 && CL_TraceLine(p, light->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction == 1)
-                               VectorMA(ambientcolor, f, light->currentcolor, ambientcolor);
+                       f = (1 - VectorLength2(v)) * r_refdef.scene.rtlightstylevalue[light->style];
+                       if (f <= 0)
+                               continue;
+                       if (!light->shadow || CL_TraceLine(p, light->shadoworigin, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID, true, false, NULL, false).fraction == 1)
+                               VectorMA(ambientcolor, f, light->color, ambientcolor);
                }
        }
 }
index 5997605e45d771d346d58c5247a59cf8f0377081..4ca67910a5c5e1354141c8a6aa586fc929583358 100644 (file)
@@ -92,6 +92,6 @@ 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, int dynamic);
+void R_CompleteLightPoint(vec3_t ambientcolor, vec3_t diffusecolor, vec3_t diffusenormal, const vec3_t p, qboolean dynamic, qboolean rtworld);
 
 #endif
index fbcd8b36d4b4b504ea6422090c49c1973b2444b6..02348b373c73b308e78365f50f41254f07c18941 100644 (file)
@@ -386,7 +386,7 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
 
                        // lit sprite by lightgrid if it is not fullbright, lit only ambient
                        if (!(texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
-                               VectorAdd(ent->modellight_ambient, ent->modellight_diffuse, rsurface.modellight_ambient);
+                               VectorAdd(ent->modellight_ambient, ent->modellight_diffuse, rsurface.modellight_ambient); // sprites dont use lightdirection
 
                        // SPR_LABEL should not use depth test AT ALL
                        if(model->sprite.sprnum_type == SPR_LABEL || model->sprite.sprnum_type == SPR_LABEL_SCALE)