Implemented r_ambient (mainly for sake of Nehahra's insanely dark maps).
[xonotic/darkplaces.git] / r_light.c
index 141d90508129514420b9e363a59e532ccb1dd670..defa8f0d58ddc1463364dfed8351a0dee3f56af1 100644 (file)
--- a/r_light.c
+++ b/r_light.c
@@ -178,8 +178,8 @@ void R_PushDlights (void)
 
        r_dlightframecount = r_framecount + 1;  // because the count hasn't advanced yet for this frame
 
-//     if (gl_flashblend.value || !r_dynamic.value)
-//             return;
+       if (/*gl_flashblend.value ||*/ !r_dynamic.value)
+               return;
 
        l = cl_dlights;
 
@@ -203,6 +203,8 @@ LIGHT SAMPLING
 mplane_t               *lightplane;
 vec3_t                 lightspot;
 
+extern cvar_t r_ambient;
+
 int RecursiveLightPoint (vec3_t color, mnode_t *node, vec3_t start, vec3_t end)
 {
        float           front, back, frac;
@@ -303,7 +305,7 @@ void R_LightPoint (vec3_t color, vec3_t p)
        end[1] = p[1];
        end[2] = p[2] - 2048;
 
-       color[0] = color[1] = color[2] = 0;
+       color[0] = color[1] = color[2] = r_ambient.value * 2.0f;
        RecursiveLightPoint (color, cl.worldmodel->nodes, p, end);
 }
 
@@ -314,7 +316,7 @@ void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits)
        vec3_t  dist;
        float   brightness, r, f;
 
-       if (/*gl_flashblend.value || !r_dynamic.value || */(!dlightbits[0] && !dlightbits[1] && !dlightbits[2] && !dlightbits[3] && !dlightbits[4] && !dlightbits[5] && !dlightbits[6] && !dlightbits[7]))
+       if (/*gl_flashblend.value ||*/ !r_dynamic.value || (!dlightbits[0] && !dlightbits[1] && !dlightbits[2] && !dlightbits[3] && !dlightbits[4] && !dlightbits[5] && !dlightbits[6] && !dlightbits[7]))
                return;
 
        for (i=0 ; i<MAX_DLIGHTS ; i++)
@@ -343,8 +345,8 @@ void R_DynamicLightPointNoMask(vec3_t color, vec3_t org)
        vec3_t  dist;
        float   brightness, r, f;
 
-//     if (gl_flashblend.value || !r_dynamic.value)
-//             return;
+       if (/*gl_flashblend.value ||*/ !r_dynamic.value)
+               return;
 
        for (i=0 ; i<MAX_DLIGHTS ; i++)
        {
@@ -363,6 +365,12 @@ void R_DynamicLightPointNoMask(vec3_t color, vec3_t org)
        }
 }
 
+void R_CompleteLightPoint (vec3_t color, vec3_t p)
+{
+       R_LightPoint(color, p);
+       R_DynamicLightPointNoMask(color, p);
+}
+
 extern float *aliasvert;
 extern float *aliasvertnorm;
 extern byte *aliasvertcolor;
@@ -419,7 +427,7 @@ void R_LightModel(int numverts, vec3_t center)
                        if (cl_dlights[i].die < cl.time || !cl_dlights[i].radius)
                                continue;
                        VectorSubtract (center, cl_dlights[i].origin, dist);
-                       if ((t2 = DotProduct(dist,dist)) + 64.0f < (t1 = cl_dlights[i].radius*cl_dlights[i].radius))
+                       if ((t2 = DotProduct(dist,dist) + 16.0f) + 64.0f < (t1 = cl_dlights[i].radius*cl_dlights[i].radius))
                        {
                                VectorCopy(cl_dlights[i].origin, nearlight[nearlights].origin);
                                nearlight[nearlights].color[0] = cl_dlights[i].color[0] * cl_dlights[i].radius * cl_dlights[i].radius * 0.5f;