]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Revert "Remove unused light attention textures (2D and 3D) since the GL1 path was... TimePath/master
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 2 Jun 2019 05:11:20 +0000 (15:11 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 2 Jun 2019 05:14:47 +0000 (15:14 +1000)
This reverts commit c254ce3c

r_shadow.c
r_shadow.h

index 1553ac675d77c024cb9f11a9f9d1659256c3541c..c2d5decc2c512ba73d8fc32212817f5e97e144af 100644 (file)
@@ -24,6 +24,7 @@ r_shadow_rendermode_t;
 
 typedef enum r_shadow_shadowmode_e
 {
+       R_SHADOW_SHADOWMODE_STENCIL,
        R_SHADOW_SHADOWMODE_SHADOWMAP2D
 }
 r_shadow_shadowmode_t;
@@ -103,6 +104,8 @@ unsigned char *r_shadow_buffer_lighttrispvs;
 
 rtexturepool_t *r_shadow_texturepool;
 rtexture_t *r_shadow_attenuationgradienttexture;
+rtexture_t *r_shadow_attenuation2dtexture;
+rtexture_t *r_shadow_attenuation3dtexture;
 skinframe_t *r_shadow_lightcorona;
 rtexture_t *r_shadow_shadowmap2ddepthbuffer;
 rtexture_t *r_shadow_shadowmap2ddepthtexture;
@@ -183,6 +186,7 @@ cvar_t r_shadow_shadowmapping_bias = {CVAR_SAVE, "r_shadow_shadowmapping_bias",
 cvar_t r_shadow_shadowmapping_polygonfactor = {CVAR_SAVE, "r_shadow_shadowmapping_polygonfactor", "2", "slope-dependent shadowmapping bias"};
 cvar_t r_shadow_shadowmapping_polygonoffset = {CVAR_SAVE, "r_shadow_shadowmapping_polygonoffset", "0", "constant shadowmapping bias"};
 cvar_t r_shadow_sortsurfaces = {0, "r_shadow_sortsurfaces", "1", "improve performance by sorting illuminated surfaces by texture"};
+cvar_t r_shadow_texture3d = {0, "r_shadow_texture3d", "1", "use 3D voxel textures for spherical attenuation rather than cylindrical (does not affect OpenGL 2.0 render path)"};
 cvar_t r_shadow_culllights_pvs = {CVAR_SAVE, "r_shadow_culllights_pvs", "1", "check if light overlaps any visible bsp leafs when determining if the light is visible"};
 cvar_t r_shadow_culllights_trace = {CVAR_SAVE, "r_shadow_culllights_trace", "1", "use raytraces from the eye to random places within light bounds to determine if the light is visible"};
 cvar_t r_shadow_culllights_trace_eyejitter = {CVAR_SAVE, "r_shadow_culllights_trace_eyejitter", "16", "offset eye location randomly by this much"};
@@ -283,6 +287,7 @@ void R_Shadow_LoadWorldLights(void);
 void R_Shadow_LoadLightsFile(void);
 void R_Shadow_LoadWorldLightsFromMap_LightArghliteTyrlite(void);
 void R_Shadow_EditLights_Reload_f(void);
+void R_Shadow_ValidateCvars(void);
 static void R_Shadow_MakeTextures(void);
 
 #define EDLIGHTSPRSIZE                 8
@@ -308,7 +313,7 @@ static void R_Shadow_SetShadowMode(void)
        r_shadow_shadowmapsampler = false;
        r_shadow_shadowmappcf = 0;
        r_shadow_shadowmapdepthtexture = r_fb.usedepthtextures;
-       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
+       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_STENCIL;
        Mod_AllocLightmap_Init(&r_shadow_shadowmapatlas_state, r_main_mempool, r_shadow_shadowmaptexturesize, r_shadow_shadowmaptexturesize);
        if (r_shadow_shadowmapping.integer || r_shadow_deferred.integer)
        {
@@ -401,7 +406,9 @@ static void r_shadow_start(void)
        // allocate vertex processing arrays
        memset(&r_shadow_bouncegrid_state, 0, sizeof(r_shadow_bouncegrid_state));
        r_shadow_attenuationgradienttexture = NULL;
-       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_SHADOWMAP2D;
+       r_shadow_attenuation2dtexture = NULL;
+       r_shadow_attenuation3dtexture = NULL;
+       r_shadow_shadowmode = R_SHADOW_SHADOWMODE_STENCIL;
        r_shadow_shadowmap2ddepthtexture = NULL;
        r_shadow_shadowmap2ddepthbuffer = NULL;
        r_shadow_shadowmapvsdcttexture = NULL;
@@ -418,6 +425,7 @@ static void r_shadow_start(void)
 
        r_shadow_texturepool = NULL;
        r_shadow_filters_texturepool = NULL;
+       R_Shadow_ValidateCvars();
        R_Shadow_MakeTextures();
        r_shadow_scenemaxlights = 0;
        r_shadow_scenenumlights = 0;
@@ -498,6 +506,8 @@ static void r_shadow_shutdown(void)
        r_shadow_bouncegrid_state.maxsplatpaths = 0;
        memset(&r_shadow_bouncegrid_state, 0, sizeof(r_shadow_bouncegrid_state));
        r_shadow_attenuationgradienttexture = NULL;
+       r_shadow_attenuation2dtexture = NULL;
+       r_shadow_attenuation3dtexture = NULL;
        R_FreeTexturePool(&r_shadow_texturepool);
        R_FreeTexturePool(&r_shadow_filters_texturepool);
        maxshadowtriangles = 0;
@@ -631,6 +641,7 @@ void R_Shadow_Init(void)
        Cvar_RegisterVariable(&r_shadow_shadowmapping_polygonfactor);
        Cvar_RegisterVariable(&r_shadow_shadowmapping_polygonoffset);
        Cvar_RegisterVariable(&r_shadow_sortsurfaces);
+       Cvar_RegisterVariable(&r_shadow_texture3d);
        Cvar_RegisterVariable(&r_shadow_culllights_pvs);
        Cvar_RegisterVariable(&r_shadow_culllights_trace);
        Cvar_RegisterVariable(&r_shadow_culllights_trace_eyejitter);
@@ -1215,7 +1226,7 @@ static unsigned int R_Shadow_MakeTextures_SamplePoint(float x, float y, float z)
 
 static void R_Shadow_MakeTextures(void)
 {
-       int x;
+       int x, y, z;
        float intensity, dist;
        unsigned int *data;
        R_Shadow_FreeShadowMaps();
@@ -1235,6 +1246,22 @@ static void R_Shadow_MakeTextures(void)
        for (x = 0;x < ATTEN1DSIZE;x++)
                data[x] = R_Shadow_MakeTextures_SamplePoint((x + 0.5f) * (1.0f / ATTEN1DSIZE) * (1.0f / 0.9375), 0, 0);
        r_shadow_attenuationgradienttexture = R_LoadTexture2D(r_shadow_texturepool, "attenuation1d", ATTEN1DSIZE, 1, (unsigned char *)data, TEXTYPE_BGRA, TEXF_CLAMP | TEXF_ALPHA | TEXF_FORCELINEAR, -1, NULL);
+       // 2D circle texture
+       for (y = 0;y < ATTEN2DSIZE;y++)
+               for (x = 0;x < ATTEN2DSIZE;x++)
+                       data[y*ATTEN2DSIZE+x] = R_Shadow_MakeTextures_SamplePoint(((x + 0.5f) * (2.0f / ATTEN2DSIZE) - 1.0f) * (1.0f / 0.9375), ((y + 0.5f) * (2.0f / ATTEN2DSIZE) - 1.0f) * (1.0f / 0.9375), 0);
+       r_shadow_attenuation2dtexture = R_LoadTexture2D(r_shadow_texturepool, "attenuation2d", ATTEN2DSIZE, ATTEN2DSIZE, (unsigned char *)data, TEXTYPE_BGRA, TEXF_CLAMP | TEXF_ALPHA | TEXF_FORCELINEAR, -1, NULL);
+       // 3D sphere texture
+       if (r_shadow_texture3d.integer && false)
+       {
+               for (z = 0;z < ATTEN3DSIZE;z++)
+                       for (y = 0;y < ATTEN3DSIZE;y++)
+                               for (x = 0;x < ATTEN3DSIZE;x++)
+                                       data[(z*ATTEN3DSIZE+y)*ATTEN3DSIZE+x] = R_Shadow_MakeTextures_SamplePoint(((x + 0.5f) * (2.0f / ATTEN3DSIZE) - 1.0f) * (1.0f / 0.9375), ((y + 0.5f) * (2.0f / ATTEN3DSIZE) - 1.0f) * (1.0f / 0.9375), ((z + 0.5f) * (2.0f / ATTEN3DSIZE) - 1.0f) * (1.0f / 0.9375));
+               r_shadow_attenuation3dtexture = R_LoadTexture3D(r_shadow_texturepool, "attenuation3d", ATTEN3DSIZE, ATTEN3DSIZE, ATTEN3DSIZE, (unsigned char *)data, TEXTYPE_BGRA, TEXF_CLAMP | TEXF_ALPHA | TEXF_FORCELINEAR, -1, NULL);
+       }
+       else
+               r_shadow_attenuation3dtexture = NULL;
        Mem_Free(data);
 
        R_Shadow_MakeTextures_MakeCorona();
@@ -1350,14 +1377,23 @@ static void R_Shadow_MakeTextures(void)
        , 16, 16, palette_bgra_embeddedpic, palette_bgra_embeddedpic);
 }
 
+void R_Shadow_ValidateCvars(void)
+{
+       if (r_shadow_texture3d.integer && true)
+               Cvar_SetValueQuick(&r_shadow_texture3d, 0);
+}
+
 void R_Shadow_RenderMode_Begin(void)
 {
 #if 0
        GLint drawbuffer;
        GLint readbuffer;
 #endif
+       R_Shadow_ValidateCvars();
 
-       if (r_shadow_lightattenuationdividebias.value != r_shadow_attendividebias
+       if (!r_shadow_attenuation2dtexture
+        || (!r_shadow_attenuation3dtexture && r_shadow_texture3d.integer)
+        || r_shadow_lightattenuationdividebias.value != r_shadow_attendividebias
         || r_shadow_lightattenuationlinearscale.value != r_shadow_attenlinearscale)
                R_Shadow_MakeTextures();
 
index c57f40b66181f66c810f3eee1f07f17589d24b6a..048fcc4ede2de61a7e92cdfa94c6c5f73e903dbd 100644 (file)
@@ -31,6 +31,7 @@ extern cvar_t r_shadow_realtime_world_compileshadow;
 extern cvar_t r_shadow_realtime_world_compilesvbsp;
 extern cvar_t r_shadow_realtime_world_compileportalculling;
 extern cvar_t r_shadow_scissor;
+extern cvar_t r_shadow_texture3d;
 
 // used by shader for bouncegrid feature
 typedef struct r_shadow_bouncegrid_settings_s