mirror of
https://github.com/UberGames/lilium-voyager.git
synced 2024-11-10 06:31:47 +00:00
OpenGL2: "Fix" cg_shadows 4.
This commit is contained in:
parent
6a77f4e363
commit
6f1712dafe
5 changed files with 29 additions and 50 deletions
|
@ -8,12 +8,6 @@ uniform float u_LightRadius;
|
|||
varying vec3 var_Position;
|
||||
varying vec3 var_Normal;
|
||||
|
||||
float sampleDistMap(sampler2D texMap, vec2 uv, float scale)
|
||||
{
|
||||
vec3 distv = texture2D(texMap, uv).xyz;
|
||||
return dot(distv, vec3(1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0)) * scale;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightToPos = var_Position - u_LightOrigin.xyz;
|
||||
|
@ -57,42 +51,28 @@ void main()
|
|||
#endif
|
||||
|
||||
intensity *= fade;
|
||||
#if defined(USE_PCF)
|
||||
|
||||
float part;
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, -1.0/512.0), u_LightRadius);
|
||||
part = max(sign(lightDist - dist), 0.0);
|
||||
#if defined(USE_PCF)
|
||||
part = float(texture2D(u_ShadowMap, st + vec2(-1.0/512.0, -1.0/512.0)).r != 1.0);
|
||||
part += float(texture2D(u_ShadowMap, st + vec2( 1.0/512.0, -1.0/512.0)).r != 1.0);
|
||||
part += float(texture2D(u_ShadowMap, st + vec2(-1.0/512.0, 1.0/512.0)).r != 1.0);
|
||||
part += float(texture2D(u_ShadowMap, st + vec2( 1.0/512.0, 1.0/512.0)).r != 1.0);
|
||||
#else
|
||||
part = float(texture2D(u_ShadowMap, st).r != 1.0);
|
||||
#endif
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, -1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2(-1.0/512.0, 1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
dist = sampleDistMap(u_ShadowMap, st + vec2( 1.0/512.0, 1.0/512.0), u_LightRadius);
|
||||
part += max(sign(lightDist - dist), 0.0);
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (part <= 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_PCF)
|
||||
intensity *= part * 0.25;
|
||||
#else
|
||||
dist = sampleDistMap(u_ShadowMap, st, u_LightRadius);
|
||||
|
||||
#if defined(USE_DISCARD)
|
||||
if (lightDist - dist <= 0.0)
|
||||
{
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
intensity *= max(sign(lightDist - dist), 0.0);
|
||||
intensity *= part;
|
||||
#endif
|
||||
|
||||
|
||||
gl_FragColor.rgb = vec3(0);
|
||||
gl_FragColor.a = clamp(intensity, 0.0, 0.75);
|
||||
}
|
||||
|
|
|
@ -1604,26 +1604,26 @@ const void *RB_PostProcess(const void *data)
|
|||
if (0 && r_sunlightMode->integer)
|
||||
{
|
||||
ivec4_t dstBox;
|
||||
VectorSet4(dstBox, 0, 0, 128, 128);
|
||||
VectorSet4(dstBox, 0, glConfig.vidHeight - 128, 128, 128);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 128, 0, 128, 128);
|
||||
VectorSet4(dstBox, 128, glConfig.vidHeight - 128, 128, 128);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 256, 0, 128, 128);
|
||||
VectorSet4(dstBox, 256, glConfig.vidHeight - 128, 128, 128);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 384, 0, 128, 128);
|
||||
VectorSet4(dstBox, 384, glConfig.vidHeight - 128, 128, 128);
|
||||
FBO_BlitFromTexture(tr.sunShadowDepthImage[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
if (0 && r_shadows->integer == 4)
|
||||
if (1 && r_shadows->integer == 4)
|
||||
{
|
||||
ivec4_t dstBox;
|
||||
VectorSet4(dstBox, 0, glConfig.vidHeight - 128, 128, 128);
|
||||
VectorSet4(dstBox, 512 + 0, glConfig.vidHeight - 128, 128, 128);
|
||||
FBO_BlitFromTexture(tr.pshadowMaps[0], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 128, glConfig.vidHeight - 128, 128, 128);
|
||||
VectorSet4(dstBox, 512 + 128, glConfig.vidHeight - 128, 128, 128);
|
||||
FBO_BlitFromTexture(tr.pshadowMaps[1], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 256, glConfig.vidHeight - 128, 128, 128);
|
||||
VectorSet4(dstBox, 512 + 256, glConfig.vidHeight - 128, 128, 128);
|
||||
FBO_BlitFromTexture(tr.pshadowMaps[2], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
VectorSet4(dstBox, 384, glConfig.vidHeight - 128, 128, 128);
|
||||
VectorSet4(dstBox, 512 + 384, glConfig.vidHeight - 128, 128, 128);
|
||||
FBO_BlitFromTexture(tr.pshadowMaps[3], NULL, NULL, NULL, dstBox, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -322,14 +322,14 @@ void FBO_Init(void)
|
|||
R_CheckFBO(tr.sunRaysFbo);
|
||||
}
|
||||
|
||||
// FIXME: Don't use separate color/depth buffers for a shadow buffer
|
||||
if (MAX_DRAWN_PSHADOWS && tr.pshadowMaps[0])
|
||||
{
|
||||
for( i = 0; i < MAX_DRAWN_PSHADOWS; i++)
|
||||
{
|
||||
tr.pshadowFbos[i] = FBO_Create(va("_shadowmap%d", i), tr.pshadowMaps[i]->width, tr.pshadowMaps[i]->height);
|
||||
FBO_AttachImage(tr.pshadowFbos[i], tr.pshadowMaps[i], GL_COLOR_ATTACHMENT0, 0);
|
||||
FBO_CreateBuffer(tr.pshadowFbos[i], GL_DEPTH_COMPONENT24_ARB, 0, 0);
|
||||
// FIXME: this next line wastes 16mb with 16x512x512 sun shadow maps, skip if OpenGL 4.3+ or ARB_framebuffer_no_attachments
|
||||
FBO_CreateBuffer(tr.pshadowFbos[i], GL_RGBA8, 0, 0);
|
||||
FBO_AttachImage(tr.pshadowFbos[i], tr.pshadowMaps[i], GL_DEPTH_ATTACHMENT, 0);
|
||||
R_CheckFBO(tr.pshadowFbos[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2808,12 +2808,11 @@ void R_CreateBuiltinImages( void ) {
|
|||
tr.screenSsaoImage = R_CreateImage("*screenSsao", NULL, width / 2, height / 2, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
|
||||
}
|
||||
|
||||
if (r_shadows->integer == 4)
|
||||
for( x = 0; x < MAX_DRAWN_PSHADOWS; x++)
|
||||
{
|
||||
for( x = 0; x < MAX_DRAWN_PSHADOWS; x++)
|
||||
{
|
||||
tr.pshadowMaps[x] = R_CreateImage(va("*shadowmap%i", x), NULL, PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
|
||||
}
|
||||
tr.pshadowMaps[x] = R_CreateImage(va("*shadowmap%i", x), NULL, PSHADOW_MAP_SIZE, PSHADOW_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24);
|
||||
//qglTextureParameterfEXT(tr.pshadowMaps[x]->texnum, GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||
//qglTextureParameterfEXT(tr.pshadowMaps[x]->texnum, GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
|
||||
}
|
||||
|
||||
if (r_sunlightMode->integer)
|
||||
|
|
|
@ -2098,7 +2098,7 @@ void R_RenderPshadowMaps(const refdef_t *fd)
|
|||
if (glRefConfig.framebufferObject)
|
||||
shadowParms.targetFbo = tr.pshadowFbos[i];
|
||||
|
||||
shadowParms.flags = VPF_SHADOWMAP | VPF_DEPTHSHADOW | VPF_NOVIEWMODEL;
|
||||
shadowParms.flags = VPF_DEPTHSHADOW | VPF_NOVIEWMODEL;
|
||||
shadowParms.zFar = shadow->lightRadius;
|
||||
|
||||
VectorCopy(shadow->lightOrigin, shadowParms.or.origin);
|
||||
|
|
Loading…
Reference in a new issue