]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Improved r_sky_scissor - scissor box is tighter as it now computes scissor box for...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 9 Apr 2018 05:58:15 +0000 (05:58 +0000)
committerRudolf Polzer <divVerent@gmail.com>
Sun, 15 Mar 2020 01:51:47 +0000 (21:51 -0400)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12380 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=f20adec008541b59e0000bdabf6cc262d6c92a80

gl_rmain.c
r_sky.c
render.h

index 0a1a4e9fe3b45b661a1b75bb91702aae230e738f..96a35e764817d444d95f60da8baa544da31e81fb 100644 (file)
@@ -10529,25 +10529,48 @@ static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, const msurface_
                        const msurface_t *surf = texturesurfacelist[i];
                        const float *v;
                        float p[3];
+                       float mins[3], maxs[3];
+                       int scissor[4];
                        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 (j > 0)
                                {
-                                       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];
+                                       if (mins[0] > p[0]) mins[0] = p[0];
+                                       if (mins[1] > p[1]) mins[1] = p[1];
+                                       if (mins[2] > p[2]) mins[2] = p[2];
+                                       if (maxs[0] < p[0]) maxs[0] = p[0];
+                                       if (maxs[1] < p[1]) maxs[1] = p[1];
+                                       if (maxs[2] < p[2]) maxs[2] = p[2];
                                }
                                else
                                {
-                                       VectorCopy(p, skyscissormins);
-                                       VectorCopy(p, skyscissormaxs);
-                                       skyscissor = true;
+                                       VectorCopy(p, mins);
+                                       VectorCopy(p, maxs);
                                }
                        }
+                       if (!R_ScissorForBBox(mins, maxs, scissor))
+                       {
+                               if (skyscissor[2])
+                               {
+                                       if (skyscissor[0] > scissor[0])
+                                       {
+                                               skyscissor[2] += skyscissor[0] - scissor[0];
+                                               skyscissor[0] = scissor[0];
+                                       }
+                                       if (skyscissor[1] > scissor[1])
+                                       {
+                                               skyscissor[3] += skyscissor[1] - scissor[1];
+                                               skyscissor[1] = scissor[1];
+                                       }
+                                       if (skyscissor[0] + skyscissor[2] < scissor[0] + scissor[2])
+                                               skyscissor[2] = scissor[0] + scissor[2] - skyscissor[0];
+                                       if (skyscissor[1] + skyscissor[3] < scissor[1] + scissor[3])
+                                               skyscissor[3] = scissor[1] + scissor[3] - skyscissor[1];
+                               }
+                               else
+                                       Vector4Copy(scissor, skyscissor);
+                       }
                }
        }
 
diff --git a/r_sky.c b/r_sky.c
index bf338240cf30290fa05bc800aea7f0a43dbd18b9..17754782640d899399fe729128c639de793cb2ac 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -9,9 +9,7 @@ cvar_t r_skyscroll2 = {CVAR_SAVE, "r_skyscroll2", "2", "speed at which lower clo
 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];
+int skyscissor[4];
 
 static int skyrendersphere;
 static int skyrenderbox;
@@ -64,9 +62,7 @@ void R_SkyStartFrame(void)
        // 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);
+       Vector4Clear(skyscissor);
        if (r_sky.integer)
        {
                if (skyboxskinframe[0] || skyboxskinframe[1] || skyboxskinframe[2] || skyboxskinframe[3] || skyboxskinframe[4] || skyboxskinframe[5])
@@ -406,16 +402,15 @@ 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)
+       if (r_sky_scissor.integer)
        {
-               // compute the scissor, if it's offscreen just return
-               if (R_ScissorForBBox(skyscissormins, skyscissormaxs, scissor))
+               // if the scissor is empty just return
+               if (skyscissor[2] == 0 || skyscissor[3] == 0)
                        return;
-               GL_Scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
+               GL_Scissor(skyscissor[0], skyscissor[1], skyscissor[2], skyscissor[3]);
                GL_ScissorTest(true);
        }
        if (skyrendersphere)
index 0b54c35fee584e54711702b101d5061f3784b522..1d60682742557c301f802e9ef52ef633506fc73a 100644 (file)
--- a/render.h
+++ b/render.h
@@ -36,9 +36,7 @@ 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];
+extern int skyscissor[4];
 int R_SetSkyBox(const char *sky);
 void R_SkyStartFrame(void);
 void R_Sky(void);