]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_light.c
cleaned up R_RenderView setup code a bit, and shuffled SCR_CalcRefdef stuff to SCR_Up...
[xonotic/darkplaces.git] / r_light.c
index f5bbc46f561333118754b878aa81526de81f5ae4..3734eea9eaa67206e2c8c2627f2569c173487e7b 100644 (file)
--- a/r_light.c
+++ b/r_light.c
@@ -81,14 +81,15 @@ void R_Light_Init(void)
 
 /*
 ==================
-R_AnimateLight
+R_UpdateLights
 ==================
 */
-void R_AnimateLight (void)
+void R_UpdateLights(void)
 {
        int i, j, k;
+       dlight_t *cd;
+       rdlight_t *rd;
 
-//
 // light animations
 // 'm' is normal light, 'a' is no light, 'z' is double bright
        i = (int)(cl.time * 10);
@@ -104,14 +105,6 @@ void R_AnimateLight (void)
                k = k*22;
                d_lightstylevalue[j] = k;
        }
-}
-
-
-void R_BuildLightList(void)
-{
-       int i;
-       dlight_t *cd;
-       rdlight_t *rd;
 
        r_numdlights = 0;
        c_dlights = 0;
@@ -126,41 +119,69 @@ void R_BuildLightList(void)
                        continue;
                rd = &r_dlight[r_numdlights++];
                VectorCopy(cd->origin, rd->origin);
-               VectorScale(cd->color, cd->radius * 64.0f, rd->light);
+               VectorScale(cd->color, d_lightstylevalue[cd->style] * (1.0f / 256.0f), rd->color);
+               rd->radius = bound(0, cd->radius, 2048.0f);
+               VectorScale(rd->color, rd->radius * 64.0f, rd->light);
+#if 0
                rd->cullradius2 = DotProduct(rd->light, rd->light) * (0.25f / (64.0f * 64.0f)) + 4096.0f;
                // clamp radius to avoid overflowing division table in lightmap code
-               if (rd->cullradius2 > (2048.0f * 2048.0f))
-                       rd->cullradius2 = (2048.0f * 2048.0f);
+               rd->cullradius2 = bound(0, rd->cullradius2, 2048.0f*2048.0f);
                rd->cullradius = sqrt(rd->cullradius2);
+#else
+               rd->cullradius = rd->radius;
+               rd->cullradius2 = rd->cullradius * rd->cullradius;
+#endif
                rd->subtract = 1.0f / rd->cullradius2;
                rd->ent = cd->ent;
+               rd->cubemapnum = cd->cubemapnum;
+               rd->shadow = cd->shadow;
+               rd->corona = cd->corona;
+
+               rd->matrix_lighttoworld = cd->matrix;
+               Matrix4x4_ConcatScale(&rd->matrix_lighttoworld, rd->cullradius);
+               Matrix4x4_Invert_Simple(&rd->matrix_worldtolight, &rd->matrix_lighttoworld);
+               Matrix4x4_Concat(&rd->matrix_worldtoattenuationxyz, &matrix_attenuationxyz, &rd->matrix_worldtolight);
+               Matrix4x4_Concat(&rd->matrix_worldtoattenuationz, &matrix_attenuationz, &rd->matrix_worldtolight);
+
                c_dlights++; // count every dlight in use
        }
 }
 
 void R_DrawCoronas(void)
 {
-       int i;
+       int i, lnum;
        float cscale, scale, viewdist, dist;
        rdlight_t *rd;
+       worldlight_t *wl;
        if (!r_coronas.integer)
                return;
        R_Mesh_Matrix(&r_identitymatrix);
-       viewdist = DotProduct(r_origin, vpn);
+       viewdist = DotProduct(r_vieworigin, r_viewforward);
+       if (r_shadow_realtime_world.integer)
+       {
+               for (lnum = 0, wl = r_shadow_worldlightchain;wl;wl = wl->next, lnum++)
+               {
+                       if (wl->corona * r_coronas.value > 0 && (r_shadow_debuglight.integer < 0 || r_shadow_debuglight.integer == lnum) && (dist = (DotProduct(wl->origin, r_viewforward) - viewdist)) >= 24.0f && CL_TraceLine(wl->origin, r_vieworigin, NULL, NULL, true, NULL, SUPERCONTENTS_SOLID) == 1)
+                       {
+                               cscale = wl->corona * r_coronas.value * 0.25f;
+                               scale = wl->radius * 0.25f;
+                               R_DrawSprite(GL_ONE, GL_ONE, lightcorona, true, rd->origin, r_viewright, r_viewup, scale, -scale, -scale, scale, wl->color[0] * cscale, wl->color[1] * cscale, wl->color[2] * cscale, 1);
+                       }
+               }
+       }
        for (i = 0;i < r_numdlights;i++)
        {
                rd = r_dlight + i;
-               dist = (DotProduct(rd->origin, vpn) - viewdist);
-               if (dist >= 24.0f && CL_TraceLine(rd->origin, r_origin, NULL, NULL, true, NULL, SUPERCONTENTS_SOLID) == 1)
+               if (rd->corona * r_coronas.value > 0 && (dist = (DotProduct(rd->origin, r_viewforward) - viewdist)) >= 24.0f && CL_TraceLine(rd->origin, r_vieworigin, NULL, NULL, true, NULL, SUPERCONTENTS_SOLID) == 1)
                {
-                       cscale = (1.0f / 131072.0f);
-                       scale = rd->cullradius * 0.25f;
+                       cscale = rd->corona * r_coronas.value * 0.25f;
+                       scale = rd->radius * 0.25f;
                        if (gl_flashblend.integer)
                        {
                                cscale *= 4.0f;
                                scale *= 2.0f;
                        }
-                       R_DrawSprite(GL_ONE, GL_ONE, lightcorona, true, rd->origin, vright, vup, scale, -scale, -scale, scale, rd->light[0] * cscale, rd->light[1] * cscale, rd->light[2] * cscale, 1);
+                       R_DrawSprite(GL_ONE, GL_ONE, lightcorona, true, rd->origin, r_viewright, r_viewup, scale, -scale, -scale, scale, rd->color[0] * cscale, rd->color[1] * cscale, rd->color[2] * cscale, 1);
                }
        }
 }
@@ -252,8 +273,7 @@ static void R_RecursiveMarkLights(entity_render_t *ent, vec3_t lightorigin, rdli
                        {
                                surf->dlightbits[0] = surf->dlightbits[1] = surf->dlightbits[2] = surf->dlightbits[3] = surf->dlightbits[4] = surf->dlightbits[5] = surf->dlightbits[6] = surf->dlightbits[7] = 0;
                                surf->dlightframe = r_framecount;
-                               if (r_dlightmap.integer)
-                                       surf->cached_dlight = true;
+                               surf->cached_dlight = true;
                        }
                        surf->dlightbits[bitindex] |= bit;
                }
@@ -381,7 +401,7 @@ int R_LightModel(float *ambient4f, float *diffusecolor, float *diffusenormal, co
                VectorSet(ambient4f, 1, 1, 1);
                maxnearlights = 0;
        }
-       else if (r_shadow_realtime_world.integer)
+       else if (r_shadow_realtime_world.integer && r_shadow_realtime_world_lightmaps.value <= 0)
                maxnearlights = 0;
        else
        {
@@ -591,7 +611,7 @@ void R_UpdateEntLights(entity_render_t *ent)
        int i;
        const mlight_t *sl;
        vec3_t v;
-       if (r_shadow_realtime_dlight.integer || gl_flashblend.integer)
+       if (r_shadow_realtime_world.integer && r_shadow_realtime_world_lightmaps.value <= 0)
                return;
        VectorSubtract(ent->origin, ent->entlightsorigin, v);
        if (ent->entlightsframe != (r_framecount - 1) || (realtime > ent->entlightstime && DotProduct(v,v) >= 1.0f))