Implemented r_sky_scissor feature (on by default) - this limits rendering of sky...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 9 Apr 2018 05:29:12 +0000 (05:29 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 9 Apr 2018 05:29:12 +0000 (05:29 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12379 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
model_brush.c
r_sky.c
render.h

index 73d1e2a..a51d300 100644 (file)
@@ -10511,6 +10511,7 @@ void RSurf_SetupDepthAndCulling(void)
 
 static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, const msurface_t **texturesurfacelist)
 {
+       int i, j;
        // transparent sky would be ridiculous
        if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
                return;
@@ -10518,20 +10519,52 @@ static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, const msurface_
        skyrenderlater = true;
        RSurf_SetupDepthAndCulling();
        GL_DepthMask(true);
-       // LordHavoc: HalfLife maps have freaky skypolys so don't use
+
+       // add the vertices of the surfaces to a world bounding box so we can scissor the sky render later
+       if (r_sky_scissor.integer)
+       {
+               RSurf_PrepareVerticesForBatch(BATCHNEED_ARRAY_VERTEX | BATCHNEED_ALLOWMULTIDRAW, texturenumsurfaces, texturesurfacelist);
+               for (i = 0; i < texturenumsurfaces; i++)
+               {
+                       const msurface_t *surf = texturesurfacelist[i];
+                       const float *v;
+                       float p[3];
+                       for (j = 0, v = rsurface.batchvertex3f + 3 * surf->num_firstvertex; j < surf->num_vertices; j++, v += 3)
+                       {
+                               Matrix4x4_Transform(&rsurface.matrix, v, p);
+                               if (skyscissor)
+                               {
+                                       if (skyscissormins[0] > p[0]) skyscissormins[0] = p[0];
+                                       if (skyscissormins[1] > p[1]) skyscissormins[1] = p[1];
+                                       if (skyscissormins[2] > p[2]) skyscissormins[2] = p[2];
+                                       if (skyscissormaxs[0] < p[0]) skyscissormaxs[0] = p[0];
+                                       if (skyscissormaxs[1] < p[1]) skyscissormaxs[1] = p[1];
+                                       if (skyscissormaxs[2] < p[2]) skyscissormaxs[2] = p[2];
+                               }
+                               else
+                               {
+                                       VectorCopy(p, skyscissormins);
+                                       VectorCopy(p, skyscissormaxs);
+                                       skyscissor = true;
+                               }
+                       }
+               }
+       }
+
+       // LadyHavoc: HalfLife maps have freaky skypolys so don't use
        // skymasking on them, and Quake3 never did sky masking (unlike
        // software Quake and software Quake2), so disable the sky masking
        // in Quake3 maps as it causes problems with q3map2 sky tricks,
        // and skymasking also looks very bad when noclipping outside the
        // level, so don't use it then either.
-       if (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.skymasking && r_q1bsp_skymasking.integer && !r_refdef.viewcache.world_novis && !r_trippy.integer)
+       if (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.skymasking && (r_refdef.scene.worldmodel->brush.isq3bsp ? r_q3bsp_renderskydepth.integer : r_q1bsp_skymasking.integer) && !r_refdef.viewcache.world_novis && !r_trippy.integer)
        {
                R_Mesh_ResetTextureState();
                if (skyrendermasked)
                {
                        R_SetupShader_DepthOrShadow(false, false, false);
                        // depth-only (masking)
-                       GL_ColorMask(0,0,0,0);
+                       GL_ColorMask(0, 0, 0, 0);
                        // just to make sure that braindead drivers don't draw
                        // anything despite that colormask...
                        GL_BlendFunc(GL_ZERO, GL_ONE);
index ac1a988..2d465af 100644 (file)
@@ -7899,6 +7899,7 @@ static void Mod_Q3BSP_Load(dp_model_t *mod, void *buffer, void *bufferend)
        mod->brush.isbsp2 = false;
        mod->brush.isq2bsp = false;
        mod->brush.isq3bsp = true;
+       mod->brush.skymasking = true;
        mod->numframes = 2; // although alternate textures are not supported it is annoying to complain about no such frame 1
        mod->numskins = 1;
 
diff --git a/r_sky.c b/r_sky.c
index 97b2daf..bf33824 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -6,8 +6,12 @@
 cvar_t r_sky = {CVAR_SAVE, "r_sky", "1", "enables sky rendering (black otherwise)"};
 cvar_t r_skyscroll1 = {CVAR_SAVE, "r_skyscroll1", "1", "speed at which upper clouds layer scrolls in quake sky"};
 cvar_t r_skyscroll2 = {CVAR_SAVE, "r_skyscroll2", "2", "speed at which lower clouds layer scrolls in quake sky"};
+cvar_t r_sky_scissor = {0, "r_sky_scissor", "1", "limit rendering of sky to approximately the area of the sky surfaces"};
 int skyrenderlater;
 int skyrendermasked;
+int skyscissor;
+float skyscissormins[3];
+float skyscissormaxs[3];
 
 static int skyrendersphere;
 static int skyrenderbox;
@@ -59,6 +63,10 @@ void R_SkyStartFrame(void)
        skyrendermasked = false;
        // for depth-masked sky, we need to know whether any sky was rendered
        skyrenderlater = false;
+       // we can scissor the sky to just the relevant area
+       skyscissor = false;
+       VectorClear(skyscissormins);
+       VectorClear(skyscissormaxs);
        if (r_sky.integer)
        {
                if (skyboxskinframe[0] || skyboxskinframe[1] || skyboxskinframe[2] || skyboxskinframe[3] || skyboxskinframe[4] || skyboxskinframe[5])
@@ -398,9 +406,18 @@ static void R_SkySphere(void)
 
 void R_Sky(void)
 {
+       int scissor[4];
        Matrix4x4_CreateFromQuakeEntity(&skymatrix, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2], 0, 0, 0, r_refdef.farclip * (0.5f / 16.0f));
        Matrix4x4_Invert_Simple(&skyinversematrix, &skymatrix);
 
+       if (r_sky_scissor.integer && skyscissor)
+       {
+               // compute the scissor, if it's offscreen just return
+               if (R_ScissorForBBox(skyscissormins, skyscissormaxs, scissor))
+                       return;
+               GL_Scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
+               GL_ScissorTest(true);
+       }
        if (skyrendersphere)
        {
                // this does not modify depth buffer
@@ -420,6 +437,7 @@ void R_Sky(void)
                //GL_Clear(GL_DEPTH_BUFFER_BIT);
        }
        */
+       GL_Scissor(0, 0, vid.width, vid.height);
 }
 
 //===============================================================
@@ -454,6 +472,7 @@ void R_Sky_Init(void)
        Cvar_RegisterVariable (&r_sky);
        Cvar_RegisterVariable (&r_skyscroll1);
        Cvar_RegisterVariable (&r_skyscroll2);
+       Cvar_RegisterVariable (&r_sky_scissor);
        memset(&skyboxskinframe, 0, sizeof(skyboxskinframe));
        skyname[0] = 0;
        R_RegisterModule("R_Sky", r_sky_start, r_sky_shutdown, r_sky_newmap, NULL, NULL);
index e049dbc..0b54c35 100644 (file)
--- a/render.h
+++ b/render.h
@@ -33,7 +33,12 @@ void FOG_clear(void);
 extern cvar_t r_sky;
 extern cvar_t r_skyscroll1;
 extern cvar_t r_skyscroll2;
+extern cvar_t r_sky_scissor;
+extern cvar_t r_q3bsp_renderskydepth;
 extern int skyrenderlater, skyrendermasked;
+extern int skyscissor;
+extern float skyscissormins[3];
+extern float skyscissormaxs[3];
 int R_SetSkyBox(const char *sky);
 void R_SkyStartFrame(void);
 void R_Sky(void);