]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
shadowmap projection fixes
authoreihrul <eihrul@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 30 Sep 2009 15:26:55 +0000 (15:26 +0000)
committereihrul <eihrul@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 30 Sep 2009 15:26:55 +0000 (15:26 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9264 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
gl_textures.c
r_shadow.c
r_textures.h

index 72f8c7d51c4f737a5f65c4c516a3cf2149672026..54159c25531e183819966e955defdb57b299597b 100644 (file)
@@ -912,11 +912,6 @@ static const char *builtinshaderstring =
 "{\n"
 "      vec3 adir = abs(dir);\n"
 "# ifndef USESHADOWMAPVSDCT\n"
-"#  ifdef USESHADOWMAPRECT\n"
-"#   define cubedir(dx, dy, ox, oy) { tc = vec2(dx, dy); offset = vec2(ox, oy); }\n"
-"#  else\n"
-"#   define cubedir(dx, dy, ox, oy) { tc = vec2(dx, dy); offset = vec2(ox/2.0, oy/4.0); }\n"
-"#  endif\n"
 "      vec2 tc;\n"
 "      vec2 offset;\n"
 "      float ma;\n"
@@ -925,14 +920,14 @@ static const char *builtinshaderstring =
 "              if (adir.x > adir.z)\n"
 "              {\n"
 "                      ma = adir.x;\n"
-"                      if (dir.x >= 0.0) cubedir(-dir.z, -dir.y, 0.5, 0.5) // +X\n"
-"                      else              cubedir( dir.z, -dir.y, 1.5, 0.5) // -X\n"
+"                      if (dir.x >= 0.0) { tc = vec2(-dir.z, -dir.y); offset = vec2(0.5, 0.5); } // +X\n"
+"                      else              { tc = vec2( dir.z, -dir.y); offset = vec2(1.5, 0.5); } // -X\n"
 "              }\n"
 "              else\n"
 "              {\n"
 "                      ma = adir.z;\n"
-"                      if (dir.z >= 0.0) cubedir( dir.x, -dir.y, 0.5, 2.5) // +Z\n"
-"                      else              cubedir(-dir.x, -dir.y, 1.5, 2.5) // -Z\n"
+"                      if (dir.z >= 0.0) { tc = vec2( dir.x, -dir.y); offset = vec2(0.5, 2.5); } // +Z\n"
+"                      else              { tc = vec2(-dir.x, -dir.y); offset = vec2(1.5, 2.5); } // -Z\n"
 "              }\n"
 "      }\n"
 "      else\n"
@@ -940,28 +935,22 @@ static const char *builtinshaderstring =
 "              if (adir.y > adir.z)\n"
 "              {\n"
 "                      ma = adir.y;\n"
-"                      if (dir.y >= 0.0) cubedir( dir.x,  dir.z, 0.5, 1.5) // +Y\n"
-"                      else              cubedir( dir.x, -dir.z, 1.5, 1.5) // -Y\n"
+"                      if (dir.y >= 0.0) { tc = vec2( dir.x,  dir.z); offset = vec2(0.5, 1.5); } // +Y\n"
+"                      else              { tc = vec2( dir.x, -dir.z); offset = vec2(1.5, 1.5); } // -Y\n"
 "              }\n"
 "              else\n"
 "              {\n"
 "                      ma = adir.z;\n"
-"                      if (dir.z >= 0.0) cubedir( dir.x, -dir.y, 0.5, 2.5) // +Z\n"
-"                      else              cubedir(-dir.x, -dir.y, 1.5, 2.5) // -Z\n"
+"                      if (dir.z >= 0.0) { tc = vec2( dir.x, -dir.y); offset = vec2(0.5, 2.5); } // +Z\n"
+"                      else              { tc = vec2(-dir.x, -dir.y); offset = vec2(1.5, 2.5); } // -Z\n"
 "              }\n"
 "      }\n"
 "\n"
-"#  ifdef USESHADOWMAPRECT\n"
-"      return vec3(tc * ShadowMap_Parameters.x, ShadowMap_Parameters.w) / ma + vec3(offset * ShadowMap_Parameters.y, ShadowMap_Parameters.z);\n"
-"#  else\n"
-"      return vec3(tc * ShadowMap_Parameters.xy, ShadowMap_Parameters.w) / ma + vec3(offset, ShadowMap_Parameters.z);\n"
-"#  endif\n"
+"      vec3 stc = vec3(tc * ShadowMap_Parameters.x, ShadowMap_Parameters.w) / ma + vec3(offset * ShadowMap_Parameters.y, ShadowMap_Parameters.z);\n"
+"      stc.xy *= ShadowMap_TextureScale.xy;\n"
+"      return stc;\n"
 "# else\n"
-"#  ifdef USESHADOWMAPRECT \n"
-"    return vec3(textureCube(Texture_CubeProjection, dir.xyz).ra * ShadowMap_TextureScale.xy, ShadowMap_Parameters.z + ShadowMap_Parameters.w / max(max(adir.x, adir.y), adir.z));\n"
-"#  else\n"
-"    return vec3(textureCube(Texture_CubeProjection, dir.xyz).ra, ShadowMap_Parameters.z + ShadowMap_Parameters.w / max(max(adir.x, adir.y), adir.z));\n"
-"#  endif\n"
+"      return vec3(textureCube(Texture_CubeProjection, dir.xyz).ra * ShadowMap_Parameters.xy, ShadowMap_Parameters.z + ShadowMap_Parameters.w / max(max(adir.x, adir.y), adir.z));\n"
 "# endif\n"
 "}\n"
 "#endif // defined(USESHADOWMAPRECT) || defined(USESHADOWMAP2D)\n"
index e5b084fe033d88ed202a8ccbec6e8ee1c3218a46..3f9a3ba6527ed8066ccd0b47868323308064fcd2 100644 (file)
@@ -1147,7 +1147,7 @@ rtexture_t *R_LoadTextureShadowMapCube(rtexturepool_t *rtexturepool, const char
     return R_SetupTexture(rtexturepool, identifier, width, width, 1, 6, TEXF_ALWAYSPRECACHE | TEXF_CLAMP | (filter ? TEXF_FORCELINEAR | TEXF_COMPARE : TEXF_FORCENEAREST), TEXTYPE_SHADOWMAP, GLTEXTURETYPE_CUBEMAP, NULL, NULL);
 }
 
-rtexture_t *R_LoadTextureCubeProjection(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int size, int border)
+rtexture_t *R_LoadTextureCubeProjection(rtexturepool_t *rtexturepool, const char *identifier, int size, int border)
 {
     // maps to a 2x3 texture rectangle with normalized coordinates (must be scaled by size after lookup)
     // +-
@@ -1171,8 +1171,8 @@ rtexture_t *R_LoadTextureCubeProjection(rtexturepool_t *rtexturepool, const char
                {
                        for (k = 0;k < res;k++)
                        {
-                               *texel++ = (x + ((2*k + 1)<<stepbits))/width;
-                               *texel++ = (y + ((2*j + 1)<<stepbits))/height;
+                               *texel++ = (x + ((2*k + 1)<<stepbits))/2;
+                               *texel++ = (y + ((2*j + 1)<<stepbits))/3;
                        }
                }
        }
index 8151870717d2e1d8d039313d09ebb3ed7875acaf..55cb1683b88f1b21b433fa41250f788ecc6f7cc1 100644 (file)
@@ -1493,7 +1493,7 @@ void R_Shadow_RenderMode_ShadowMap(int side, qboolean clear, int size)
        {
                // complex unrolled cube approach (more flexible)
                if (r_shadow_shadowmapvsdct && !r_shadow_shadowmapcubeprojectiontexture[r_shadow_shadowmaplod])
-                       r_shadow_shadowmapcubeprojectiontexture[r_shadow_shadowmaplod] = R_LoadTextureCubeProjection(r_shadow_texturepool, "shadowmapcubeprojection", 2, 4, size, r_shadow_shadowmapborder);
+                       r_shadow_shadowmapcubeprojectiontexture[r_shadow_shadowmaplod] = R_LoadTextureCubeProjection(r_shadow_texturepool, "shadowmapcubeprojection", size, r_shadow_shadowmapborder);
                if (!r_shadow_shadowmap2dtexture)
                {
 #if 1
@@ -1527,15 +1527,15 @@ void R_Shadow_RenderMode_ShadowMap(int side, qboolean clear, int size)
                R_Viewport_InitRectSideView(&viewport, &rsurface.rtlight->matrix_lighttoworld, side, size, r_shadow_shadowmapping_bordersize.integer, nearclip, farclip, NULL);
                r_shadow_shadowmap_texturescale[0] = 1.0f / R_TextureWidth(r_shadow_shadowmap2dtexture);
                r_shadow_shadowmap_texturescale[1] = 1.0f / R_TextureHeight(r_shadow_shadowmap2dtexture);
-               r_shadow_shadowmap_parameters[0] = (0.5f / 2) * (1.0f - r_shadow_shadowmapborder / (float)size);
-               r_shadow_shadowmap_parameters[1] = (0.5f / 4) * (1.0f - r_shadow_shadowmapborder / (float)size);
+               r_shadow_shadowmap_parameters[0] = r_shadow_shadowmapvsdct ? size / (float)maxsize : 0.5f * (size - r_shadow_shadowmapborder);
+               r_shadow_shadowmap_parameters[1] = r_shadow_shadowmapvsdct ? 0.75f * size / (float)maxsize : size;
                r_shadow_rendermode = R_SHADOW_RENDERMODE_SHADOWMAP2D;
        }
        else if (r_shadow_shadowmode == 2)
        {
                // complex unrolled cube approach (more flexible)
                if (r_shadow_shadowmapvsdct && !r_shadow_shadowmapcubeprojectiontexture[r_shadow_shadowmaplod])
-                       r_shadow_shadowmapcubeprojectiontexture[r_shadow_shadowmaplod] = R_LoadTextureCubeProjection(r_shadow_texturepool, "shadowmapcubeprojection", 2, 3, size, r_shadow_shadowmapborder);
+                       r_shadow_shadowmapcubeprojectiontexture[r_shadow_shadowmaplod] = R_LoadTextureCubeProjection(r_shadow_texturepool, "shadowmapcubeprojection", size, r_shadow_shadowmapborder);
                if (!r_shadow_shadowmaprectangletexture)
                {
 #if 1
@@ -1567,10 +1567,10 @@ void R_Shadow_RenderMode_ShadowMap(int side, qboolean clear, int size)
                        qglClearColor(1,1,1,1);CHECKGLERROR
                }
                R_Viewport_InitRectSideView(&viewport, &rsurface.rtlight->matrix_lighttoworld, side, size, r_shadow_shadowmapborder, nearclip, farclip, NULL);
-               r_shadow_shadowmap_texturescale[0] = 2*size;
-               r_shadow_shadowmap_texturescale[1] = 3*size;
-               r_shadow_shadowmap_parameters[0] = 0.5f * (size - r_shadow_shadowmapborder);
-               r_shadow_shadowmap_parameters[1] = size;
+               r_shadow_shadowmap_texturescale[0] = 1.0f;
+               r_shadow_shadowmap_texturescale[1] = 1.0f;
+               r_shadow_shadowmap_parameters[0] = r_shadow_shadowmapvsdct ? 2*size : 0.5f * (size - r_shadow_shadowmapborder);
+               r_shadow_shadowmap_parameters[1] = r_shadow_shadowmapvsdct ? 3*size : size;
                r_shadow_rendermode = R_SHADOW_RENDERMODE_SHADOWMAPRECTANGLE;
        }
        else if (r_shadow_shadowmode == 3)
@@ -3716,7 +3716,7 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                        if ((r_shadow_shadowmapping_maxsize.integer >> i) > lodlinear)
                                r_shadow_shadowmaplod = i;
 
-               size = r_shadow_shadowmapvsdct || r_shadow_shadowmode ? r_shadow_shadowmapping_maxsize.integer >> r_shadow_shadowmaplod : lodlinear;
+               size = r_shadow_shadowmapvsdct || r_shadow_shadowmode == 3 ? r_shadow_shadowmapping_maxsize.integer >> r_shadow_shadowmaplod : lodlinear;
                size = bound(1, size, 2048);
 
                //Con_Printf("distance %f lodlinear %i (lod %i) size %i\n", distance, lodlinear, r_shadow_shadowmaplod, size);
index 3cb7f8381b883c9c97996b02d3c89a8196eb82b2..55adebc5278576253cb05d67da81a9cbc2acc88b 100644 (file)
@@ -86,7 +86,7 @@ rtexture_t *R_LoadTextureCubeMap(rtexturepool_t *rtexturepool, const char *ident
 rtexture_t *R_LoadTextureShadowMapRectangle(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, qboolean filter);
 rtexture_t *R_LoadTextureShadowMap2D(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, qboolean filter);
 rtexture_t *R_LoadTextureShadowMapCube(rtexturepool_t *rtexturepool, const char *identifier, int width, qboolean filter);
-rtexture_t *R_LoadTextureCubeProjection(rtexturepool_t *rtexturepool, const char *identifier, int width, int height, int size, int border);
+rtexture_t *R_LoadTextureCubeProjection(rtexturepool_t *rtexturepool, const char *identifier, int size, int border);
 
 // free a texture
 void R_FreeTexture(rtexture_t *rt);