reuse screenspace depth texture unit for orthographic shadowmaps so they can coexist...
authoreihrul <eihrul@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 4 Feb 2010 01:45:36 +0000 (01:45 +0000)
committereihrul <eihrul@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 4 Feb 2010 01:45:36 +0000 (01:45 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9928 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
r_shadow.c
render.h

index 2b70cb7..b1bb20d 100644 (file)
@@ -3727,9 +3727,9 @@ static void R_GLSL_CompilePermutation(r_glsl_permutation_t *p, unsigned int mode
                if (p->loc_Texture_Cube            >= 0) qglUniform1iARB(p->loc_Texture_Cube           , GL20TU_CUBE);
                if (p->loc_Texture_Refraction      >= 0) qglUniform1iARB(p->loc_Texture_Refraction     , GL20TU_REFRACTION);
                if (p->loc_Texture_Reflection      >= 0) qglUniform1iARB(p->loc_Texture_Reflection     , GL20TU_REFLECTION);
-               if (p->loc_Texture_ShadowMapRect   >= 0) qglUniform1iARB(p->loc_Texture_ShadowMapRect  , GL20TU_SHADOWMAPRECT);
+               if (p->loc_Texture_ShadowMapRect   >= 0) qglUniform1iARB(p->loc_Texture_ShadowMapRect  , permutation & SHADERPERMUTATION_SHADOWMAPORTHO ? GL20TU_SHADOWMAPORTHORECT : GL20TU_SHADOWMAPRECT);
                if (p->loc_Texture_ShadowMapCube   >= 0) qglUniform1iARB(p->loc_Texture_ShadowMapCube  , GL20TU_SHADOWMAPCUBE);
-               if (p->loc_Texture_ShadowMap2D     >= 0) qglUniform1iARB(p->loc_Texture_ShadowMap2D    , GL20TU_SHADOWMAP2D);
+               if (p->loc_Texture_ShadowMap2D     >= 0) qglUniform1iARB(p->loc_Texture_ShadowMap2D    , permutation & SHADERPERMUTATION_SHADOWMAPORTHO ? GL20TU_SHADOWMAPORTHO2D : GL20TU_SHADOWMAP2D);
                if (p->loc_Texture_CubeProjection  >= 0) qglUniform1iARB(p->loc_Texture_CubeProjection , GL20TU_CUBEPROJECTION);
                if (p->loc_Texture_ScreenDepth     >= 0) qglUniform1iARB(p->loc_Texture_ScreenDepth    , GL20TU_SCREENDEPTH);
                if (p->loc_Texture_ScreenNormalMap >= 0) qglUniform1iARB(p->loc_Texture_ScreenNormalMap, GL20TU_SCREENNORMALMAP);
@@ -5021,8 +5021,8 @@ void R_SetupShader_Surface(const vec3_t lightcolorbase, qboolean modellighting,
                if (r_glsl_permutation->loc_Texture_ScreenSpecular  >= 0) R_Mesh_TexBind(GL20TU_SCREENSPECULAR    , r_shadow_prepasslightingspeculartexture             );
                if (rsurface.rtlight || r_shadow_usingshadowmaportho)
                {
-                       if (r_glsl_permutation->loc_Texture_ShadowMap2D     >= 0) R_Mesh_TexBind(GL20TU_SHADOWMAP2D       , r_shadow_shadowmap2dtexture                         );
-                       if (r_glsl_permutation->loc_Texture_ShadowMapRect   >= 0) R_Mesh_TexBind(GL20TU_SHADOWMAPRECT     , r_shadow_shadowmaprectangletexture                  );
+                       if (r_glsl_permutation->loc_Texture_ShadowMap2D     >= 0) R_Mesh_TexBind(r_shadow_usingshadowmaportho ? GL20TU_SHADOWMAPORTHO2D : GL20TU_SHADOWMAP2D, r_shadow_shadowmap2dtexture                         );
+                       if (r_glsl_permutation->loc_Texture_ShadowMapRect   >= 0) R_Mesh_TexBind(r_shadow_usingshadowmaportho ? GL20TU_SHADOWMAPORTHORECT : GL20TU_SHADOWMAPRECT, r_shadow_shadowmaprectangletexture                  );
                        if (rsurface.rtlight)
                        {
                                if (r_glsl_permutation->loc_Texture_Cube            >= 0) R_Mesh_TexBind(GL20TU_CUBE              , rsurface.rtlight->currentcubemap                    );
index 734c43e..2b9f48e 100644 (file)
@@ -505,8 +505,6 @@ void R_Shadow_FreeShadowMaps(void)
        r_shadow_shadowmapvsdcttexture = NULL;
 
        CHECKGLERROR
-
-       r_shadow_usingshadowmaportho = false;
 }
 
 void r_shadow_start(void)
@@ -1978,6 +1976,7 @@ void R_Shadow_RenderMode_Reset(void)
        r_shadow_usingshadowmaprect = false;
        r_shadow_usingshadowmapcube = false;
        r_shadow_usingshadowmap2d = false;
+       r_shadow_usingshadowmaportho = false;
        CHECKGLERROR
 }
 
@@ -2315,12 +2314,20 @@ void R_Shadow_RenderMode_DrawDeferredLight(qboolean stenciltest, qboolean shadow
                qglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, r_shadow_prepasslightingfbo);CHECKGLERROR
                if (shadowmapping)
                {
-                       if (r_shadow_shadowmode == R_SHADOW_SHADOWMODE_SHADOWMAP2D)
+                       switch (r_shadow_shadowmode)
+                       {
+                       case R_SHADOW_SHADOWMODE_SHADOWMAP2D:
                                r_shadow_usingshadowmap2d = true;
-                       else if (r_shadow_shadowmode == R_SHADOW_SHADOWMODE_SHADOWMAPRECTANGLE)
+                               break;
+                       case R_SHADOW_SHADOWMODE_SHADOWMAPRECTANGLE:
                                r_shadow_usingshadowmaprect = true;
-                       else if (r_shadow_shadowmode == R_SHADOW_SHADOWMODE_SHADOWMAPCUBESIDE)
+                               break;
+                       case R_SHADOW_SHADOWMODE_SHADOWMAPCUBESIDE:
                                r_shadow_usingshadowmapcube = true;
+                               break;
+                       default:
+                               break;
+                       }
                }
 
                // render the lighting
@@ -4291,7 +4298,7 @@ void R_DrawModelShadowMaps(void)
        GL_DepthMask(true);
        GL_DepthTest(true);
        R_SetViewport(&viewport);
-       GL_Scissor(viewport.x, viewport.y, viewport.width + r_shadow_shadowmapborder, viewport.height + r_shadow_shadowmapborder);
+       GL_Scissor(viewport.x, viewport.y, min(viewport.width + r_shadow_shadowmapborder, 2*r_shadow_shadowmapmaxsize), viewport.height + r_shadow_shadowmapborder);
        qglClearDepth(1);
 #if 0
        qglClearColor(1,1,1,1);
index ee9e759..23b6b31 100644 (file)
--- a/render.h
+++ b/render.h
@@ -452,6 +452,9 @@ typedef enum gl20_texunit_e
        GL20TU_SHADOWMAPCUBE = 11,
        GL20TU_SHADOWMAP2D = 11,
        GL20TU_CUBEPROJECTION = 12,
+       // orthographic-projection shadowmapping, reuses prepass screenspace depth, so must fix later if the two could ever coexist during final deferred lighting pass
+       GL20TU_SHADOWMAPORTHORECT = 13,
+       GL20TU_SHADOWMAPORTHO2D = 13,
        // rtlight prepass data (screenspace depth and normalmap)
        GL20TU_SCREENDEPTH = 13,
        GL20TU_SCREENNORMALMAP = 14,