"{\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"
" 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"
" 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"
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)
// +-
{
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;
}
}
}
{
// 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
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
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)
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);
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);