]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_light.c
newline change?
[xonotic/darkplaces.git] / r_light.c
index 90136bd724fb1e9f269a02b26dd5e2ee8353bda3..4264ea65565b898927650f5f42b6b17bbf17ca2c 100644 (file)
--- a/r_light.c
+++ b/r_light.c
@@ -26,7 +26,7 @@ int r_numdlights = 0;
 
 cvar_t r_lightmodels = {CVAR_SAVE, "r_lightmodels", "1"};
 cvar_t r_vismarklights = {0, "r_vismarklights", "1"};
-cvar_t r_lightmodelhardness = {CVAR_SAVE, "r_lightmodelhardness", "0.9"};
+//cvar_t r_lightmodelhardness = {CVAR_SAVE, "r_lightmodelhardness", "1"};
 
 static rtexture_t *lightcorona;
 static rtexturepool_t *lighttexturepool;
@@ -35,7 +35,7 @@ void r_light_start(void)
 {
        float dx, dy;
        int x, y, a;
-       byte pixels[32][32][4];
+       qbyte pixels[32][32][4];
        lighttexturepool = R_AllocTexturePool();
        for (y = 0;y < 32;y++)
        {
@@ -43,7 +43,7 @@ void r_light_start(void)
                for (x = 0;x < 32;x++)
                {
                        dx = (x - 15.5f) * (1.0f / 16.0f);
-                       a = ((1.0f / (dx * dx + dy * dy + 0.2f)) - (1.0f / (1.0f + 0.2))) * 8.0f / (1.0f / (1.0f + 0.2));
+                       a = ((1.0f / (dx * dx + dy * dy + 0.2f)) - (1.0f / (1.0f + 0.2))) * 64.0f / (1.0f / (1.0f + 0.2));
                        a = bound(0, a, 255);
                        pixels[y][x][0] = 255;
                        pixels[y][x][1] = 255;
@@ -67,7 +67,7 @@ void r_light_newmap(void)
 void R_Light_Init(void)
 {
        Cvar_RegisterVariable(&r_lightmodels);
-       Cvar_RegisterVariable(&r_lightmodelhardness);
+       //Cvar_RegisterVariable(&r_lightmodelhardness);
        Cvar_RegisterVariable(&r_vismarklights);
        R_RegisterModule("R_Light", r_light_start, r_light_shutdown, r_light_newmap);
 }
@@ -172,7 +172,8 @@ void R_DrawCoronas(void)
                        VectorSubtract(rd->origin, vpn, diff);
                        if (TraceLine(r_origin, diff, NULL, NULL, 0, true) == 1)
                        {
-                               scale = 1.0f / 4096.0f;
+                               scale = 1.0f / 262144.0f;
+                               //scale = 64.0f / (DotProduct(diff,diff) + 1024.0f);
                                m.cr = rd->light[0] * scale;
                                m.cg = rd->light[1] * scale;
                                m.cb = rd->light[2] * scale;
@@ -195,7 +196,7 @@ void R_DrawCoronas(void)
                                tvxyz[3][0] = rd->origin[0] + vright[0] * scale - vup[0] * scale;
                                tvxyz[3][1] = rd->origin[1] + vright[1] * scale - vup[1] * scale;
                                tvxyz[3][2] = rd->origin[2] + vright[2] * scale - vup[2] * scale;
-                               R_Mesh_DrawDecal(&m);
+                               R_Mesh_Draw(&m);
                        }
                }
        }
@@ -394,7 +395,7 @@ static void R_VisMarkLights (rdlight_t *rd, int bit, int bitindex)
        int             i, k, m, c, leafnum;
        msurface_t *surf, **mark;
        mleaf_t *leaf;
-       byte    *in;
+       qbyte   *in;
        int             row;
        float   low[3], high[3], dist, maxdist;
 
@@ -661,7 +662,7 @@ loc0:
 
                                if (surf->samples)
                                {
-                                       byte *lightmap;
+                                       qbyte *lightmap;
                                        int maps, line3, size3, dsfrac = ds & 15, dtfrac = dt & 15, scale = 0, r00 = 0, g00 = 0, b00 = 0, r01 = 0, g01 = 0, b01 = 0, r10 = 0, g10 = 0, b10 = 0, r11 = 0, g11 = 0, b11 = 0;
                                        line3 = ((surf->extents[0]>>4)+1)*3;
                                        size3 = ((surf->extents[0]>>4)+1) * ((surf->extents[1]>>4)+1)*3; // LordHavoc: *3 for colored lighting
@@ -803,10 +804,10 @@ void R_ModelLightPoint (vec3_t color, vec3_t p, int *dlightbits)
                dlightbits[0] = dlightbits[1] = dlightbits[2] = dlightbits[3] = dlightbits[4] = dlightbits[5] = dlightbits[6] = dlightbits[7] = 0;
 }
 
-void R_LightModel(int numverts)
+void R_LightModel(int numverts, float colorr, float colorg, float colorb, int worldcoords)
 {
        int i, j, nearlights = 0;
-       float color[3], basecolor[3], v[3], t, *av, *avn, *avc, a, number, f, hardness, hardnessoffset, dist2;
+       float color[3], basecolor[3], v[3], t, *av, *avn, *avc, a, number, f/*, hardness, hardnessoffset*/, dist2;
        struct
        {
                vec3_t origin;
@@ -819,7 +820,11 @@ void R_LightModel(int numverts)
        //staticlight_t *sl;
        a = currentrenderentity->alpha;
        if (currentrenderentity->effects & EF_FULLBRIGHT)
-               basecolor[0] = basecolor[1] = basecolor[2] = 1;
+       {
+               basecolor[0] = colorr;
+               basecolor[1] = colorg;
+               basecolor[2] = colorb;
+       }
        else
        {
                if (r_lightmodels.integer)
@@ -836,7 +841,11 @@ void R_LightModel(int numverts)
                                        nl->fadetype = sl->fadetype;
                                        nl->distancescale = sl->distancescale;
                                        nl->radius = sl->radius;
-                                       VectorCopy(sl->origin, nl->origin);
+                                       // transform the light into the model's coordinate system
+                                       if (worldcoords)
+                                               VectorCopy(sl->origin, nl->origin);
+                                       else
+                                               softwareuntransform(sl->origin, nl->origin);
                                        VectorCopy(sl->color, nl->light);
                                        nl->cullradius2 = 99999999;
                                        nl->lightsubtract = 0;
@@ -861,12 +870,14 @@ void R_LightModel(int numverts)
                                        //if (TraceLine(currentrenderentity->origin, r_dlight[i].origin, NULL, NULL, 0) == 1)
                                        {
                                                // transform the light into the model's coordinate system
-                                               //if (gl_transform.integer)
-                                               //      softwareuntransform(r_dlight[i].origin, nl->origin);
-                                               //else
+                                               if (worldcoords)
                                                        VectorCopy(r_dlight[i].origin, nl->origin);
+                                               else
+                                                       softwareuntransform(r_dlight[i].origin, nl->origin);
                                                nl->cullradius2 = r_dlight[i].cullradius2;
-                                               VectorCopy(r_dlight[i].light, nl->light);
+                                               nl->light[0] = r_dlight[i].light[0] * colorr;
+                                               nl->light[1] = r_dlight[i].light[1] * colorg;
+                                               nl->light[2] = r_dlight[i].light[2] * colorb;
                                                nl->lightsubtract = r_dlight[i].lightsubtract;
                                                nl++;
                                                nearlights++;
@@ -877,13 +888,16 @@ void R_LightModel(int numverts)
                else
                        R_CompleteLightPoint (basecolor, currentrenderentity->origin, true, NULL);
        }
+       basecolor[0] *= colorr;
+       basecolor[1] *= colorg;
+       basecolor[2] *= colorb;
        avc = aliasvertcolor;
        if (nearlights)
        {
                av = aliasvert;
                avn = aliasvertnorm;
-               hardness = r_lightmodelhardness.value;
-               hardnessoffset = (1.0f - hardness);
+               //hardness = r_lightmodelhardness.value;
+               //hardnessoffset = (1.0f - hardness);
                for (i = 0;i < numverts;i++)
                {
                        VectorCopy(basecolor, color);
@@ -907,7 +921,7 @@ void R_LightModel(int numverts)
                                                #endif
                                                // DotProduct(avn,v) * t is dotproduct with a normalized v,
                                                // the hardness variables are for backlighting/shinyness
-                                               f *= DotProduct(avn,v) * t * hardness + hardnessoffset;
+                                               f *= DotProduct(avn,v) * t;// * hardness + hardnessoffset;
                                                if (f > 0)
                                                        VectorMA(color, f, nl->light, color);
                                        }
@@ -917,7 +931,7 @@ void R_LightModel(int numverts)
                        VectorCopy(color, avc);
                        avc[3] = a;
                        avc += 4;
-                       av += 3;
+                       av += 4;
                        avn += 3;
                }
        }