]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_shadow.c
E4M9 was added to the Transfusion map list
[xonotic/darkplaces.git] / r_shadow.c
index 582e7e4108d75aa958da78d913116c9a3b872a6b..f8a0e3dec69b8b410ba16d5cd65d661cecdd3feb 100644 (file)
@@ -29,13 +29,15 @@ rtexture_t *r_shadow_blankbumptexture;
 rtexture_t *r_shadow_blankglosstexture;
 rtexture_t *r_shadow_blankwhitetexture;
 
+cvar_t r_shadow_lightattenuationpower = {0, "r_shadow_lightattenuationpower", "2"};
 cvar_t r_shadow_lightattenuationscale = {0, "r_shadow_lightattenuationscale", "2"};
 cvar_t r_shadow_lightintensityscale = {0, "r_shadow_lightintensityscale", "1"};
 cvar_t r_shadow_realtime = {0, "r_shadow_realtime", "0"};
 cvar_t r_shadow_gloss = {0, "r_shadow_gloss", "1"};
 cvar_t r_shadow_debuglight = {0, "r_shadow_debuglight", "-1"};
 cvar_t r_shadow_scissor = {0, "r_shadow_scissor", "1"};
-cvar_t r_shadow_bumpscale = {0, "r_shadow_bumpscale", "4"};
+cvar_t r_shadow_bumpscale_bumpmap = {0, "r_shadow_bumpscale_bumpmap", "4"};
+cvar_t r_shadow_bumpscale_basetexture = {0, "r_shadow_bumpscale_basetexture", "4"};
 cvar_t r_shadow_shadownudge = {0, "r_shadow_shadownudge", "1"};
 
 void R_Shadow_ClearWorldLights(void);
@@ -87,13 +89,15 @@ void r_shadow_newmap(void)
 
 void R_Shadow_Init(void)
 {
+       Cvar_RegisterVariable(&r_shadow_lightattenuationpower);
        Cvar_RegisterVariable(&r_shadow_lightattenuationscale);
        Cvar_RegisterVariable(&r_shadow_lightintensityscale);
        Cvar_RegisterVariable(&r_shadow_realtime);
        Cvar_RegisterVariable(&r_shadow_gloss);
        Cvar_RegisterVariable(&r_shadow_debuglight);
        Cvar_RegisterVariable(&r_shadow_scissor);
-       Cvar_RegisterVariable(&r_shadow_bumpscale);
+       Cvar_RegisterVariable(&r_shadow_bumpscale_bumpmap);
+       Cvar_RegisterVariable(&r_shadow_bumpscale_basetexture);
        Cvar_RegisterVariable(&r_shadow_shadownudge);
        R_Shadow_EditLights_Init();
        R_RegisterModule("R_Shadow", r_shadow_start, r_shadow_shutdown, r_shadow_newmap);
@@ -128,7 +132,7 @@ void R_Shadow_MakeTriangleShadowFlags(const int *elements, const float *vertex,
                // of the comparison use it, therefore they are both multiplied the
                // same amount...  furthermore the subtract can be done on the
                // vectors, saving a little bit of math in the dotproducts
-#if 0
+#if 1
                // fast version
                // subtracts v1 from v0 and v2, combined into a crossproduct,
                // combined with a dotproduct of the light location relative to the
@@ -142,7 +146,7 @@ void R_Shadow_MakeTriangleShadowFlags(const int *elements, const float *vertex,
 #else
                // readable version
                {
-               float dir0[3], dir1[3], temp[3], f;
+               float dir0[3], dir1[3], temp[3];
 
                // calculate two mostly perpendicular edge directions
                VectorSubtract(v0, v1, dir0);
@@ -161,9 +165,7 @@ void R_Shadow_MakeTriangleShadowFlags(const int *elements, const float *vertex,
                // I.E. flat, so all points give the same answer)
                // the normal is not normalized because it is used on both sides of
                // the comparison, so it's magnitude does not matter
-               //trianglefacinglight[i] = DotProduct(relativelightorigin, temp) >= DotProduct(v0, temp);
-               f = DotProduct(relativelightorigin, temp) - DotProduct(v0, temp);
-               trianglefacinglight[i] = f > 0 && f < lightradius * sqrt(DotProduct(temp, temp));
+               trianglefacinglight[i] = DotProduct(relativelightorigin, temp) >= DotProduct(v0, temp);
                }
 #endif
        }
@@ -347,7 +349,7 @@ void R_Shadow_RenderShadowMeshVolume(shadowmesh_t *firstmesh)
        }
 }
 
-float r_shadow_atten1;
+float r_shadow_attenpower, r_shadow_attenscale;
 static void R_Shadow_MakeTextures(void)
 {
        int x, y, d, side;
@@ -355,7 +357,8 @@ static void R_Shadow_MakeTextures(void)
        qbyte *data;
        R_FreeTexturePool(&r_shadow_texturepool);
        r_shadow_texturepool = R_AllocTexturePool();
-       r_shadow_atten1 = r_shadow_lightattenuationscale.value;
+       r_shadow_attenpower = r_shadow_lightattenuationpower.value;
+       r_shadow_attenscale = r_shadow_lightattenuationscale.value;
        data = Mem_Alloc(tempmempool, 6*128*128*4);
        data[0] = 128;
        data[1] = 128;
@@ -431,8 +434,8 @@ static void R_Shadow_MakeTextures(void)
                        v[2] = 0;
                        intensity = 1.0f - sqrt(DotProduct(v, v));
                        if (intensity > 0)
-                               intensity *= intensity;
-                       intensity = bound(0, intensity * r_shadow_atten1 * 256.0f, 255.0f);
+                               intensity = pow(intensity, r_shadow_attenpower);
+                       intensity = bound(0, intensity * r_shadow_attenscale * 256.0f, 255.0f);
                        d = bound(0, intensity, 255);
                        data[((0*128+y)*128+x)*4+0] = d;
                        data[((0*128+y)*128+x)*4+1] = d;
@@ -450,7 +453,8 @@ void R_Shadow_Stage_Begin(void)
 
        //cl.worldmodel->numlights = min(cl.worldmodel->numlights, 1);
        if (!r_shadow_attenuation2dtexture
-        || r_shadow_lightattenuationscale.value != r_shadow_atten1)
+        || r_shadow_lightattenuationpower.value != r_shadow_attenpower
+        || r_shadow_lightattenuationscale.value != r_shadow_attenscale)
                R_Shadow_MakeTextures();
        if (r_shadow_reloadlights && cl.worldmodel)
        {
@@ -612,6 +616,8 @@ int R_Shadow_ScissorForBBoxAndSphere(const float *mins, const float *maxs, const
                return true;
        // ok some of it is infront of the view, transform each corner back to
        // worldspace and then to screenspace and make screen rect
+       // initialize these variables just to avoid compiler warnings
+       x1 = y1 = x2 = y2 = 0;
        for (i = 0;i < 8;i++)
        {
                v2[0] = (i & 1) ? smins[0] : smaxs[0];