changed sky rendering to occur after depthmask polygons, instead of before
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 6 Nov 2009 11:49:32 +0000 (11:49 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 6 Nov 2009 11:49:32 +0000 (11:49 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9431 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
r_sky.c
render.h

index 692d03b..6a0c378 100644 (file)
@@ -4859,6 +4859,14 @@ void R_RenderScene(void)
 
                if (R_DrawBrushModelsSky() && r_timereport_active)
                        R_TimeReport("bmodelsky");
 
                if (R_DrawBrushModelsSky() && r_timereport_active)
                        R_TimeReport("bmodelsky");
+
+               if (skyrendermasked && skyrenderlater)
+               {
+                       // we have to force off the water clipping plane while rendering sky
+                       R_SetupView(false);
+                       R_Sky();
+                       R_SetupView(true);
+               }
        }
 
        R_AnimCache_CacheVisibleEntities();
        }
 
        R_AnimCache_CacheVisibleEntities();
@@ -7026,16 +7034,7 @@ static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, msurface_t **te
        if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
                return;
        R_SetupGenericShader(false);
        if (rsurface.texture->currentmaterialflags & MATERIALFLAGMASK_DEPTHSORTED)
                return;
        R_SetupGenericShader(false);
-       if (skyrendernow)
-       {
-               skyrendernow = false;
-               // we have to force off the water clipping plane while rendering sky
-               R_SetupView(false);
-               R_Sky();
-               R_SetupView(true);
-               // restore entity matrix
-               R_Mesh_Matrix(&rsurface.matrix);
-       }
+       skyrenderlater = true;
        RSurf_SetupDepthAndCulling();
        GL_DepthMask(true);
        // LordHavoc: HalfLife maps have freaky skypolys so don't use
        RSurf_SetupDepthAndCulling();
        GL_DepthMask(true);
        // LordHavoc: HalfLife maps have freaky skypolys so don't use
diff --git a/r_sky.c b/r_sky.c
index c5e8425..8f63cab 100644 (file)
--- a/r_sky.c
+++ b/r_sky.c
@@ -6,13 +6,15 @@
 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 = {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"};
-int skyrendernow;
+int skyrenderlater;
 int skyrendermasked;
 
 static int skyrendersphere;
 static int skyrenderbox;
 static rtexturepool_t *skytexturepool;
 static char skyname[MAX_QPATH];
 int skyrendermasked;
 
 static int skyrendersphere;
 static int skyrenderbox;
 static rtexturepool_t *skytexturepool;
 static char skyname[MAX_QPATH];
+static matrix4x4_t skymatrix;
+static matrix4x4_t skyinversematrix;
 
 typedef struct suffixinfo_s
 {
 
 typedef struct suffixinfo_s
 {
@@ -52,18 +54,17 @@ static rtexture_t *skyboxside[6];
 
 void R_SkyStartFrame(void)
 {
 
 void R_SkyStartFrame(void)
 {
-       skyrendernow = false;
        skyrendersphere = false;
        skyrenderbox = false;
        skyrendermasked = false;
        skyrendersphere = false;
        skyrenderbox = false;
        skyrendermasked = false;
+       // for depth-masked sky, we need to know whether any sky was rendered
+       skyrenderlater = false;
        if (r_sky.integer && !(r_refdef.fogenabled && r_refdef.fogmasktable[FOGMASKTABLEWIDTH-1] < (1.0f / 256.0f)))
        {
                if (skyboxside[0] || skyboxside[1] || skyboxside[2] || skyboxside[3] || skyboxside[4] || skyboxside[5])
                        skyrenderbox = true;
                else if (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.solidskytexture)
                        skyrendersphere = true;
        if (r_sky.integer && !(r_refdef.fogenabled && r_refdef.fogmasktable[FOGMASKTABLEWIDTH-1] < (1.0f / 256.0f)))
        {
                if (skyboxside[0] || skyboxside[1] || skyboxside[2] || skyboxside[3] || skyboxside[4] || skyboxside[5])
                        skyrenderbox = true;
                else if (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->brush.solidskytexture)
                        skyrendersphere = true;
-               // for depth-masked sky, render the sky on the first sky surface encountered
-               skyrendernow = true;
                skyrendermasked = true;
        }
 }
                skyrendermasked = true;
        }
 }
@@ -330,9 +331,9 @@ static void skyspherecalc(void)
        unsigned short *e;
        float a, b, x, ax, ay, v[3], length, *vertex3f, *texcoord2f;
        float dx, dy, dz;
        unsigned short *e;
        float a, b, x, ax, ay, v[3], length, *vertex3f, *texcoord2f;
        float dx, dy, dz;
-       dx = 16;
-       dy = 16;
-       dz = 16 / 3;
+       dx = 16.0f;
+       dy = 16.0f;
+       dz = 16.0f / 3.0f;
        vertex3f = skysphere_vertex3f;
        texcoord2f = skysphere_texcoord2f;
        for (j = 0;j <= skygridy;j++)
        vertex3f = skysphere_vertex3f;
        texcoord2f = skysphere_texcoord2f;
        for (j = 0;j <= skygridy;j++)
@@ -373,7 +374,7 @@ static void skyspherecalc(void)
 
 static void R_SkySphere(void)
 {
 
 static void R_SkySphere(void)
 {
-       float speedscale;
+       double speedscale;
        static qboolean skysphereinitialized = false;
        matrix4x4_t scroll1matrix, scroll2matrix;
        if (!skysphereinitialized)
        static qboolean skysphereinitialized = false;
        matrix4x4_t scroll1matrix, scroll2matrix;
        if (!skysphereinitialized)
@@ -386,11 +387,11 @@ static void R_SkySphere(void)
 
        // scroll speed for upper layer
        speedscale = r_refdef.scene.time*r_skyscroll1.value*8.0/128.0;
 
        // scroll speed for upper layer
        speedscale = r_refdef.scene.time*r_skyscroll1.value*8.0/128.0;
-       speedscale -= (int)speedscale;
+       speedscale -= floor(speedscale);
        Matrix4x4_CreateTranslate(&scroll1matrix, speedscale, speedscale, 0);
        // scroll speed for lower layer (transparent layer)
        speedscale = r_refdef.scene.time*r_skyscroll2.value*8.0/128.0;
        Matrix4x4_CreateTranslate(&scroll1matrix, speedscale, speedscale, 0);
        // scroll speed for lower layer (transparent layer)
        speedscale = r_refdef.scene.time*r_skyscroll2.value*8.0/128.0;
-       speedscale -= (int)speedscale;
+       speedscale -= floor(speedscale);
        Matrix4x4_CreateTranslate(&scroll2matrix, speedscale, speedscale, 0);
 
        // FIXME: fixed function path can't properly handle r_refdef.view.colorscale > 1
        Matrix4x4_CreateTranslate(&scroll2matrix, speedscale, speedscale, 0);
 
        // FIXME: fixed function path can't properly handle r_refdef.view.colorscale > 1
@@ -448,34 +449,32 @@ static void R_SkySphere(void)
 
 void R_Sky(void)
 {
 
 void R_Sky(void)
 {
-       matrix4x4_t skymatrix;
-       if (skyrendermasked)
+       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);
+
+       R_Mesh_Matrix(&skymatrix);
+       if (skyrendersphere)
        {
        {
-               Matrix4x4_CreateTranslate(&skymatrix, r_refdef.view.origin[0], r_refdef.view.origin[1], r_refdef.view.origin[2]);
-               R_Mesh_Matrix(&skymatrix);
-               if (skyrendersphere)
-               {
-                       // this does not modify depth buffer
-                       R_SkySphere();
-               }
-               else if (skyrenderbox)
-               {
-                       // this does not modify depth buffer
-                       R_SkyBox();
-               }
-               /* this will be skyroom someday
-               else
-               {
-                       // this modifies the depth buffer so we have to clear it afterward
-                       //R_SkyRoom();
-                       // clear the depthbuffer that was used while rendering the skyroom
-                       //GL_Clear(GL_DEPTH_BUFFER_BIT);
-               }
-               */
-               GL_DepthRange(0, 1);
-               GL_DepthTest(true);
-               GL_DepthMask(true);
+               // this does not modify depth buffer
+               R_SkySphere();
        }
        }
+       else if (skyrenderbox)
+       {
+               // this does not modify depth buffer
+               R_SkyBox();
+       }
+       /* this will be skyroom someday
+       else
+       {
+               // this modifies the depth buffer so we have to clear it afterward
+               //R_SkyRoom();
+               // clear the depthbuffer that was used while rendering the skyroom
+               //GL_Clear(GL_DEPTH_BUFFER_BIT);
+       }
+       */
+       GL_DepthRange(0, 1);
+       GL_DepthTest(true);
+       GL_DepthMask(true);
 }
 
 //===============================================================
 }
 
 //===============================================================
index 4f49d78..41b1d65 100644 (file)
--- a/render.h
+++ b/render.h
@@ -33,7 +33,7 @@ extern void FOG_clear(void);
 extern cvar_t r_sky;
 extern cvar_t r_skyscroll1;
 extern cvar_t r_skyscroll2;
 extern cvar_t r_sky;
 extern cvar_t r_skyscroll1;
 extern cvar_t r_skyscroll2;
-extern int skyrendernow, skyrendermasked;
+extern int skyrenderlater, skyrendermasked;
 extern int R_SetSkyBox(const char *sky);
 extern void R_SkyStartFrame(void);
 extern void R_Sky(void);
 extern int R_SetSkyBox(const char *sky);
 extern void R_SkyStartFrame(void);
 extern void R_Sky(void);