- Added .mtr file support. .mtr files are just .shader files that are accessed first.

- Added support for q3gl2_sun shaderparm in sky shaders to control sun shadows
- Added r_shadowFilter 0/1/2 for cascaded shadow maps.
- Added sun shadow support cvars.
- Changed r_testSunlight to r_forceSun 0/1/2 and r_sunShadows 0/1.
This commit is contained in:
James Canete 2012-10-17 10:02:11 +00:00
parent 4f57e94d05
commit 982eab2003
17 changed files with 4002 additions and 3597 deletions

View file

@ -1,3 +1,8 @@
- Added .mtr file support. .mtr files are just .shader files that are accessed first.
- Added support for q3gl2_sun shaderparm in sky shaders to control sun shadows
- Added r_shadowFilter 0/1/2 for cascaded shadow maps.
- Added sun shadow support cvars.
- Changed r_testSunlight to r_forceSun 0/1/2 and r_sunShadows 0/1.
- Spread in automatic weapons should be reduced in 3 burst mode.
- Updated the ioq3 base Reaction is based on to ioq3 svn version 2322
- Scale map lights by 0.66 and sunlight by 0.33 when r_testSunlight 1

View file

@ -129,11 +129,15 @@ void GL_BindToTMU( image_t *image, int tmu )
int texnum;
int oldtmu = glState.currenttmu;
texnum = image->texnum;
if (!image)
texnum = 0;
else
texnum = image->texnum;
if ( glState.currenttextures[tmu] != texnum ) {
GL_SelectTexture( tmu );
image->frameUsed = tr.frameCount;
if (image)
image->frameUsed = tr.frameCount;
glState.currenttextures[tmu] = texnum;
qglBindTexture( GL_TEXTURE_2D, texnum );
GL_SelectTexture( oldtmu );
@ -582,7 +586,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
FBO_t* fbo = NULL;
qboolean inQuery = qfalse;
#ifdef REACTION
#if 1 //def REACTION
float depth[2];
#endif
@ -604,7 +608,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
oldSort = -1;
depthRange = qfalse;
#ifdef REACTION
#if 1 //def REACTION
depth[0] = 0.f;
depth[1] = 1.f;
#endif
@ -754,7 +758,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
}
}
#ifdef REACTION
#if 1 //def REACTION
if(!oldDepthRange)
{
depth[0] = 0;
@ -772,7 +776,7 @@ void RB_RenderDrawSurfList( drawSurf_t *drawSurfs, int numDrawSurfs ) {
if (!sunflare)
qglDepthRange (0, 1);
#ifdef REACTION
#if 1 //def REACTION
depth[0] = 0;
depth[1] = 1;
#endif
@ -876,6 +880,9 @@ void RB_SetGL2D (void) {
// set time for 2D shaders
backEnd.refdef.time = ri.Milliseconds();
backEnd.refdef.floatTime = backEnd.refdef.time * 0.001f;
// reset color scaling
backEnd.refdef.colorScale = 1.0f;
}
@ -1198,6 +1205,72 @@ const void *RB_DrawSurfs( const void *data ) {
RB_RenderDrawSurfList( cmd->drawSurfs, cmd->numDrawSurfs );
qglColorMask(!backEnd.colorMask[0], !backEnd.colorMask[1], !backEnd.colorMask[2], !backEnd.colorMask[3]);
backEnd.depthFill = qfalse;
if (backEnd.viewParms.flags & VPF_USESUNLIGHT)
{
vec4_t quadVerts[4];
vec2_t texCoords[4];
FBO_t *oldFbo = glState.currentFBO;
// If we're using multisampling, resolve the depth first
if (tr.msaaResolveFbo)
{
FBO_FastBlit(tr.renderFbo, NULL, tr.msaaResolveFbo, NULL, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
}
FBO_Bind(tr.screenShadowFbo);
VectorSet4(quadVerts[0], -1, 1, 0, 1);
VectorSet4(quadVerts[1], 1, 1, 0, 1);
VectorSet4(quadVerts[2], 1, -1, 0, 1);
VectorSet4(quadVerts[3], -1, -1, 0, 1);
texCoords[0][0] = 0; texCoords[0][1] = 1;
texCoords[1][0] = 1; texCoords[1][1] = 1;
texCoords[2][0] = 1; texCoords[2][1] = 0;
texCoords[3][0] = 0; texCoords[3][1] = 0;
GL_State( GLS_DEPTHTEST_DISABLE );
GLSL_BindProgram(&tr.shadowmaskShader);
GL_BindToTMU(tr.renderDepthImage, TB_COLORMAP);
GL_BindToTMU(tr.sunShadowDepthImage[0], TB_SHADOWMAP);
GL_BindToTMU(tr.sunShadowDepthImage[1], TB_SHADOWMAP2);
GL_BindToTMU(tr.sunShadowDepthImage[2], TB_SHADOWMAP3);
GLSL_SetUniformMatrix16(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMVP, backEnd.refdef.sunShadowMvp[0]);
GLSL_SetUniformMatrix16(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMVP2, backEnd.refdef.sunShadowMvp[1]);
GLSL_SetUniformMatrix16(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMVP3, backEnd.refdef.sunShadowMvp[2]);
GLSL_SetUniformVec3(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWORIGIN, backEnd.refdef.vieworg);
{
vec4_t viewInfo;
vec3_t viewVector;
float zmax = backEnd.viewParms.zFar;
float ymax = zmax * tan(backEnd.viewParms.fovY * M_PI / 360.0f);
float xmax = zmax * tan(backEnd.viewParms.fovX * M_PI / 360.0f);
float zmin = r_znear->value;
VectorScale(backEnd.refdef.viewaxis[0], zmax, viewVector);
GLSL_SetUniformVec3(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWFORWARD, viewVector);
VectorScale(backEnd.refdef.viewaxis[1], xmax, viewVector);
GLSL_SetUniformVec3(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWLEFT, viewVector);
VectorScale(backEnd.refdef.viewaxis[2], ymax, viewVector);
GLSL_SetUniformVec3(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWUP, viewVector);
VectorSet4(viewInfo, zmax / zmin, zmax, 0.0, 0.0);
GLSL_SetUniformVec4(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWINFO, viewInfo);
}
RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes);
FBO_Bind(oldFbo);
}
}
if ((backEnd.viewParms.flags & VPF_DEPTHCLAMP) && glRefConfig.depthClamp)
@ -1556,6 +1629,15 @@ const void *RB_PostProcess(const void *data)
FBO_BlitFromTexture(tr.sunShadowDepthImage[2], NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
}
if (0)
{
vec4i_t dstBox;
VectorSet4(dstBox, 256, tr.screenScratchFbo->height - 256, 256, 256);
FBO_BlitFromTexture(tr.renderDepthImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
VectorSet4(dstBox, 512, tr.screenScratchFbo->height - 256, 256, 256);
FBO_BlitFromTexture(tr.screenShadowImage, NULL, NULL, tr.screenScratchFbo, dstBox, NULL, NULL, 0);
}
backEnd.framePostProcessed = qtrue;
return (const void *)(cmd + 1);

View file

@ -107,14 +107,53 @@ void Matrix16Translation( vec3_t vec, matrix_t out )
void Matrix16Ortho( float left, float right, float bottom, float top, float znear, float zfar, matrix_t out )
{
Matrix16Zero(out);
out[ 0] = 2.0f / (right - left);
out[ 5] = 2.0f / (top - bottom);
out[10] = 2.0f / (zfar - znear);
out[12] = -(right + left) / (right - left);
out[13] = -(top + bottom) / (top - bottom);
out[14] = -(zfar + znear) / (zfar - znear);
out[15] = 1.0f;
out[ 0] = 2.0f / (right - left); out[ 4] = 0.0f; out[ 8] = 0.0f; out[12] = -(right + left) / (right - left);
out[ 1] = 0.0f; out[ 5] = 2.0f / (top - bottom); out[ 9] = 0.0f; out[13] = -(top + bottom) / (top - bottom);
out[ 2] = 0.0f; out[ 6] = 0.0f; out[10] = 2.0f / (zfar - znear); out[14] = -(zfar + znear) / (zfar - znear);
out[ 3] = 0.0f; out[ 7] = 0.0f; out[11] = 0.0f; out[15] = 1.0f;
}
void Matrix16View(vec3_t axes[3], vec3_t origin, matrix_t out)
{
out[0] = axes[0][0];
out[1] = axes[1][0];
out[2] = axes[2][0];
out[3] = 0;
out[4] = axes[0][1];
out[5] = axes[1][1];
out[6] = axes[2][1];
out[7] = 0;
out[8] = axes[0][2];
out[9] = axes[1][2];
out[10] = axes[2][2];
out[11] = 0;
out[12] = -DotProduct(origin, axes[0]);
out[13] = -DotProduct(origin, axes[1]);
out[14] = -DotProduct(origin, axes[2]);
out[15] = 1;
}
void Matrix16SimpleInverse( const matrix_t in, matrix_t out)
{
vec3_t v;
float invSqrLen;
VectorCopy(in + 0, v);
invSqrLen = 1.0f / DotProduct(v, v); VectorScale(v, invSqrLen, v);
out[ 0] = v[0]; out[ 4] = v[1]; out[ 8] = v[2]; out[12] = -DotProduct(v, &in[12]);
VectorCopy(in + 4, v);
invSqrLen = 1.0f / DotProduct(v, v); VectorScale(v, invSqrLen, v);
out[ 1] = v[0]; out[ 5] = v[1]; out[ 9] = v[2]; out[13] = -DotProduct(v, &in[12]);
VectorCopy(in + 8, v);
invSqrLen = 1.0f / DotProduct(v, v); VectorScale(v, invSqrLen, v);
out[ 2] = v[0]; out[ 6] = v[1]; out[10] = v[2]; out[14] = -DotProduct(v, &in[12]);
out[ 3] = 0.0f; out[ 7] = 0.0f; out[11] = 0.0f; out[15] = 1.0f;
}
void VectorLerp( vec3_t a, vec3_t b, float lerp, vec3_t c)

View file

@ -38,6 +38,8 @@ qboolean Matrix16Compare(const matrix_t a, const matrix_t b);
void Matrix16Dump( const matrix_t in );
void Matrix16Translation( vec3_t vec, matrix_t out );
void Matrix16Ortho( float left, float right, float bottom, float top, float znear, float zfar, matrix_t out );
void Matrix16View(vec3_t axes[3], vec3_t origin, matrix_t out);
void Matrix16SimpleInverse( const matrix_t in, matrix_t out);
#define VectorCopy2(a,b) ((b)[0]=(a)[0],(b)[1]=(a)[1])

View file

@ -37,6 +37,7 @@ typedef struct {
float blurFactor;
float sunDir[3];
float sunCol[3];
float sunAmbCol[3];
} refdefex_t;
#endif

View file

@ -483,9 +483,10 @@ void FBO_Init(void)
tr.sunShadowFbo[i] = FBO_Create("_sunshadowmap", tr.sunShadowDepthImage[i]->width, tr.sunShadowDepthImage[i]->height);
FBO_Bind(tr.sunShadowFbo[i]);
//FBO_CreateBuffer(tr.pshadowFbos[i], GL_RGBA8, 0, 0);
//FBO_CreateBuffer(tr.sunShadowFbo[i], GL_RGBA8, 0, 0);
//FBO_AttachTextureImage(tr.sunShadowImage, 0);
qglDrawBuffer(GL_NONE);
qglReadBuffer(GL_NONE);
//FBO_CreateBuffer(tr.sunShadowFbo, GL_DEPTH_COMPONENT24_ARB, 0, 0);
R_AttachFBOTextureDepth(tr.sunShadowDepthImage[i]->texnum);
@ -550,6 +551,15 @@ void FBO_Init(void)
R_CheckFBO(tr.quarterFbo[i]);
}
{
tr.screenShadowFbo = FBO_Create("_screenshadow", tr.screenShadowImage->width, tr.screenShadowImage->height);
FBO_Bind(tr.screenShadowFbo);
FBO_AttachTextureImage(tr.screenShadowImage, 0);
R_CheckFBO(tr.screenShadowFbo);
}
GL_CheckErrors();
FBO_Bind(NULL);
@ -719,7 +729,14 @@ void FBO_BlitFromTexture(struct image_s *src, vec4i_t inSrcBox, vec2_t inSrcTexS
GL_State( blend );
RB_InstantQuad2(quadVerts, texCoords, color, shaderProgram, invTexRes);
GLSL_BindProgram(shaderProgram);
GLSL_SetUniformMatrix16(shaderProgram, TEXTURECOLOR_UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
GLSL_SetUniformVec4(shaderProgram, TEXTURECOLOR_UNIFORM_COLOR, color);
GLSL_SetUniformVec2(shaderProgram, TEXTURECOLOR_UNIFORM_INVTEXRES, invTexRes);
GLSL_SetUniformVec2(shaderProgram, TEXTURECOLOR_UNIFORM_AUTOEXPOSUREMINMAX, tr.autoExposureMinMax);
RB_InstantQuad2(quadVerts, texCoords); //, color, shaderProgram, invTexRes);
}
void FBO_Blit(FBO_t *src, vec4i_t inSrcBox, vec2_t srcTexScale, FBO_t *dst, vec4i_t dstBox, struct shaderProgram_s *shaderProgram, vec4_t color, int blend)

View file

@ -250,51 +250,52 @@ static const char *fallbackLightallShader_vp =
"itangent;\r\n#endif\r\n\r\n#if defined(USE_LIGHT_VECTOR) && defined(USE_FAS"
"T_LIGHT)\r\nvarying vec3 var_VectLight;\r\n#endif\r\n\r\n#if defined(USE_"
"LIGHT) && !defined(USE_DELUXEMAP)\r\nvarying vec3 var_WorldLight;\r\n#end"
"if\r\n\r\n\r\nvec2 DoTexMatrix(vec2 st, vec3 position, mat4 texMatrix)\r\n{"
"\r\n\tvec2 st2 = (texMatrix * vec4(st, 1, 0)).st;\r\n\r\n\tvec3 offsetPos ="
" position.xyz / 1024.0;\r\n\toffsetPos.x += offsetPos.z;\r\n\r\n\tvec2 texO"
"ffset = sin((offsetPos.xy + vec2(texMatrix[3][1])) * 2.0 * M_PI);\r\n\t\r\n"
"\treturn st2 + texOffset * texMatrix[3][0];\r\n}\r\n\r\nvoid main()\r\n{\r"
"\n#if defined(USE_VERTEX_ANIMATION)\r\n\tvec4 position = mix(attr_Position"
", attr_Position2, u_VertexLerp);\r\n\tvec3 normal = normalize(mix(attr_N"
"ormal, attr_Normal2, u_VertexLerp));\r\n #if defined(USE_VERT_TANGEN"
"T_SPACE)\r\n\tvec3 tangent = normalize(mix(attr_Tangent, attr_Tangent2,"
" u_VertexLerp));\r\n\tvec3 bitangent = normalize(mix(attr_Bitangent, attr"
"_Bitangent2, u_VertexLerp));\r\n #endif\r\n#else\r\n\tvec4 position = att"
"r_Position;\r\n\tvec3 normal = attr_Normal;\r\n #if defined(USE_VERT_TA"
"NGENT_SPACE)\r\n\tvec3 tangent = attr_Tangent;\r\n\tvec3 bitangent = attr"
"_Bitangent;\r\n #endif\r\n#endif\r\n\r\n\tgl_Position = u_ModelViewProject"
"ionMatrix * position;\r\n\r\n#if (defined(USE_LIGHTMAP) || defined(USE_LIGH"
"T_VERTEX)) && !defined(USE_DELUXEMAP)\r\n\tvec3 worldLight = attr_LightDire"
"ction;\r\n#endif\r\n\t\r\n#if defined(USE_MODELMATRIX)\r\n\tposition = u_M"
"odelMatrix * position;\r\n\tnormal = (u_ModelMatrix * vec4(normal, 0.0))"
".xyz;\r\n #if defined(USE_VERT_TANGENT_SPACE)\r\n\ttangent = (u_ModelMat"
"rix * vec4(tangent, 0.0)).xyz;\r\n\tbitangent = (u_ModelMatrix * vec4(bitan"
"gent, 0.0)).xyz;\r\n #endif\r\n\r\n #if defined(USE_LIGHTMAP) && !defined"
"(USE_DELUXEMAP)\r\n\tworldLight = (u_ModelMatrix * vec4(worldLight, 0.0)).x"
"yz;\r\n #endif\r\n#endif\r\n\r\n\tvar_Position = position.xyz;\r\n\r\n#if "
"defined(TCGEN_ENVIRONMENT) || defined(USE_NORMALMAP) || defined(USE_LIGHT) "
"&& !defined(USE_FAST_LIGHT)\r\n\tvec3 SampleToView = u_ViewOrigin - positio"
"n.xyz;\r\n#endif\r\n\r\n#if defined(USE_NORMALMAP) || defined(USE_LIGHT) &&"
" !defined(USE_FAST_LIGHT)\r\n\tvar_SampleToView = SampleToView;\r\n#endif\r"
"\n\r\n#if defined(TCGEN_ENVIRONMENT)\r\n\tvec3 viewer = normalize(SampleToV"
"iew);\r\n\tvec3 reflected = normal * 2.0 * dot(normal, viewer) - viewer;\r"
"\n\r\n\tvec2 tex = reflected.yz * vec2(0.5, -0.5) + 0.5;\r\n#else\r\n\tvec2"
" tex = attr_TexCoord0.st;\r\n#endif\r\n\r\n\tvar_DiffuseTex = DoTexMatrix(t"
"ex, position.xyz, u_DiffuseTexMatrix);\r\n\r\n#if defined(USE_LIGHTMAP)\r\n"
"\tvar_LightTex = attr_TexCoord1.st;\r\n#endif\r\n\r\n\tvar_Color = u_VertCo"
"lor * attr_Color + u_BaseColor;\r\n \r\n\tvar_Normal = normal;\r\n#if defi"
"ned(USE_VERT_TANGENT_SPACE)\r\n\tvar_Tangent = tangent;\r\n\tvar_Bitangent "
"= bitangent;\r\n#endif\r\n\r\n#if defined(USE_LIGHT) && !defined(USE_DELUXE"
"MAP)\r\n #if defined(USE_LIGHT_VECTOR)\r\n\tvec3 worldLight = u_LightOrigi"
"n.xyz - (position.xyz * u_LightOrigin.w);\r\n #endif\r\n\r\n\tworldLight +"
"= normal * 0.0001;\r\n\tvar_WorldLight = worldLight;\r\n#endif\r\n\r\n#if d"
"efined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)\r\n #if defined(USE_IN"
"VSQRLIGHT)\r\n\tfloat intensity = 1.0 / dot(worldLight, worldLight);\r\n #"
"else\r\n\tfloat intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_L"
"ightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #endif\r\n\tfloat NL ="
" clamp(dot(normal, normalize(worldLight)), 0.0, 1.0);\r\n\r\n\tvar_VectLigh"
"t = u_DirectedLight * intensity * NL + u_AmbientLight;\r\n#endif\r\n}\r\n";
"if\r\n\r\nvarying vec4 var_ScreenPos;\r\n\r\nvec2 DoTexMatrix(vec2 st, ve"
"c3 position, mat4 texMatrix)\r\n{\r\n\tvec2 st2 = (texMatrix * vec4(st, 1, "
"0)).st;\r\n\r\n\tvec3 offsetPos = position.xyz / 1024.0;\r\n\toffsetPos.x +"
"= offsetPos.z;\r\n\r\n\tvec2 texOffset = sin((offsetPos.xy + vec2(texMatrix"
"[3][1])) * 2.0 * M_PI);\r\n\t\r\n\treturn st2 + texOffset * texMatrix[3][0]"
";\r\n}\r\n\r\nvoid main()\r\n{\r\n#if defined(USE_VERTEX_ANIMATION)\r\n\tve"
"c4 position = mix(attr_Position, attr_Position2, u_VertexLerp);\r\n\tvec3 "
"normal = normalize(mix(attr_Normal, attr_Normal2, u_VertexLerp));"
"\r\n #if defined(USE_VERT_TANGENT_SPACE)\r\n\tvec3 tangent = normalize(m"
"ix(attr_Tangent, attr_Tangent2, u_VertexLerp));\r\n\tvec3 bitangent = n"
"ormalize(mix(attr_Bitangent, attr_Bitangent2, u_VertexLerp));\r\n #endif\r"
"\n#else\r\n\tvec4 position = attr_Position;\r\n\tvec3 normal = attr_Nor"
"mal;\r\n #if defined(USE_VERT_TANGENT_SPACE)\r\n\tvec3 tangent = attr_Ta"
"ngent;\r\n\tvec3 bitangent = attr_Bitangent;\r\n #endif\r\n#endif\r\n\r\n"
"\tgl_Position = u_ModelViewProjectionMatrix * position;\r\n\tvar_ScreenPos "
"= gl_Position;\r\n\r\n#if (defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTE"
"X)) && !defined(USE_DELUXEMAP)\r\n\tvec3 worldLight = attr_LightDirection;"
"\r\n#endif\r\n\t\r\n#if defined(USE_MODELMATRIX)\r\n\tposition = u_ModelMa"
"trix * position;\r\n\tnormal = (u_ModelMatrix * vec4(normal, 0.0)).xyz;"
"\r\n #if defined(USE_VERT_TANGENT_SPACE)\r\n\ttangent = (u_ModelMatrix *"
" vec4(tangent, 0.0)).xyz;\r\n\tbitangent = (u_ModelMatrix * vec4(bitangent,"
" 0.0)).xyz;\r\n #endif\r\n\r\n #if defined(USE_LIGHTMAP) && !defined(USE_"
"DELUXEMAP)\r\n\tworldLight = (u_ModelMatrix * vec4(worldLight, 0.0)).xyz;\r"
"\n #endif\r\n#endif\r\n\r\n\tvar_Position = position.xyz;\r\n\r\n#if defin"
"ed(TCGEN_ENVIRONMENT) || defined(USE_NORMALMAP) || defined(USE_LIGHT) && !d"
"efined(USE_FAST_LIGHT)\r\n\tvec3 SampleToView = u_ViewOrigin - position.xyz"
";\r\n#endif\r\n\r\n#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !def"
"ined(USE_FAST_LIGHT)\r\n\tvar_SampleToView = SampleToView;\r\n#endif\r\n\r"
"\n#if defined(TCGEN_ENVIRONMENT)\r\n\tvec3 viewer = normalize(SampleToView)"
";\r\n\tvec3 reflected = normal * 2.0 * dot(normal, viewer) - viewer;\r\n\r"
"\n\tvec2 tex = reflected.yz * vec2(0.5, -0.5) + 0.5;\r\n#else\r\n\tvec2 tex"
" = attr_TexCoord0.st;\r\n#endif\r\n\r\n\tvar_DiffuseTex = DoTexMatrix(tex, "
"position.xyz, u_DiffuseTexMatrix);\r\n\r\n#if defined(USE_LIGHTMAP)\r\n\tva"
"r_LightTex = attr_TexCoord1.st;\r\n#endif\r\n\r\n\tvar_Color = u_VertColor "
"* attr_Color + u_BaseColor;\r\n \r\n\tvar_Normal = normal;\r\n#if defined("
"USE_VERT_TANGENT_SPACE)\r\n\tvar_Tangent = tangent;\r\n\tvar_Bitangent = bi"
"tangent;\r\n#endif\r\n\r\n#if defined(USE_LIGHT) && !defined(USE_DELUXEMAP)"
"\r\n #if defined(USE_LIGHT_VECTOR)\r\n\tvec3 worldLight = u_LightOrigin.xy"
"z - (position.xyz * u_LightOrigin.w);\r\n #endif\r\n\r\n\tworldLight += no"
"rmal * 0.0001;\r\n\tvar_WorldLight = worldLight;\r\n#endif\r\n\r\n#if defin"
"ed(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)\r\n #if defined(USE_INVSQR"
"LIGHT)\r\n\tfloat intensity = 1.0 / dot(worldLight, worldLight);\r\n #else"
"\r\n\tfloat intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_Light"
"Radius * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #endif\r\n\tfloat NL = cla"
"mp(dot(normal, normalize(worldLight)), 0.0, 1.0);\r\n\r\n\tvar_VectLight = "
"u_DirectedLight * intensity * NL + u_AmbientLight;\r\n#endif\r\n}\r\n";
static const char *fallbackLightallShader_fp =
"uniform sampler2D u_DiffuseMap;\r\n\r\n#if defined(USE_LIGHTMAP)\r\nuniform"
@ -302,167 +303,137 @@ static const char *fallbackLightallShader_fp =
"rm sampler2D u_NormalMap;\r\n#endif\r\n\r\n#if defined(USE_DELUXEMAP)\r\nun"
"iform sampler2D u_DeluxeMap;\r\n#endif\r\n\r\n#if defined(USE_SPECULARMAP)"
"\r\nuniform sampler2D u_SpecularMap;\r\n#endif\r\n\r\n#if defined(USE_SHADO"
"WMAP)\r\nuniform sampler2D u_ShadowMap;\r\n #if defined(USE_SHADOW_CASCADE"
")\r\nuniform sampler2D u_ShadowMap2;\r\nuniform sampler2D u_ShadowMap3;\r\n"
" #endif\r\n#endif\r\n\r\nuniform vec3 u_ViewOrigin;\r\n\r\n#if define"
"d(USE_LIGHT_VECTOR)\r\nuniform vec3 u_DirectedLight;\r\nuniform vec3 "
" u_AmbientLight;\r\nuniform float u_LightRadius;\r\n#endif\r\n\r\n#i"
"f defined(USE_SHADOWMAP)\r\nuniform mat4 u_ShadowMvp;\r\n #if defined"
"(USE_SHADOW_CASCADE)\r\nuniform mat4 u_ShadowMvp2;\r\nuniform mat4 "
" u_ShadowMvp3;\r\n #endif\r\n#endif\r\n\r\n#if defined(USE_LIGHT)\r\nunif"
"orm vec2 u_MaterialInfo;\r\n#endif\r\n\r\n#if defined(USE_LIGHTMAP) ||"
" defined(USE_LIGHT_VERTEX)\r\nuniform float u_MapLightScale;\r\n#endif"
"\r\n\r\nvarying vec2 var_DiffuseTex;\r\n#if defined(USE_LIGHTMAP)\r\nv"
"arying vec2 var_LightTex;\r\n#endif\r\nvarying vec4 var_Color;\r"
"\nvarying vec3 var_Position;\r\n\r\nvarying vec3 var_SampleToView"
";\r\n\r\nvarying vec3 var_Normal;\r\n#if defined(USE_VERT_TANGENT_SPAC"
"E)\r\nvarying vec3 var_Tangent;\r\nvarying vec3 var_Bitangent;\r"
"\n#endif\r\n\r\n#if defined(USE_LIGHT_VECTOR) && defined(USE_FAST_LIGHT)\r"
"\nvarying vec3 var_VectLight;\r\n#endif\r\n\r\n#if defined(USE_LIGHT) "
"&& !defined(USE_DELUXEMAP)\r\nvarying vec3 var_WorldLight;\r\n#endif\r"
"\n\r\n#define EPSILON 0.00000001\r\n\r\n#if defined(USE_PARALLAXMAP)\r\nflo"
"at SampleHeight(sampler2D normalMap, vec2 t)\r\n{\r\n #if defined(SWIZZLE_"
"NORMALMAP)\r\n\treturn texture2D(normalMap, t).r;\r\n #else\r\n\treturn te"
"xture2D(normalMap, t).a;\r\n #endif\r\n}\r\n\r\nfloat RayIntersectDisplace"
"Map(vec2 dp, vec2 ds, sampler2D normalMap)\r\n{\r\n\tconst int linearSearch"
"Steps = 16;\r\n\tconst int binarySearchSteps = 6;\r\n\r\n\tfloat depthStep "
"= 1.0 / float(linearSearchSteps);\r\n\r\n\t// current size of search window"
"\r\n\tfloat size = depthStep;\r\n\r\n\t// current depth position\r\n\tfloat"
" depth = 0.0;\r\n\r\n\t// best match found (starts with last position 1.0)"
"\r\n\tfloat bestDepth = 1.0;\r\n\r\n\t// search front to back for first poi"
"nt inside object\r\n\tfor(int i = 0; i < linearSearchSteps - 1; ++i)\r\n\t{"
"\r\n\t\tdepth += size;\r\n\t\t\r\n\t\tfloat t = 1.0 - SampleHeight(normalMa"
"p, dp + ds * depth);\r\n\t\t\r\n\t\tif(bestDepth > 0.996)\t\t// if no depth"
" found yet\r\n\t\t\tif(depth >= t)\r\n\t\t\t\tbestDepth = depth;\t// store "
"best depth\r\n\t}\r\n\r\n\tdepth = bestDepth;\r\n\t\r\n\t// recurse around "
"first point (depth) for closest match\r\n\tfor(int i = 0; i < binarySearchS"
"teps; ++i)\r\n\t{\r\n\t\tsize *= 0.5;\r\n\r\n\t\tfloat t = 1.0 - SampleHeig"
"ht(normalMap, dp + ds * depth);\r\n\t\t\r\n\t\tif(depth >= t)\r\n\t\t{\r\n"
"\t\t\tbestDepth = depth;\r\n\t\t\tdepth -= 2.0 * size;\r\n\t\t}\r\n\r\n\t\t"
"depth += size;\r\n\t}\r\n\r\n\treturn bestDepth;\r\n}\r\n#endif\r\n\r\nfloa"
"t CalcDiffuse(vec3 N, vec3 L, vec3 E, float NE, float NL, float fzero, floa"
"t shininess)\r\n{\r\n #if defined(USE_OREN_NAYAR)\r\n\tfloat roughness = s"
"qrt(2.0 / max(shininess, EPSILON));\r\n\r\n\tfloat gamma = dot(E - N * NE, "
"L - N * NL);\r\n\tfloat r_sq = roughness * roughness;\r\n\r\n\tfloat A = 1."
"0 - 0.5 * (r_sq / (r_sq + 0.57));\r\n\tfloat B = 0.45 * (r_sq / (r_sq + 0.0"
"9));\r\n\r\n\tfloat alpha = max(acos(NE), acos(NL));\r\n\tfloat beta = min"
"(acos(NE), acos(NL));\r\n\r\n\tfloat C = sin(alpha) * tan(beta);\r\n\r\n\tr"
"eturn A + B * clamp(gamma, 0.0, 1.0) * C;\r\n #else\r\n\treturn 1.0 - fzer"
"o;\r\n #endif\r\n}\r\n\r\n#if defined(USE_SPECULARMAP)\r\nfloat CalcSpecul"
"ar(float NH, float NL, float NE, float EH, float fzero, float shininess)\r"
"\n{\r\n #if defined(USE_BLINN) || defined(USE_TRIACE) || defined(USE_TORRA"
"NCE_SPARROW)\r\n\tfloat blinn = pow(NH, shininess);\r\n #endif\r\n\r\n #i"
"f defined(USE_BLINN)\r\n\treturn blinn;\r\n #endif\r\n\r\n #if defined(US"
"E_COOK_TORRANCE) || defined (USE_TRIACE) || defined (USE_TORRANCE_SPARROW)"
"\r\n\tfloat fresnel = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r\n #endif"
"\r\n\r\n #if defined(USE_COOK_TORRANCE) || defined(USE_TORRANCE_SPARROW)\r"
"\n\tfloat geo = 2.0 * NH * min(NE, NL);\r\n\tgeo /= max(EH, geo);\r\n #end"
"if \r\n\r\n #if defined(USE_COOK_TORRANCE)\r\n\tfloat m = sqrt(2.0 / max("
"shininess, EPSILON));\r\n\r\n\tfloat m_sq = m * m;\r\n\tfloat NH_sq = NH * "
"NH;\r\n\tfloat beckmann = exp((NH_sq - 1.0) / max(m_sq * NH_sq, EPSILON)) /"
" max(4.0 * m_sq * NH_sq * NH_sq, EPSILON);\r\n\r\n\treturn fresnel * geo * "
"beckmann / max(NE, EPSILON);\r\n #endif\r\n\r\n #if defined(USE_TRIACE)\r"
"\n\tfloat scale = 0.1248582 * shininess + 0.2691817;\r\n\r\n\treturn fresne"
"l * scale * blinn / max(max(NL, NE), EPSILON);\r\n #endif\r\n \r\n #if d"
"efined(USE_TORRANCE_SPARROW)\r\n\tfloat scale = 0.125 * shininess + 1.0;\r"
"\n\r\n\treturn fresnel * geo * scale * blinn / max(NE, EPSILON);\r\n #endi"
"f\r\n}\r\n#endif\r\n\r\nfloat PCF(sampler2D shadowmap, vec2 st, float dist)"
"\r\n{\r\n\tfloat mult;\r\n\t\r\n\tmult = sign(clamp(texture2D(shadowmap, s"
"t + vec2(-1.0, -1.0) / 1024.0).r - dist, 0.0, 1.0));\r\n\tmult += sign(clam"
"p(texture2D(shadowmap, st + vec2( 1.0, -1.0) / 1024.0).r - dist, 0.0, 1.0))"
";\r\n\tmult += sign(clamp(texture2D(shadowmap, st + vec2(-1.0, 1.0) / 1024"
".0).r - dist, 0.0, 1.0));\r\n\tmult += sign(clamp(texture2D(shadowmap, st +"
" vec2( 1.0, 1.0) / 1024.0).r - dist, 0.0, 1.0));\r\n\tmult *= 0.25;\r\n\t"
"\r\n\t//mult = sign(clamp(texture2D(shadowmap, st).r - dist, 0.0, 1.0));\r"
"\n\t\t\r\n\treturn mult;\r\n}\r\n\r\nvoid main()\r\n{\r\n#if defined(USE_LI"
"GHT) || defined(USE_NORMALMAP)\r\n\tvec3 surfNormal = normalize(var_Normal)"
";\r\n#endif\r\n\r\n#if defined(USE_DELUXEMAP)\r\n\tvec3 worldLight = 2.0 * "
"texture2D(u_DeluxeMap, var_LightTex).xyz - vec3(1.0);\r\n\t//worldLight += "
"var_WorldLight * 0.0001;\r\n#elif defined(USE_LIGHT)\r\n\tvec3 worldLight ="
" var_WorldLight;\r\n#endif\r\n\r\n#if defined(USE_LIGHTMAP)\r\n\tvec4 light"
"Sample = texture2D(u_LightMap, var_LightTex).rgba;\r\n #if defined(RGBE_LI"
"GHTMAP)\r\n\tlightSample.rgb *= exp2(lightSample.a * 255.0 - 128.0);\r\n #"
"endif\r\n\tvec3 directedLight = lightSample.rgb * u_MapLightScale;\r\n#elif"
" defined(USE_LIGHT_VECTOR)\r\n #if defined(USE_FAST_LIGHT)\r\n\tvec3 direc"
"tedLight = var_VectLight;\r\n #else\r\n #if defined(USE_INVSQRLIGHT)\r"
"\n\tfloat intensity = 1.0 / dot(worldLight, worldLight);\r\n #else\r\n\t"
"float intensity = clamp((1.0 - dot(worldLight, worldLight) / (u_LightRadius"
" * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #endif\r\n\r\n\tvec3 directedL"
"ight = u_DirectedLight * intensity;\r\n\tvec3 ambientLight = u_AmbientLigh"
"t;\r\n #endif\r\n\r\n #if defined(USE_SHADOWMAP)\r\n\tvec4 biasPos = vec4"
"(var_Position + surfNormal * (length(var_SampleToView) * 0.005 + 0.05), 1.0"
");\r\n\tvec4 shadowpos = u_ShadowMvp * biasPos;\r\n\tfloat outside1 = dot(v"
"ec3(1.0, 1.0, 1.0), sign(clamp(abs(shadowpos.xyz) - 1.0, 0.0, 1.0)));\r\n\t"
"\r\n\t#if defined(USE_SHADOW_CASCADE)\r\n\tvec4 shadowpos2 = u_ShadowMvp2 *"
" biasPos;\r\n\tfloat outside2 = dot(vec3(1.0, 1.0, 1.0), sign(clamp(abs(sha"
"dowpos2.xyz) - 1.0, 0.0, 1.0)));\r\n\r\n\tvec4 shadowpos3 = u_ShadowMvp3 * "
"biasPos;\r\n\tfloat outside3 = dot(vec3(1.0, 1.0, 1.0), sign(clamp(abs(shad"
"owpos3.xyz) - 1.0, 0.0, 1.0)));\r\n\t\r\n\tif (outside1 < 1.0)\r\n\t{\r\n\t"
"\tshadowpos.xyz = shadowpos.xyz * 0.5 + 0.5;\r\n\t\tdirectedLight *= PCF(u_"
"ShadowMap, shadowpos.xy, shadowpos.z);\r\n\t}\r\n\telse if (outside2 < 1.0)"
"\r\n\t{\r\n\t\tshadowpos2.xyz = shadowpos2.xyz * 0.5 + 0.5;\r\n\t\tdirected"
"Light *= PCF(u_ShadowMap2, shadowpos2.xy, shadowpos2.z);\r\n\t}\r\n\telse i"
"f (outside3 < 1.0)\r\n\t{\r\n\t\tshadowpos3.xyz = shadowpos3.xyz * 0.5 + 0."
"5;\r\n\t\tfloat mult = PCF(u_ShadowMap3, shadowpos3.xy, shadowpos3.z) + cla"
"mp(length(var_SampleToView) / 1024.0 - 0.95, 0.0, 1.0);\r\n\t\tdirectedLigh"
"t *= clamp(mult, 0.0, 1.0);\r\n\t}\r\n\t\r\n\t#else\r\n\tshadowpos.xyz = sh"
"adowpos.xyz * 0.5 + 0.5;\r\n\tdirectedLight *= clamp(PCF(u_ShadowMap, shado"
"wpos.xy, shadowpos.z) - outside1, 1.0, 0.0);\r\n\t#endif\r\n #endif\r\n#el"
"if defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLight = var_Color.rgb * u_Ma"
"pLightScale;\r\n#endif\r\n\t\r\n#if defined(USE_NORMALMAP) || defined(USE_L"
"IGHT) && !defined(USE_FAST_LIGHT)\r\n\tvec3 SampleToView = normalize(var_Sa"
"mpleToView);\r\n#endif\r\n\tvec2 tex = var_DiffuseTex;\r\n\r\n\tfloat ambie"
"ntDiff = 1.0;\r\n\r\n#if defined(USE_NORMALMAP)\r\n #if defined(USE_VERT_T"
"ANGENT_SPACE)\r\n vec3 tangent = normalize(var_Tangent);\r\n\tvec3 bit"
"angent = normalize(var_Bitangent);\r\n #else\r\n\tvec3 q0 = dFdx(var_Posi"
"tion);\r\n\tvec3 q1 = dFdy(var_Position);\r\n\tvec2 st0 = dFdx(tex);\r\n\t"
"vec2 st1 = dFdy(tex);\r\n\tfloat dir = sign(st1.t * st0.s - st0.t * st1.s);"
"\r\n\r\n\tvec3 tangent = normalize( q0 * st1.t - q1 * st0.t) * dir;\r\n\t"
"vec3 bitangent = -normalize( q0 * st1.s - q1 * st0.s) * dir;\r\n #endif\r"
"\n\r\n\tmat3 tangentToWorld = mat3(tangent, bitangent, surfNormal);\r\n\r\n"
" #if defined(USE_PARALLAXMAP)\r\n\tvec3 offsetDir = normalize(SampleToView"
" * tangentToWorld);\r\n #if 0\r\n float height = SampleHeight(u_Norma"
"lMap, tex);\r\n\tfloat pdist = 0.05 * height - (0.05 / 2.0);\r\n #else\r"
"\n\toffsetDir.xy *= -0.05 / offsetDir.z;\r\n\tfloat pdist = RayIntersectDis"
"placeMap(tex, offsetDir.xy, u_NormalMap);\r\n #endif\t\r\n\ttex += offse"
"tDir.xy * pdist;\r\n #endif\r\n #if defined(SWIZZLE_NORMALMAP)\r\n\tvec3 "
"normal = 2.0 * texture2D(u_NormalMap, tex).agb - 1.0;\r\n #else\r\n\tvec3 "
"normal = 2.0 * texture2D(u_NormalMap, tex).rgb - 1.0;\r\n #endif\r\n\tnorm"
"al.z = sqrt(clamp(1.0 - dot(normal.xy, normal.xy), 0.0, 1.0));\r\n\tvec3 wo"
"rldNormal = tangentToWorld * normal;\r\n #if defined(r_normalAmbient)\r\n"
"\tambientDiff = 0.781341 * normal.z + 0.218659;\r\n #endif\r\n#elif define"
"d(USE_LIGHT)\r\n\tvec3 worldNormal = surfNormal;\r\n#endif\r\n\r\n\tvec4 di"
"ffuse = texture2D(u_DiffuseMap, tex);\r\n\r\n#if defined(USE_LIGHT) && defi"
"ned(USE_FAST_LIGHT)\r\n\tdiffuse.rgb *= directedLight;\r\n#elif defined(USE"
"_LIGHT)\r\n\tworldNormal = normalize(worldNormal);\r\n\tworldLight = normal"
"ize(worldLight);\r\n\r\n #if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VE"
"RTEX)\r\n\tdirectedLight /= max(dot(surfNormal, worldLight), 0.004);\r\n\r"
"\n #if defined(r_normalAmbient)\r\n\tvec3 ambientLight = directedLight *"
" r_normalAmbient;\r\n\tdirectedLight -= ambientLight;\r\n #else\r\n\tvec"
"3 ambientLight = vec3(0);\r\n #endif\r\n #endif\r\n\r\n\tfloat NL = cla"
"mp(dot(worldNormal, worldLight), 0.0, 1.0);\r\n\tfloat surfNL = clamp(do"
"t(surfNormal, worldLight), 0.0, 1.0);\r\n\tNL = min(NL, surfNL * 2.0);\r"
"\n\tfloat NE = clamp(dot(worldNormal, SampleToView), 0.0, 1.0);\r\n\t\r\n"
"\tfloat fzero = u_MaterialInfo.x;\r\n\tfloat shininess = u_MaterialInfo.y;"
"\r\n #if defined(USE_SPECULARMAP)\r\n\tvec4 specular = texture2D(u_Specula"
"rMap, tex);\r\n\t//specular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1."
"0);\r\n\tshininess *= specular.a;\r\n #endif\r\n\tfloat directedDiff = NL "
"* CalcDiffuse(worldNormal, worldLight, SampleToView, NE, NL, fzero, shinine"
"ss);\r\n\tdiffuse.rgb *= directedLight * directedDiff + ambientDiff * ambie"
"ntLight;\r\n \r\n #if defined(USE_SPECULARMAP)\r\n\tvec3 halfAngle = norm"
"alize(worldLight + SampleToView);\r\n\r\n\tfloat EH = clamp(dot(SampleToVie"
"w, halfAngle), 0.0, 1.0);\r\n\tfloat NH = clamp(dot(worldNormal, halfAngle"
"), 0.0, 1.0);\r\n\r\n\tfloat directedSpec = NL * CalcSpecular(NH, NL, NE, E"
"H, fzero, shininess);\r\n \r\n #if defined(r_normalAmbient)\r\n\tvec3 a"
"mbientHalf = normalize(surfNormal + SampleToView);\r\n\tfloat ambientSpec ="
" max(dot(ambientHalf, worldNormal) + 0.5, 0.0);\r\n\tambientSpec *= ambient"
"Spec * 0.44;\r\n\tambientSpec = pow(ambientSpec, shininess) * fzero;\r\n\ts"
"pecular.rgb *= directedSpec * directedLight + ambientSpec * ambientLight;\r"
"\n #else\r\n\tspecular.rgb *= directedSpec * directedLight;\r\n #endi"
"f\r\n #endif\r\n#endif\r\n\r\n\tgl_FragColor = diffuse;\r\n\r\n#if defined"
"(USE_SPECULARMAP) && defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)\r\n\tgl"
"_FragColor.rgb += specular.rgb;\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VER"
"TEX)\r\n\tgl_FragColor *= var_Color;\r\n#endif\r\n}\r\n";
"WMAP)\r\nuniform sampler2D u_ShadowMap;\r\n#endif\r\n\r\nuniform vec3 "
"u_ViewOrigin;\r\n\r\n#if defined(USE_LIGHT_VECTOR)\r\nuniform vec3 u_D"
"irectedLight;\r\nuniform vec3 u_AmbientLight;\r\nuniform float u_L"
"ightRadius;\r\n#endif\r\n\r\n#if defined(USE_LIGHT)\r\nuniform vec2 u_"
"MaterialInfo;\r\n#endif\r\n\r\nvarying vec2 var_DiffuseTex;\r\n#if def"
"ined(USE_LIGHTMAP)\r\nvarying vec2 var_LightTex;\r\n#endif\r\nvarying "
"vec4 var_Color;\r\nvarying vec3 var_Position;\r\n\r\nvarying vec3"
" var_SampleToView;\r\n\r\nvarying vec3 var_Normal;\r\n#if defined"
"(USE_VERT_TANGENT_SPACE)\r\nvarying vec3 var_Tangent;\r\nvarying vec3 "
" var_Bitangent;\r\n#endif\r\n\r\n#if defined(USE_LIGHT_VECTOR) && defin"
"ed(USE_FAST_LIGHT)\r\nvarying vec3 var_VectLight;\r\n#endif\r\n\r\n#if"
" defined(USE_LIGHT) && !defined(USE_DELUXEMAP)\r\nvarying vec3 var_Wor"
"ldLight;\r\n#endif\r\n\r\nvarying vec4 var_ScreenPos;\r\n\r\n#define EPSI"
"LON 0.00000001\r\n\r\n#if defined(USE_PARALLAXMAP)\r\nfloat SampleHeight(sa"
"mpler2D normalMap, vec2 t)\r\n{\r\n #if defined(SWIZZLE_NORMALMAP)\r\n\tre"
"turn texture2D(normalMap, t).r;\r\n #else\r\n\treturn texture2D(normalMap,"
" t).a;\r\n #endif\r\n}\r\n\r\nfloat RayIntersectDisplaceMap(vec2 dp, vec2 "
"ds, sampler2D normalMap)\r\n{\r\n\tconst int linearSearchSteps = 16;\r\n\tc"
"onst int binarySearchSteps = 6;\r\n\r\n\tfloat depthStep = 1.0 / float(line"
"arSearchSteps);\r\n\r\n\t// current size of search window\r\n\tfloat size ="
" depthStep;\r\n\r\n\t// current depth position\r\n\tfloat depth = 0.0;\r\n"
"\r\n\t// best match found (starts with last position 1.0)\r\n\tfloat bestDe"
"pth = 1.0;\r\n\r\n\t// search front to back for first point inside object\r"
"\n\tfor(int i = 0; i < linearSearchSteps - 1; ++i)\r\n\t{\r\n\t\tdepth += s"
"ize;\r\n\t\t\r\n\t\tfloat t = 1.0 - SampleHeight(normalMap, dp + ds * depth"
");\r\n\t\t\r\n\t\tif(bestDepth > 0.996)\t\t// if no depth found yet\r\n\t\t"
"\tif(depth >= t)\r\n\t\t\t\tbestDepth = depth;\t// store best depth\r\n\t}"
"\r\n\r\n\tdepth = bestDepth;\r\n\t\r\n\t// recurse around first point (dept"
"h) for closest match\r\n\tfor(int i = 0; i < binarySearchSteps; ++i)\r\n\t{"
"\r\n\t\tsize *= 0.5;\r\n\r\n\t\tfloat t = 1.0 - SampleHeight(normalMap, dp "
"+ ds * depth);\r\n\t\t\r\n\t\tif(depth >= t)\r\n\t\t{\r\n\t\t\tbestDepth = "
"depth;\r\n\t\t\tdepth -= 2.0 * size;\r\n\t\t}\r\n\r\n\t\tdepth += size;\r\n"
"\t}\r\n\r\n\treturn bestDepth;\r\n}\r\n#endif\r\n\r\nfloat CalcDiffuse(vec3"
" N, vec3 L, vec3 E, float NE, float NL, float fzero, float shininess)\r\n{"
"\r\n #if defined(USE_OREN_NAYAR)\r\n\tfloat roughness = sqrt(2.0 / max(shi"
"niness, EPSILON));\r\n\r\n\tfloat gamma = dot(E - N * NE, L - N * NL);\r\n"
"\tfloat r_sq = roughness * roughness;\r\n\r\n\tfloat A = 1.0 - 0.5 * (r_sq "
"/ (r_sq + 0.57));\r\n\tfloat B = 0.45 * (r_sq / (r_sq + 0.09));\r\n\r\n\tfl"
"oat alpha = max(acos(NE), acos(NL));\r\n\tfloat beta = min(acos(NE), acos("
"NL));\r\n\r\n\tfloat C = sin(alpha) * tan(beta);\r\n\r\n\treturn A + B * cl"
"amp(gamma, 0.0, 1.0) * C;\r\n #else\r\n\treturn 1.0 - fzero;\r\n #endif\r"
"\n}\r\n\r\n#if defined(USE_SPECULARMAP)\r\nfloat CalcSpecular(float NH, flo"
"at NL, float NE, float EH, float fzero, float shininess)\r\n{\r\n #if defi"
"ned(USE_BLINN) || defined(USE_TRIACE) || defined(USE_TORRANCE_SPARROW)\r\n"
"\tfloat blinn = pow(NH, shininess);\r\n #endif\r\n\r\n #if defined(USE_BL"
"INN)\r\n\treturn blinn;\r\n #endif\r\n\r\n #if defined(USE_COOK_TORRANCE)"
" || defined (USE_TRIACE) || defined (USE_TORRANCE_SPARROW)\r\n\tfloat fresn"
"el = fzero + (1.0 - fzero) * pow(1.0 - EH, 5);\r\n #endif\r\n\r\n #if def"
"ined(USE_COOK_TORRANCE) || defined(USE_TORRANCE_SPARROW)\r\n\tfloat geo = 2"
".0 * NH * min(NE, NL);\r\n\tgeo /= max(EH, geo);\r\n #endif \r\n\r\n #if"
" defined(USE_COOK_TORRANCE)\r\n\tfloat m = sqrt(2.0 / max(shininess, EPSILO"
"N));\r\n\r\n\tfloat m_sq = m * m;\r\n\tfloat NH_sq = NH * NH;\r\n\tfloat be"
"ckmann = exp((NH_sq - 1.0) / max(m_sq * NH_sq, EPSILON)) / max(4.0 * m_sq *"
" NH_sq * NH_sq, EPSILON);\r\n\r\n\treturn fresnel * geo * beckmann / max(NE"
", EPSILON);\r\n #endif\r\n\r\n #if defined(USE_TRIACE)\r\n\tfloat scale ="
" 0.1248582 * shininess + 0.2691817;\r\n\r\n\treturn fresnel * scale * blinn"
" / max(max(NL, NE), EPSILON);\r\n #endif\r\n \r\n #if defined(USE_TORRAN"
"CE_SPARROW)\r\n\tfloat scale = 0.125 * shininess + 1.0;\r\n\r\n\treturn fre"
"snel * geo * scale * blinn / max(NE, EPSILON);\r\n #endif\r\n}\r\n#endif\r"
"\n\r\nvoid main()\r\n{\r\n#if defined(USE_LIGHT) || defined(USE_NORMALMAP)"
"\r\n\tvec3 surfNormal = normalize(var_Normal);\r\n#endif\r\n\r\n#if defined"
"(USE_DELUXEMAP)\r\n\tvec3 worldLight = 2.0 * texture2D(u_DeluxeMap, var_Lig"
"htTex).xyz - vec3(1.0);\r\n\t//worldLight += var_WorldLight * 0.0001;\r\n#e"
"lif defined(USE_LIGHT)\r\n\tvec3 worldLight = var_WorldLight;\r\n#endif\r\n"
"\r\n#if defined(USE_LIGHTMAP)\r\n\tvec4 lightSample = texture2D(u_LightMap,"
" var_LightTex).rgba;\r\n #if defined(RGBE_LIGHTMAP)\r\n\tlightSample.rgb *"
"= exp2(lightSample.a * 255.0 - 128.0);\r\n #endif\r\n\tvec3 directedLight "
"= lightSample.rgb;\r\n#elif defined(USE_LIGHT_VECTOR)\r\n #if defined(USE_"
"FAST_LIGHT)\r\n\tvec3 directedLight = var_VectLight;\r\n #else\r\n #if "
"defined(USE_INVSQRLIGHT)\r\n\tfloat intensity = 1.0 / dot(worldLight, world"
"Light);\r\n #else\r\n\tfloat intensity = clamp((1.0 - dot(worldLight, wo"
"rldLight) / (u_LightRadius * u_LightRadius)) * 1.07, 0.0, 1.0);\r\n #end"
"if\r\n\r\n\tvec3 directedLight = u_DirectedLight * intensity;\r\n\tvec3 amb"
"ientLight = u_AmbientLight;\r\n #endif\r\n\r\n #if defined(USE_SHADOWMAP"
")\r\n\tvec2 shadowTex = var_ScreenPos.xy / var_ScreenPos.w * 0.5 + 0.5;\r\n"
"\tdirectedLight *= texture2D(u_ShadowMap, shadowTex).r;\r\n #endif\r\n#eli"
"f defined(USE_LIGHT_VERTEX)\r\n\tvec3 directedLight = var_Color.rgb;\r\n#en"
"dif\r\n\t\r\n#if defined(USE_NORMALMAP) || defined(USE_LIGHT) && !defined(U"
"SE_FAST_LIGHT)\r\n\tvec3 SampleToView = normalize(var_SampleToView);\r\n#en"
"dif\r\n\tvec2 tex = var_DiffuseTex;\r\n\r\n\tfloat ambientDiff = 1.0;\r\n\r"
"\n#if defined(USE_NORMALMAP)\r\n #if defined(USE_VERT_TANGENT_SPACE)\r\n "
" vec3 tangent = normalize(var_Tangent);\r\n\tvec3 bitangent = normalize("
"var_Bitangent);\r\n #else\r\n\tvec3 q0 = dFdx(var_Position);\r\n\tvec3 q1"
" = dFdy(var_Position);\r\n\tvec2 st0 = dFdx(tex);\r\n\tvec2 st1 = dFdy(tex"
");\r\n\tfloat dir = sign(st1.t * st0.s - st0.t * st1.s);\r\n\r\n\tvec3 ta"
"ngent = normalize( q0 * st1.t - q1 * st0.t) * dir;\r\n\tvec3 bitangent = -n"
"ormalize( q0 * st1.s - q1 * st0.s) * dir;\r\n #endif\r\n\r\n\tmat3 tangent"
"ToWorld = mat3(tangent, bitangent, surfNormal);\r\n\r\n #if defined(USE_PA"
"RALLAXMAP)\r\n\tvec3 offsetDir = normalize(SampleToView * tangentToWorld);"
"\r\n #if 0\r\n float height = SampleHeight(u_NormalMap, tex);\r\n\tfl"
"oat pdist = 0.05 * height - (0.05 / 2.0);\r\n #else\r\n\toffsetDir.xy *="
" -0.05 / offsetDir.z;\r\n\tfloat pdist = RayIntersectDisplaceMap(tex, offse"
"tDir.xy, u_NormalMap);\r\n #endif\t\r\n\ttex += offsetDir.xy * pdist;\r"
"\n #endif\r\n #if defined(SWIZZLE_NORMALMAP)\r\n\tvec3 normal = 2.0 * tex"
"ture2D(u_NormalMap, tex).agb - 1.0;\r\n #else\r\n\tvec3 normal = 2.0 * tex"
"ture2D(u_NormalMap, tex).rgb - 1.0;\r\n #endif\r\n\tnormal.z = sqrt(clamp("
"1.0 - dot(normal.xy, normal.xy), 0.0, 1.0));\r\n\tvec3 worldNormal = tangen"
"tToWorld * normal;\r\n #if defined(r_normalAmbient)\r\n\tambientDiff = 0.7"
"81341 * normal.z + 0.218659;\r\n #endif\r\n#elif defined(USE_LIGHT)\r\n\tv"
"ec3 worldNormal = surfNormal;\r\n#endif\r\n\r\n\tvec4 diffuse = texture2D(u"
"_DiffuseMap, tex);\r\n\r\n#if defined(USE_LIGHT) && defined(USE_FAST_LIGHT)"
"\r\n\tdiffuse.rgb *= directedLight;\r\n#elif defined(USE_LIGHT)\r\n\tworldN"
"ormal = normalize(worldNormal);\r\n\tworldLight = normalize(worldLight);\r"
"\n\r\n #if defined(USE_LIGHTMAP) || defined(USE_LIGHT_VERTEX)\r\n\tdirecte"
"dLight /= max(dot(surfNormal, worldLight), 0.004);\r\n\r\n #if defined(r"
"_normalAmbient)\r\n\tvec3 ambientLight = directedLight * r_normalAmbient;\r"
"\n\tdirectedLight -= ambientLight;\r\n #else\r\n\tvec3 ambientLight = ve"
"c3(0);\r\n #endif\r\n #endif\r\n\r\n\tfloat NL = clamp(dot(worldNormal,"
" worldLight), 0.0, 1.0);\r\n\tfloat surfNL = clamp(dot(surfNormal, worl"
"dLight), 0.0, 1.0);\r\n\tNL = min(NL, surfNL * 2.0);\r\n\tfloat NE = clam"
"p(dot(worldNormal, SampleToView), 0.0, 1.0);\r\n\t\r\n\tfloat fzero = u_Ma"
"terialInfo.x;\r\n\tfloat shininess = u_MaterialInfo.y;\r\n #if defined(USE"
"_SPECULARMAP)\r\n\tvec4 specular = texture2D(u_SpecularMap, tex);\r\n\t//sp"
"ecular.rgb = clamp(specular.rgb - diffuse.rgb, 0.0, 1.0);\r\n\tshininess *="
" specular.a;\r\n #endif\r\n\tfloat directedDiff = NL * CalcDiffuse(worldNo"
"rmal, worldLight, SampleToView, NE, NL, fzero, shininess);\r\n\tdiffuse.rgb"
" *= directedLight * directedDiff + ambientDiff * ambientLight;\r\n \r\n #"
"if defined(USE_SPECULARMAP)\r\n\tvec3 halfAngle = normalize(worldLight + Sa"
"mpleToView);\r\n\r\n\tfloat EH = clamp(dot(SampleToView, halfAngle), 0.0, 1"
".0);\r\n\tfloat NH = clamp(dot(worldNormal, halfAngle), 0.0, 1.0);\r\n\r\n"
"\tfloat directedSpec = NL * CalcSpecular(NH, NL, NE, EH, fzero, shininess);"
"\r\n \r\n #if defined(r_normalAmbient)\r\n\tvec3 ambientHalf = normaliz"
"e(surfNormal + SampleToView);\r\n\tfloat ambientSpec = max(dot(ambientHalf,"
" worldNormal) + 0.5, 0.0);\r\n\tambientSpec *= ambientSpec * 0.44;\r\n\tamb"
"ientSpec = pow(ambientSpec, shininess) * fzero;\r\n\tspecular.rgb *= direct"
"edSpec * directedLight + ambientSpec * ambientLight;\r\n #else\r\n\tspec"
"ular.rgb *= directedSpec * directedLight;\r\n #endif\r\n #endif\r\n#end"
"if\r\n\r\n\tgl_FragColor = diffuse;\r\n\r\n#if defined(USE_SPECULARMAP) && "
"defined(USE_LIGHT) && !defined(USE_FAST_LIGHT)\r\n\tgl_FragColor.rgb += spe"
"cular.rgb;\r\n#endif\r\n\r\n#if !defined(USE_LIGHT_VERTEX)\r\n\tgl_FragColo"
"r *= var_Color;\r\n#endif\r\n}\r\n";
static const char *fallbackShadowfillShader_vp =
"attribute vec4 attr_Position;\r\nattribute vec3 attr_Normal;\r\nattribute"
@ -727,6 +698,77 @@ static const char *fallbackCalcLevels4xShader_fp =
"5), current);\r\n\r\n\tcurrent.y *= 0.0625;\r\n#endif\r\n\r\n\tgl_FragColor"
" = vec4(current, 1.0f);\r\n}\r\n";
static const char *fallbackShadowmaskShader_vp =
"attribute vec4 attr_Position;\r\nattribute vec4 attr_TexCoord0;\r\n\r\nunif"
"orm vec3 u_ViewForward;\r\nuniform vec3 u_ViewLeft;\r\nuniform vec3 u"
"_ViewUp;\r\nuniform vec4 u_ViewInfo; // zfar / znear\r\n\r\nvarying vec2 "
" var_ScreenTex;\r\nvarying vec3 var_ViewDir;\r\n\r\nvoid main()\r\n{\r\n"
"\tgl_Position = attr_Position;\r\n\t//vec2 screenCoords = gl_Position.xy / "
"gl_Position.w;\r\n\t//var_ScreenTex = screenCoords * 0.5 + 0.5;\r\n\tvar_Sc"
"reenTex = attr_TexCoord0.xy;\r\n\tvec2 screenCoords = attr_TexCoord0.xy * 2"
".0 - 1.0;\r\n\tvar_ViewDir = u_ViewForward + u_ViewLeft * -screenCoords.x +"
" u_ViewUp * screenCoords.y;\r\n}\r\n";
static const char *fallbackShadowmaskShader_fp =
"uniform sampler2D u_ScreenDepthMap;\r\n\r\nuniform sampler2D u_ShadowMap;\r"
"\n#if 1 //defined(USE_SHADOW_CASCADE)\r\nuniform sampler2D u_ShadowMap2;\r"
"\nuniform sampler2D u_ShadowMap3;\r\n#endif\r\n\r\nuniform mat4 u_Shad"
"owMvp;\r\n#if 1 //defined(USE_SHADOW_CASCADE)\r\nuniform mat4 u_Shadow"
"Mvp2;\r\nuniform mat4 u_ShadowMvp3;\r\n#endif\r\n\r\nuniform vec3 u_"
"ViewOrigin;\r\nuniform vec4 u_ViewInfo; // zfar / znear, zfar\r\n\r\nvary"
"ing vec2 var_ScreenTex;\r\nvarying vec3 var_ViewDir;\r\n\r\n// Input: I"
"t uses texture coords as the random number seed.\r\n// Output: Random numbe"
"r: [0,1), that is between 0.0 and 0.999999... inclusive.\r\n// Author: Mich"
"ael Pohoreski\r\n// Copyright: Copyleft 2012 :-)\r\n// Source: http://stack"
"overflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixe"
"l-shader\r\n\r\nfloat random( vec2 p )\r\n{\r\n // We need irrationals for"
" pseudo randomness.\r\n // Most (all?) known transcendental numbers will ("
"generally) work.\r\n const vec2 r = vec2(\r\n 23.1406926327792690, // "
"e^pi (Gelfond's constant)\r\n 2.6651441426902251); // 2^sqrt(2) (Gelfon"
"d?chneider constant)\r\n //return fract( cos( mod( 123456789., 1e-7 + 256"
". * dot(p,r) ) ) );\r\n return mod( 123456789., 1e-7 + 256. * dot(p,r) ); "
" \r\n}\r\n\r\nfloat PCF(sampler2D shadowmap, vec2 st, float dist)\r\n{\r\n"
"\tfloat mult;\r\n\tfloat scale = 2.0 / r_shadowMapSize;\r\n\t\t\r\n#if defi"
"ned(USE_SHADOW_FILTER)\r\n\tfloat r = random(var_ScreenTex.xy);\r\n\tfloat "
"sinr = sin(r) * scale;\r\n\tfloat cosr = cos(r) * scale;\r\n\tmat2 rmat = m"
"at2(cosr, sinr, -sinr, cosr);\r\n\r\n\tmult = step(dist, texture2D(shadowma"
"p, st + rmat * vec2(-0.7055767, 0.196515)).r);\r\n\tmult += step(dist, text"
"ure2D(shadowmap, st + rmat * vec2(0.3524343, -0.7791386)).r);\r\n mult +"
"= step(dist, texture2D(shadowmap, st + rmat * vec2(0.2391056, 0.9189604)).r"
");\r\n #if defined(USE_SHADOW_FILTER2)\r\n\tmult += step(dist, texture2D(s"
"hadowmap, st + rmat * vec2(-0.07580382, -0.09224417)).r);\r\n\tmult += step"
"(dist, texture2D(shadowmap, st + rmat * vec2(0.5784913, -0.002528916)).r);"
"\r\n\tmult += step(dist, texture2D(shadowmap, st + rmat * vec2(0.192888, 0."
"4064181)).r);\r\n\tmult += step(dist, texture2D(shadowmap, st + rmat * vec2"
"(-0.6335801, -0.5247476)).r);\r\n\tmult += step(dist, texture2D(shadowmap, "
"st + rmat * vec2(-0.5579782, 0.7491854)).r);\r\n\tmult += step(dist, textur"
"e2D(shadowmap, st + rmat * vec2(0.7320465, 0.6317794)).r);\r\n\r\n\tmult *="
" 0.11111;\r\n #else\r\n mult *= 0.33333;\r\n #endif\r\n#else\r\n\tmult"
" = step(dist, texture2D(shadowmap, st).r);\r\n#endif\r\n\t\t\r\n\treturn mu"
"lt;\r\n}\r\n\r\nvoid main()\r\n{\r\n\tconst float fadeTo = 0.5;\r\n\tfloat "
"result = fadeTo;\r\n\tfloat sampleZ_W = texture2D(u_ScreenDepthMap, var_Scr"
"eenTex).r;\r\n\r\n\tfloat depth = 1.0 / mix(u_ViewInfo.x, 1.0, sampleZ_W);"
"\r\n\tfloat sampleZ = u_ViewInfo.y * depth;\r\n\tvec4 biasPos = vec4(u_View"
"Origin + var_ViewDir * depth * 0.99, 1.0);\r\n\t\r\n #if defined(USE_SHADO"
"W_CASCADE)\r\n\tvec4 shadowpos = u_ShadowMvp * biasPos;\r\n\tshadowpos /= s"
"hadowpos.w;\r\n\r\n\tvec4 shadowpos2 = u_ShadowMvp2 * biasPos;\r\n\tshadowp"
"os2 /= shadowpos2.w;\r\n\r\n\tvec4 shadowpos3 = u_ShadowMvp3 * biasPos;\r\n"
"\tshadowpos3 /= shadowpos3.w;\r\n\t\r\n\tif (all(lessThan(abs(shadowpos.xyz"
"), vec3(1.0))))\r\n\t{\r\n\t\tshadowpos.xyz = shadowpos.xyz * 0.5 + 0.5;\r"
"\n\t\tresult = PCF(u_ShadowMap, shadowpos.xy, shadowpos.z);\r\n\t}\r\n\tels"
"e if (all(lessThan(abs(shadowpos2.xyz), vec3(1.0))))\r\n\t{\r\n\t\tshadowpo"
"s2.xyz = shadowpos2.xyz * 0.5 + 0.5;\r\n\t\tresult = PCF(u_ShadowMap2, shad"
"owpos2.xy, shadowpos2.z);\r\n\t}\r\n\telse if (all(lessThan(abs(shadowpos3."
"xyz), vec3(1.0))))\r\n\t{\r\n\t\tshadowpos3.xyz = shadowpos3.xyz * 0.5 + 0."
"5;\r\n\t\tresult = PCF(u_ShadowMap3, shadowpos3.xy, shadowpos3.z);\r\n\r\n"
"\t\tfloat fade = clamp(sampleZ / r_shadowCascadeZFar * 10.0 - 9.0, 0.0, 1.0"
");\r\n\t\tresult = mix(result, fadeTo, fade);\r\n\t}\r\n\t\r\n #else\r\n\t"
"vec4 shadowpos = u_ShadowMvp * biasPos;\r\n\tshadowpos /= shadowpos.w;\r\n"
"\r\n\tfloat outside = dot(vec3(1.0), step(1.0, abs(shadowpos.xyz)));\r\n\r"
"\n\tshadowpos.xyz = shadowpos.xyz * 0.5 + 0.5;\r\n\tresult = clamp(PCF(u_Sh"
"adowMap, shadowpos.xy, shadowpos.z) - outside, 1.0, 0.0);\r\n #endif\r\n\t"
"\t\r\n\tgl_FragColor.rgba = vec4(vec3(result), 1.0);\r\n}";
static void GLSL_PrintInfoLog(GLhandleARB object, qboolean developerOnly)
@ -1786,13 +1828,8 @@ void GLSL_InitGPUShaders(void)
{
if (i & LIGHTDEF_USE_SHADOWMAP)
continue;
if (i & LIGHTDEF_USE_SHADOW_CASCADE)
continue;
}
if ((i & LIGHTDEF_USE_SHADOW_CASCADE) && !(i & LIGHTDEF_USE_SHADOWMAP))
continue;
attribs = ATTR_POSITION | ATTR_TEXCOORD | ATTR_COLOR | ATTR_NORMAL;
extradefines[0] = '\0';
@ -1883,9 +1920,6 @@ void GLSL_InitGPUShaders(void)
if (i & LIGHTDEF_USE_SHADOWMAP)
Q_strcat(extradefines, 1024, "#define USE_SHADOWMAP\n");
if (i & LIGHTDEF_USE_SHADOW_CASCADE)
Q_strcat(extradefines, 1024, "#define USE_SHADOW_CASCADE\n");
if (i & LIGHTDEF_TCGEN_ENVIRONMENT)
Q_strcat(extradefines, 1024, "#define TCGEN_ENVIRONMENT\n");
@ -1920,8 +1954,6 @@ void GLSL_InitGPUShaders(void)
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_DELUXEMAP, "u_DeluxeMap", GLSL_INT);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_SPECULARMAP, "u_SpecularMap", GLSL_INT);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMAP, "u_ShadowMap", GLSL_INT);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMAP2, "u_ShadowMap2", GLSL_INT);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMAP3, "u_ShadowMap3", GLSL_INT);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_AMBIENTLIGHT, "u_AmbientLight", GLSL_VEC3);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_DIRECTEDLIGHT, "u_DirectedLight", GLSL_VEC3);
@ -1934,12 +1966,6 @@ void GLSL_InitGPUShaders(void)
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_VERTCOLOR, "u_VertColor", GLSL_VEC4);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_VERTEXLERP, "u_VertexLerp", GLSL_FLOAT);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMVP, "u_ShadowMvp", GLSL_MAT16);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMVP2, "u_ShadowMvp2", GLSL_MAT16);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMVP3, "u_ShadowMvp3", GLSL_MAT16);
GLSL_AddUniform(&tr.lightallShader[i], GENERIC_UNIFORM_MAPLIGHTSCALE, "u_MapLightScale", GLSL_FLOAT);
GLSL_EndUniforms(&tr.lightallShader[i]);
qglUseProgramObjectARB(tr.lightallShader[i].program);
@ -1949,8 +1975,6 @@ void GLSL_InitGPUShaders(void)
GLSL_SetUniformInt(&tr.lightallShader[i], GENERIC_UNIFORM_DELUXEMAP, TB_DELUXEMAP);
GLSL_SetUniformInt(&tr.lightallShader[i], GENERIC_UNIFORM_SPECULARMAP, TB_SPECULARMAP);
GLSL_SetUniformInt(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMAP, TB_SHADOWMAP);
GLSL_SetUniformInt(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMAP2, TB_SHADOWMAP2);
GLSL_SetUniformInt(&tr.lightallShader[i], GENERIC_UNIFORM_SHADOWMAP3, TB_SHADOWMAP3);
qglUseProgramObjectARB(0);
GLSL_FinishGPUShader(&tr.lightallShader[i]);
@ -1985,7 +2009,7 @@ void GLSL_InitGPUShaders(void)
attribs = ATTR_POSITION | ATTR_NORMAL;
extradefines[0] = '\0';
Q_strcat(extradefines, 1024, "#define USE_PCF\n#define USE_DISCARD");
Q_strcat(extradefines, 1024, "#define USE_PCF\n#define USE_DISCARD\n");
if (!GLSL_InitGPUShader(&tr.pshadowShader, "pshadow", attribs, qtrue, extradefines, qtrue, fallbackPshadowShader_vp, fallbackPshadowShader_fp, PSHADOW_UNIFORM_COUNT))
{
@ -2092,7 +2116,7 @@ void GLSL_InitGPUShaders(void)
extradefines[0] = '\0';
if (!i)
Q_strcat(extradefines, 1024, "#define FIRST_PASS");
Q_strcat(extradefines, 1024, "#define FIRST_PASS\n");
if (!GLSL_InitGPUShader(&tr.calclevels4xShader[i], "calclevels4x", attribs, qtrue, extradefines, qtrue, fallbackCalcLevels4xShader_vp, fallbackCalcLevels4xShader_fp, TEXTURECOLOR_UNIFORM_COUNT))
{
@ -2117,6 +2141,54 @@ void GLSL_InitGPUShaders(void)
}
attribs = ATTR_POSITION | ATTR_TEXCOORD;
extradefines[0] = '\0';
if (r_shadowFilter->integer >= 1)
Q_strcat(extradefines, 1024, "#define USE_SHADOW_FILTER\n");
if (r_shadowFilter->integer >= 2)
Q_strcat(extradefines, 1024, "#define USE_SHADOW_FILTER2\n");
Q_strcat(extradefines, 1024, "#define USE_SHADOW_CASCADE\n");
Q_strcat(extradefines, 1024, va("#define r_shadowMapSize %d\n", r_shadowMapSize->integer));
Q_strcat(extradefines, 1024, va("#define r_shadowCascadeZFar %f\n", r_shadowCascadeZFar->value));
if (!GLSL_InitGPUShader(&tr.shadowmaskShader, "shadowmask", attribs, qtrue, extradefines, qtrue, fallbackShadowmaskShader_vp, fallbackShadowmaskShader_fp, SHADOWMASK_UNIFORM_COUNT))
{
ri.Error(ERR_FATAL, "Could not load shadowmask shader!\n");
}
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMVP, "u_ShadowMvp", GLSL_MAT16);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMVP2, "u_ShadowMvp2", GLSL_MAT16);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMVP3, "u_ShadowMvp3", GLSL_MAT16);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWORIGIN, "u_ViewOrigin", GLSL_VEC3);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWINFO, "u_ViewInfo", GLSL_VEC4);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWFORWARD,"u_ViewForward", GLSL_VEC3);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWLEFT, "u_ViewLeft", GLSL_VEC3);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_VIEWUP, "u_ViewUp", GLSL_VEC3);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SCREENDEPTHMAP, "u_ScreenDepthMap", GLSL_INT);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMAP, "u_ShadowMap", GLSL_INT);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMAP2, "u_ShadowMap2", GLSL_INT);
GLSL_AddUniform(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMAP3, "u_ShadowMap3", GLSL_INT);
GLSL_EndUniforms(&tr.shadowmaskShader);
qglUseProgramObjectARB(tr.shadowmaskShader.program);
GLSL_SetUniformInt(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SCREENDEPTHMAP, TB_COLORMAP);
GLSL_SetUniformInt(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMAP, TB_SHADOWMAP);
GLSL_SetUniformInt(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMAP2, TB_SHADOWMAP2);
GLSL_SetUniformInt(&tr.shadowmaskShader, SHADOWMASK_UNIFORM_SHADOWMAP3, TB_SHADOWMAP3);
qglUseProgramObjectARB(0);
GLSL_FinishGPUShader(&tr.shadowmaskShader);
numEtcShaders++;
endTime = ri.Milliseconds();
ri.Printf(PRINT_ALL, "loaded %i GLSL shaders (%i gen %i light %i etc) in %5.2f seconds\n",
@ -2157,6 +2229,9 @@ void GLSL_InitGPUShaders(void)
GLSL_LoadGPUShaderText("CalcLevels4x", NULL, GL_VERTEX_SHADER_ARB, NULL, 0, qtrue);
GLSL_LoadGPUShaderText("CalcLevels4x", NULL, GL_FRAGMENT_SHADER_ARB, NULL, 0, qtrue);
GLSL_LoadGPUShaderText("Shadowmask", NULL, GL_VERTEX_SHADER_ARB, NULL, 0, qtrue);
GLSL_LoadGPUShaderText("Shadowmask", NULL, GL_FRAGMENT_SHADER_ARB, NULL, 0, qtrue);
}
}

View file

@ -2278,6 +2278,22 @@ static void EmptyTexture( int width, int height, imgType_t type, imgFlags_t flag
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
// Fix for sampling depth buffer on old nVidia cards
// from http://www.idevgames.com/forums/thread-4141-post-34844.html#pid34844
switch(internalFormat)
{
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16_ARB:
case GL_DEPTH_COMPONENT24_ARB:
case GL_DEPTH_COMPONENT32_ARB:
qglTexParameterf(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE );
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
break;
default:
break;
}
GL_CheckErrors();
}
@ -2977,6 +2993,8 @@ void R_CreateBuiltinImages( void ) {
{
tr.quarterImage[x] = R_CreateImage(va("*quarter%d", x), NULL, 512, 512, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
}
tr.screenShadowImage = R_CreateImage("*screenShadow", NULL, width, height, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
}
for( x = 0; x < MAX_DRAWN_PSHADOWS; x++)
@ -2987,7 +3005,7 @@ void R_CreateBuiltinImages( void ) {
//tr.sunShadowImage = R_CreateImage("*sunshadowmap", NULL, SUNSHADOW_MAP_SIZE, SUNSHADOW_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_RGBA8);
for ( x = 0; x < 3; x++)
{
tr.sunShadowDepthImage[x] = R_CreateImage(va("*sunshadowdepth%i", x), NULL, SUNSHADOW_MAP_SIZE, SUNSHADOW_MAP_SIZE, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT16_ARB);
tr.sunShadowDepthImage[x] = R_CreateImage(va("*sunshadowdepth%i", x), NULL, r_shadowMapSize->integer, r_shadowMapSize->integer, IMGTYPE_COLORALPHA, IMGFLAG_NO_COMPRESSION | IMGFLAG_CLAMPTOEDGE, GL_DEPTH_COMPONENT24_ARB);
}
}

View file

@ -128,7 +128,16 @@ cvar_t *r_imageUpsample;
cvar_t *r_imageUpsampleMaxSize;
cvar_t *r_imageUpsampleType;
cvar_t *r_genNormalMaps;
cvar_t *r_testSunlight;
cvar_t *r_forceSun;
cvar_t *r_forceSunMapLightScale;
cvar_t *r_forceSunLightScale;
cvar_t *r_forceSunAmbientScale;
cvar_t *r_sunShadows;
cvar_t *r_shadowFilter;
cvar_t *r_shadowMapSize;
cvar_t *r_shadowCascadeZNear;
cvar_t *r_shadowCascadeZFar;
cvar_t *r_shadowCascadeZBias;
cvar_t *r_ignoreGLErrors;
cvar_t *r_logFile;
@ -1137,7 +1146,7 @@ void R_Register( void )
r_cameraExposure = ri.Cvar_Get( "r_cameraExposure", "0", CVAR_CHEAT );
r_srgb = ri.Cvar_Get( "r_srgb", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_depthPrepass = ri.Cvar_Get( "r_depthPrepass", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_depthPrepass = ri.Cvar_Get( "r_depthPrepass", "1", CVAR_ARCHIVE );
r_normalMapping = ri.Cvar_Get( "r_normalMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_specularMapping = ri.Cvar_Get( "r_specularMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
@ -1152,7 +1161,17 @@ void R_Register( void )
r_imageUpsampleMaxSize = ri.Cvar_Get( "r_imageUpsampleMaxSize", "1024", CVAR_ARCHIVE | CVAR_LATCH );
r_imageUpsampleType = ri.Cvar_Get( "r_imageUpsampleType", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_genNormalMaps = ri.Cvar_Get( "r_genNormalMaps", "0", CVAR_ARCHIVE | CVAR_LATCH );
r_testSunlight = ri.Cvar_Get( "r_testSunlight", "0", CVAR_CHEAT );
r_forceSun = ri.Cvar_Get( "r_forceSun", "0", CVAR_CHEAT );
r_forceSunMapLightScale = ri.Cvar_Get( "r_forceSunMapLightScale", "0.5", CVAR_CHEAT );
r_forceSunLightScale = ri.Cvar_Get( "r_forceSunLightScale", "0.5", CVAR_CHEAT );
r_forceSunAmbientScale = ri.Cvar_Get( "r_forceSunAmbientScale", "0.2", CVAR_CHEAT );
r_sunShadows = ri.Cvar_Get( "r_sunShadows", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_shadowFilter = ri.Cvar_Get( "r_shadowFilter", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_shadowMapSize = ri.Cvar_Get( "r_shadowMapSize", "1024", CVAR_ARCHIVE | CVAR_LATCH );
r_shadowCascadeZNear = ri.Cvar_Get( "r_shadowCascadeZNear", "4", CVAR_ARCHIVE | CVAR_LATCH );
r_shadowCascadeZFar = ri.Cvar_Get( "r_shadowCascadeZFar", "3072", CVAR_ARCHIVE | CVAR_LATCH );
r_shadowCascadeZBias = ri.Cvar_Get( "r_shadowCascadeZBias", "-320", CVAR_ARCHIVE | CVAR_LATCH );
//
// temporary latched variables that can only change over a restart

View file

@ -67,7 +67,6 @@ typedef unsigned int glIndex_t;
#define MAX_CALC_PSHADOWS 64
#define MAX_DRAWN_PSHADOWS 16 // do not increase past 32, because bit flags are used on surfaces
#define PSHADOW_MAP_SIZE 512
#define SUNSHADOW_MAP_SIZE 1024
#define USE_VERT_TANGENT_SPACE
@ -743,11 +742,10 @@ enum
LIGHTDEF_USE_DELUXEMAP = 0x0010,
LIGHTDEF_USE_PARALLAXMAP = 0x0020,
LIGHTDEF_USE_SHADOWMAP = 0x0040,
LIGHTDEF_USE_SHADOW_CASCADE= 0x0080,
LIGHTDEF_TCGEN_ENVIRONMENT = 0x0100,
LIGHTDEF_ENTITY = 0x0200,
LIGHTDEF_ALL = 0x03FF,
LIGHTDEF_COUNT = 0x0400
LIGHTDEF_TCGEN_ENVIRONMENT = 0x0080,
LIGHTDEF_ENTITY = 0x0100,
LIGHTDEF_ALL = 0x01FF,
LIGHTDEF_COUNT = 0x0200
};
enum
@ -843,8 +841,6 @@ enum
GENERIC_UNIFORM_DELUXEMAP,
GENERIC_UNIFORM_SPECULARMAP,
GENERIC_UNIFORM_SHADOWMAP,
GENERIC_UNIFORM_SHADOWMAP2,
GENERIC_UNIFORM_SHADOWMAP3,
GENERIC_UNIFORM_DIFFUSETEXMATRIX,
//GENERIC_UNIFORM_NORMALTEXMATRIX,
//GENERIC_UNIFORM_SPECULARTEXMATRIX,
@ -873,13 +869,26 @@ enum
GENERIC_UNIFORM_TIME,
GENERIC_UNIFORM_VERTEXLERP,
GENERIC_UNIFORM_MATERIALINFO,
GENERIC_UNIFORM_SHADOWMVP,
GENERIC_UNIFORM_SHADOWMVP2,
GENERIC_UNIFORM_SHADOWMVP3,
GENERIC_UNIFORM_MAPLIGHTSCALE,
GENERIC_UNIFORM_COUNT
};
enum
{
SHADOWMASK_UNIFORM_SCREENDEPTHMAP = 0,
SHADOWMASK_UNIFORM_SHADOWMAP,
SHADOWMASK_UNIFORM_SHADOWMAP2,
SHADOWMASK_UNIFORM_SHADOWMAP3,
SHADOWMASK_UNIFORM_SHADOWMVP,
SHADOWMASK_UNIFORM_SHADOWMVP2,
SHADOWMASK_UNIFORM_SHADOWMVP3,
SHADOWMASK_UNIFORM_VIEWORIGIN,
SHADOWMASK_UNIFORM_VIEWINFO, // znear, zfar, width/2, height/2
SHADOWMASK_UNIFORM_VIEWFORWARD,
SHADOWMASK_UNIFORM_VIEWLEFT,
SHADOWMASK_UNIFORM_VIEWUP,
SHADOWMASK_UNIFORM_COUNT
};
//
// Tr3B: these are fire wall functions to avoid expensive redundant glUniform* calls
//#define USE_UNIFORM_FIREWALL 1
@ -928,7 +937,8 @@ typedef struct {
float sunShadowMvp[3][16];
float sunDir[4];
float sunCol[4];
float mapLightScale;
float sunAmbCol[4];
float colorScale;
} trRefdef_t;
@ -961,11 +971,12 @@ typedef struct {
} fog_t;
typedef enum {
VPF_NONE = 0x00,
VPF_SHADOWMAP = 0x01,
VPF_DEPTHSHADOW = 0x02,
VPF_DEPTHCLAMP = 0x04,
VPF_ORTHOGRAPHIC = 0x08,
VPF_NONE = 0x00,
VPF_SHADOWMAP = 0x01,
VPF_DEPTHSHADOW = 0x02,
VPF_DEPTHCLAMP = 0x04,
VPF_ORTHOGRAPHIC = 0x08,
VPF_USESUNLIGHT = 0x10,
} viewParmFlags_t;
typedef struct {
@ -1601,7 +1612,7 @@ typedef struct {
// the renderer front end should never modify glstate_t
typedef struct {
int currenttextures[2];
int currenttextures[NUM_TEXTURE_BUNDLES];
int currenttmu;
qboolean finishCalled;
int texEnv[2];
@ -1780,6 +1791,7 @@ typedef struct {
image_t *targetLevelsImage;
image_t *fixedLevelsImage;
image_t *sunShadowDepthImage[3];
image_t *screenShadowImage;
image_t *textureDepthImage;
@ -1794,6 +1806,7 @@ typedef struct {
FBO_t *calcLevelsFbo;
FBO_t *targetLevelsFbo;
FBO_t *sunShadowFbo[3];
FBO_t *screenShadowFbo;
shader_t *defaultShader;
shader_t *shadowShader;
@ -1830,6 +1843,7 @@ typedef struct {
shaderProgram_t bokehShader;
shaderProgram_t tonemapShader;
shaderProgram_t calclevels4xShader[2];
shaderProgram_t shadowmaskShader;
// -----------------------------------------
@ -1850,6 +1864,7 @@ typedef struct {
qboolean sunShadows;
vec3_t sunLight; // from the sky shader for this level
vec3_t sunAmbient;
vec3_t sunDirection;
frontEndCounters_t pc;
@ -2052,7 +2067,16 @@ extern cvar_t *r_imageUpsample;
extern cvar_t *r_imageUpsampleMaxSize;
extern cvar_t *r_imageUpsampleType;
extern cvar_t *r_genNormalMaps;
extern cvar_t *r_testSunlight;
extern cvar_t *r_forceSun;
extern cvar_t *r_forceSunMapLightScale;
extern cvar_t *r_forceSunLightScale;
extern cvar_t *r_forceSunAmbientScale;
extern cvar_t *r_sunShadows;
extern cvar_t *r_shadowFilter;
extern cvar_t *r_shadowMapSize;
extern cvar_t *r_shadowCascadeZNear;
extern cvar_t *r_shadowCascadeZFar;
extern cvar_t *r_shadowCascadeZBias;
extern cvar_t *r_greyscale;
@ -2334,7 +2358,8 @@ void RB_StageIteratorLightmappedMultitexture( void );
void RB_AddQuadStamp( vec3_t origin, vec3_t left, vec3_t up, float color[4] );
void RB_AddQuadStampExt( vec3_t origin, vec3_t left, vec3_t up, float color[4], float s1, float t1, float s2, float t2 );
void RB_InstantQuad( vec4_t quadVerts[4] );
void RB_InstantQuad2(vec4_t quadVerts[4], vec2_t texCoords[4], vec4_t color, shaderProgram_t *sp, vec2_t invTexRes);
//void RB_InstantQuad2(vec4_t quadVerts[4], vec2_t texCoords[4], vec4_t color, shaderProgram_t *sp, vec2_t invTexRes);
void RB_InstantQuad2(vec4_t quadVerts[4], vec2_t texCoords[4]);
void RB_ShowImages( void );

View file

@ -1905,7 +1905,7 @@ void R_SortDrawSurfs( drawSurf_t *drawSurfs, int numDrawSurfs ) {
R_RadixSort( drawSurfs, numDrawSurfs );
// skip pass through drawing if rendering a shadow map
if ((tr.viewParms.flags & VPF_SHADOWMAP) || (tr.viewParms.flags & VPF_DEPTHSHADOW))
if (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))
{
R_AddDrawSurfCmd( drawSurfs, numDrawSurfs );
return;
@ -1958,7 +1958,7 @@ static void R_AddEntitySurface (int entityNum)
// mirrors, because the true body position will already be drawn
//
if ( (ent->e.renderfx & RF_FIRST_PERSON) && (tr.viewParms.isPortal
|| (tr.viewParms.flags & VPF_SHADOWMAP) || (tr.viewParms.flags & VPF_DEPTHSHADOW))) {
|| (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW))) ) {
return;
}
@ -2587,18 +2587,24 @@ void R_RenderPshadowMaps(const refdef_t *fd)
}
}
static float CalcSplit(float n, float f, float i, float m)
{
return (n * pow(f / n, i / m) + (f - n) * i / m) / 2.0f;
}
void R_RenderSunShadowMaps(const refdef_t *fd, int level)
{
viewParms_t shadowParms;
vec4_t lightDir, lightCol;
vec3_t up;
vec3_t lightViewAxis[3];
vec3_t lightOrigin;
float viewznear, viewzfar;
float splitZNear, splitZFar, splitBias;
float viewZNear, viewZFar;
vec3_t lightviewBounds[2];
qboolean lightViewIndependentOfCameraView = qfalse;
if (r_testSunlight->integer == 2)
if (r_forceSun->integer == 2)
{
int scale = 32768;
float angle = (fd->time % scale) / (float)scale * M_PI;
@ -2624,58 +2630,90 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level)
VectorCopy4(lightDir, tr.refdef.sunDir);
VectorCopy4(lightCol, tr.refdef.sunCol);
VectorScale4(lightCol, 0.2f, tr.refdef.sunAmbCol);
}
else
{
VectorCopy4(tr.refdef.sunDir, lightDir);
}
viewZNear = r_shadowCascadeZNear->value;
viewZFar = r_shadowCascadeZFar->value;
splitBias = r_shadowCascadeZBias->value;
switch(level)
{
case 0:
default:
//viewznear = r_znear->value;
//viewzfar = 256;
viewznear = r_znear->value;
viewzfar = 128;
//splitZNear = r_znear->value;
//splitZFar = 256;
splitZNear = viewZNear;
splitZFar = CalcSplit(viewZNear, viewZFar, 1, 3) + splitBias;
break;
case 1:
viewznear = 128;
viewzfar = 384;
//viewznear = 256;
//viewzfar = 896;
splitZNear = CalcSplit(viewZNear, viewZFar, 1, 3) + splitBias;
splitZFar = CalcSplit(viewZNear, viewZFar, 2, 3) + splitBias;
//splitZNear = 256;
//splitZFar = 896;
break;
case 2:
viewznear = 384;
viewzfar = 1024;
//viewznear = 896;
//viewzfar = 3072;
splitZNear = CalcSplit(viewZNear, viewZFar, 2, 3) + splitBias;
splitZFar = viewZFar;
//splitZNear = 896;
//splitZFar = 3072;
break;
}
VectorCopy(fd->vieworg, lightOrigin);
// make up a projection
// Make up a projection
VectorScale(lightDir, -1.0f, lightViewAxis[0]);
// try to use halfway between player right and player forward as up
//VectorCopy(fd->viewaxis[1], up);
VectorScale(fd->viewaxis[0], 0.5f, up);
VectorMA(up, 0.5f, fd->viewaxis[1], up);
if ( abs(DotProduct(up, lightViewAxis[0])) > 0.9f )
if (lightViewIndependentOfCameraView)
{
// if not, halfway between player up and player forward
//VectorCopy(fd->viewaxis[2], up);
VectorScale(fd->viewaxis[0], 0.5f, up);
VectorMA(up, 0.5f, fd->viewaxis[2], up);
// Use world up as light view up
VectorSet(lightViewAxis[2], 0, 0, 1);
}
else if (level == 0)
{
// Level 0 tries to use a diamond texture orientation relative to camera view
// Use halfway between camera view forward and left for light view up
VectorAdd(fd->viewaxis[0], fd->viewaxis[1], lightViewAxis[2]);
}
else
{
// Use camera view up as light view up
VectorCopy(fd->viewaxis[2], lightViewAxis[2]);
}
CrossProduct(lightViewAxis[0], up, lightViewAxis[1]);
// Check if too close to parallel to light direction
if (abs(DotProduct(lightViewAxis[2], lightViewAxis[0])) > 0.9f)
{
if (lightViewIndependentOfCameraView)
{
// Use world left as light view up
VectorSet(lightViewAxis[2], 0, 1, 0);
}
else if (level == 0)
{
// Level 0 tries to use a diamond texture orientation relative to camera view
// Use halfway between camera view forward and up for light view up
VectorAdd(fd->viewaxis[0], fd->viewaxis[2], lightViewAxis[2]);
}
else
{
// Use camera view left as light view up
VectorCopy(fd->viewaxis[1], lightViewAxis[2]);
}
}
// clean axes
CrossProduct(lightViewAxis[2], lightViewAxis[0], lightViewAxis[1]);
VectorNormalize(lightViewAxis[1]);
CrossProduct(lightViewAxis[0], lightViewAxis[1], lightViewAxis[2]);
// Create bounds for light projection using slice of view projection
{
matrix_t lightViewMatrix;
vec4_t point, base, lightViewPoint;
@ -2685,32 +2723,14 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level)
point[3] = 1;
lightViewPoint[3] = 1;
lightViewMatrix[0] = lightViewAxis[0][0];
lightViewMatrix[1] = lightViewAxis[1][0];
lightViewMatrix[2] = lightViewAxis[2][0];
lightViewMatrix[3] = 0;
lightViewMatrix[4] = lightViewAxis[0][1];
lightViewMatrix[5] = lightViewAxis[1][1];
lightViewMatrix[6] = lightViewAxis[2][1];
lightViewMatrix[7] = 0;
lightViewMatrix[8] = lightViewAxis[0][2];
lightViewMatrix[9] = lightViewAxis[1][2];
lightViewMatrix[10] = lightViewAxis[2][2];
lightViewMatrix[11] = 0;
lightViewMatrix[12] = -DotProduct(lightOrigin, lightViewAxis[0]);
lightViewMatrix[13] = -DotProduct(lightOrigin, lightViewAxis[1]);
lightViewMatrix[14] = -DotProduct(lightOrigin, lightViewAxis[2]);
lightViewMatrix[15] = 1;
Matrix16View(lightViewAxis, lightOrigin, lightViewMatrix);
ClearBounds(lightviewBounds[0], lightviewBounds[1]);
// add view near plane
lx = viewznear * tan(fd->fov_x * M_PI / 360.0f);
ly = viewznear * tan(fd->fov_y * M_PI / 360.0f);
VectorMA(fd->vieworg, viewznear, fd->viewaxis[0], base);
lx = splitZNear * tan(fd->fov_x * M_PI / 360.0f);
ly = splitZNear * tan(fd->fov_y * M_PI / 360.0f);
VectorMA(fd->vieworg, splitZNear, fd->viewaxis[0], base);
VectorMA(base, lx, fd->viewaxis[1], point);
VectorMA(point, ly, fd->viewaxis[2], point);
@ -2734,9 +2754,9 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level)
// add view far plane
lx = viewzfar * tan(fd->fov_x * M_PI / 360.0f);
ly = viewzfar * tan(fd->fov_y * M_PI / 360.0f);
VectorMA(fd->vieworg, viewzfar, fd->viewaxis[0], base);
lx = splitZFar * tan(fd->fov_x * M_PI / 360.0f);
ly = splitZFar * tan(fd->fov_y * M_PI / 360.0f);
VectorMA(fd->vieworg, splitZFar, fd->viewaxis[0], base);
VectorMA(base, lx, fd->viewaxis[1], point);
VectorMA(point, ly, fd->viewaxis[2], point);
@ -2761,6 +2781,31 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level)
if (!glRefConfig.depthClamp)
lightviewBounds[0][0] = lightviewBounds[1][0] - 8192;
// Moving the Light in Texel-Sized Increments
// from http://msdn.microsoft.com/en-us/library/windows/desktop/ee416324%28v=vs.85%29.aspx
//
if (lightViewIndependentOfCameraView)
{
float cascadeBound, worldUnitsPerTexel, invWorldUnitsPerTexel;
cascadeBound = MAX(lightviewBounds[1][0] - lightviewBounds[0][0], lightviewBounds[1][1] - lightviewBounds[0][1]);
cascadeBound = MAX(cascadeBound, lightviewBounds[1][2] - lightviewBounds[0][2]);
worldUnitsPerTexel = cascadeBound / tr.sunShadowFbo[level]->width;
invWorldUnitsPerTexel = 1.0f / worldUnitsPerTexel;
VectorScale(lightviewBounds[0], invWorldUnitsPerTexel, lightviewBounds[0]);
lightviewBounds[0][0] = floor(lightviewBounds[0][0]);
lightviewBounds[0][1] = floor(lightviewBounds[0][1]);
lightviewBounds[0][2] = floor(lightviewBounds[0][2]);
VectorScale(lightviewBounds[0], worldUnitsPerTexel, lightviewBounds[0]);
VectorScale(lightviewBounds[1], invWorldUnitsPerTexel, lightviewBounds[1]);
lightviewBounds[1][0] = floor(lightviewBounds[1][0]);
lightviewBounds[1][1] = floor(lightviewBounds[1][1]);
lightviewBounds[1][2] = floor(lightviewBounds[1][2]);
VectorScale(lightviewBounds[1], worldUnitsPerTexel, lightviewBounds[1]);
}
//ri.Printf(PRINT_ALL, "znear %f zfar %f\n", lightviewBounds[0][0], lightviewBounds[1][0]);
//ri.Printf(PRINT_ALL, "fovx %f fovy %f xmin %f xmax %f ymin %f ymax %f\n", fd->fov_x, fd->fov_y, xmin, xmax, ymin, ymax);
}
@ -2779,10 +2824,10 @@ void R_RenderSunShadowMaps(const refdef_t *fd, int level)
else
{
shadowParms.viewportX = tr.refdef.x;
shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + SUNSHADOW_MAP_SIZE );
shadowParms.viewportY = glConfig.vidHeight - ( tr.refdef.y + tr.sunShadowFbo[level]->height );
}
shadowParms.viewportWidth = SUNSHADOW_MAP_SIZE;
shadowParms.viewportHeight = SUNSHADOW_MAP_SIZE;
shadowParms.viewportWidth = tr.sunShadowFbo[level]->width;
shadowParms.viewportHeight = tr.sunShadowFbo[level]->height;
shadowParms.isPortal = qfalse;
shadowParms.isMirror = qfalse;

View file

@ -296,7 +296,7 @@ void R_AddMD3Surfaces( trRefEntity_t *ent ) {
// don't add third_person objects if not in a portal
personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && !(tr.viewParms.isPortal
|| (tr.viewParms.flags & VPF_SHADOWMAP) || (tr.viewParms.flags & VPF_DEPTHSHADOW));
|| (tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW)));
if ( ent->e.renderfx & RF_WRAP_FRAMES ) {
ent->e.frame %= tr.currentModel->mdv[0]->numFrames;

View file

@ -367,17 +367,27 @@ void RE_RenderScene( const refdef_t *fd ) {
tr.refdef.sunDir[3] = 0.0f;
tr.refdef.sunCol[3] = 1.0f;
tr.refdef.sunAmbCol[3] = 1.0f;
VectorCopy(tr.sunDirection, tr.refdef.sunDir);
if (r_testSunlight->integer == 1)
if ( (tr.refdef.rdflags & RDF_NOWORLDMODEL) || !(r_depthPrepass->value) ){
tr.refdef.colorScale = 1.0f;
VectorSet(tr.refdef.sunCol, 0, 0, 0);
VectorSet(tr.refdef.sunAmbCol, 0, 0, 0);
}
else if (r_forceSun->integer == 1)
{
tr.refdef.mapLightScale = 0.66f;
VectorScale(tr.sunLight, pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8) * 0.33f, tr.refdef.sunCol);
float scale = pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8);
tr.refdef.colorScale = r_forceSunMapLightScale->value;
VectorScale(tr.sunLight, scale * r_forceSunLightScale->value, tr.refdef.sunCol);
VectorScale(tr.sunLight, scale * r_forceSunAmbientScale->value, tr.refdef.sunAmbCol);
}
else
{
tr.refdef.mapLightScale = tr.mapLightScale;
VectorScale(tr.sunLight, pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8), tr.refdef.sunCol);
float scale = pow(2, r_mapOverBrightBits->integer - tr.overbrightBits - 8);
tr.refdef.colorScale = tr.mapLightScale;
VectorScale(tr.sunLight, scale, tr.refdef.sunCol);
VectorScale(tr.sunAmbient, scale, tr.refdef.sunAmbCol);
}
//#ifdef REACTION
@ -389,8 +399,9 @@ void RE_RenderScene( const refdef_t *fd ) {
if (fd->rdflags & RDF_SUNLIGHT)
{
VectorCopy(extra->sunDir, tr.refdef.sunDir);
VectorCopy(extra->sunCol, tr.refdef.sunCol);
VectorCopy(extra->sunDir, tr.refdef.sunDir);
VectorCopy(extra->sunCol, tr.refdef.sunCol);
VectorCopy(extra->sunAmbCol, tr.refdef.sunAmbCol);
}
}
else
@ -447,7 +458,7 @@ void RE_RenderScene( const refdef_t *fd ) {
}
// playing with even more shadows
if(!( fd->rdflags & RDF_NOWORLDMODEL ) && (r_testSunlight->integer || tr.sunShadows))
if(!( fd->rdflags & RDF_NOWORLDMODEL ) && (r_forceSun->integer || tr.sunShadows))
{
R_RenderSunShadowMaps(fd, 0);
R_RenderSunShadowMaps(fd, 1);
@ -484,6 +495,11 @@ void RE_RenderScene( const refdef_t *fd ) {
VectorCopy( fd->vieworg, parms.pvsOrigin );
if(!( fd->rdflags & RDF_NOWORLDMODEL ) && r_depthPrepass->value && ((r_forceSun->integer) || tr.sunShadows))
{
parms.flags = VPF_USESUNLIGHT;
}
R_RenderView( &parms );
if(!( fd->rdflags & RDF_NOWORLDMODEL ))

View file

@ -809,8 +809,7 @@ static void ForwardDlight( void ) {
// where they aren't rendered
GL_State( GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHFUNC_EQUAL );
Matrix16Identity(matrix);
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, matrix);
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, backEnd.or.transformMatrix);
if (pStage->bundle[TB_DIFFUSEMAP].image[0])
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DIFFUSEMAP], TB_DIFFUSEMAP);
@ -905,7 +904,7 @@ static void ForwardSunlight( void ) {
{
shaderStage_t *pStage = input->xstages[stage];
shaderProgram_t *sp;
vec4_t vector;
//vec4_t vector;
matrix_t matrix;
if ( !pStage )
@ -920,7 +919,12 @@ static void ForwardSunlight( void ) {
int index = pStage->glslShaderIndex;
index &= ~(LIGHTDEF_LIGHTTYPE_MASK | LIGHTDEF_USE_DELUXEMAP);
index |= LIGHTDEF_USE_LIGHT_VECTOR | LIGHTDEF_USE_SHADOWMAP | LIGHTDEF_USE_SHADOW_CASCADE;
index |= LIGHTDEF_USE_LIGHT_VECTOR | LIGHTDEF_USE_SHADOWMAP;
if (backEnd.currentEntity && backEnd.currentEntity != &tr.worldEntity)
{
index |= LIGHTDEF_ENTITY;
}
sp = &tr.lightallShader[index];
}
@ -986,12 +990,8 @@ static void ForwardSunlight( void ) {
GLSL_SetUniformInt(sp, GENERIC_UNIFORM_ALPHAGEN, pStage->alphaGen);
GLSL_SetUniformVec3(sp, GENERIC_UNIFORM_DIRECTEDLIGHT, backEnd.refdef.sunCol);
GLSL_SetUniformVec3(sp, GENERIC_UNIFORM_AMBIENTLIGHT, backEnd.refdef.sunAmbCol);
VectorSet(vector, 0, 0, 0);
GLSL_SetUniformVec3(sp, GENERIC_UNIFORM_AMBIENTLIGHT, vector);
//VectorSet4(vector, 0, 0, 1, 0);
//VectorSet4(vector, 0.57735f, 0.57735f, 0.57735f, 0);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_LIGHTORIGIN, backEnd.refdef.sunDir);
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_LIGHTRADIUS, 9999999999);
@ -1000,8 +1000,7 @@ static void ForwardSunlight( void ) {
GL_State( stageGlState[stage] );
Matrix16Identity(matrix);
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, matrix);
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, backEnd.or.transformMatrix);
if (pStage->bundle[TB_DIFFUSEMAP].image[0])
R_BindAnimatedImageToTMU( &pStage->bundle[TB_DIFFUSEMAP], TB_DIFFUSEMAP);
@ -1012,6 +1011,7 @@ static void ForwardSunlight( void ) {
if (pStage->bundle[TB_SPECULARMAP].image[0])
R_BindAnimatedImageToTMU( &pStage->bundle[TB_SPECULARMAP], TB_SPECULARMAP);
/*
{
GL_BindToTMU(tr.sunShadowDepthImage[0], TB_SHADOWMAP);
GL_BindToTMU(tr.sunShadowDepthImage[1], TB_SHADOWMAP2);
@ -1020,6 +1020,8 @@ static void ForwardSunlight( void ) {
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_SHADOWMVP2, backEnd.refdef.sunShadowMvp[1]);
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_SHADOWMVP3, backEnd.refdef.sunShadowMvp[2]);
}
*/
GL_BindToTMU(tr.screenShadowImage, TB_SHADOWMAP);
ComputeTexMatrix( pStage, TB_DIFFUSEMAP, matrix );
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_DIFFUSETEXMATRIX, matrix);
@ -1312,9 +1314,44 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
{
vec4_t baseColor;
vec4_t vertColor;
qboolean tint = qtrue;
int stage2;
ComputeShaderColors(pStage, baseColor, vertColor);
for ( stage2 = stage + 1; stage2 < MAX_SHADER_STAGES; stage2++ )
{
shaderStage_t *pStage2 = input->xstages[stage2];
unsigned int srcBlendBits, dstBlendBits;
if ( !pStage2 )
{
break;
}
srcBlendBits = pStage2->stateBits & GLS_SRCBLEND_BITS;
dstBlendBits = pStage2->stateBits & GLS_DSTBLEND_BITS;
if (srcBlendBits == GLS_SRCBLEND_DST_COLOR)
{
tint = qfalse;
break;
}
}
if (!((tr.sunShadows || r_forceSun->integer) && tess.shader->sort <= SS_OPAQUE
&& !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY) ) && tess.xstages[0]->glslShaderGroup == tr.lightallShader))
{
tint = qfalse;
}
if (tint)
{
// use vectorscale to only scale first three values, not alpha
VectorScale(baseColor, backEnd.refdef.colorScale, baseColor);
VectorScale(vertColor, backEnd.refdef.colorScale, vertColor);
}
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_BASECOLOR, baseColor);
GLSL_SetUniformVec4(sp, GENERIC_UNIFORM_VERTCOLOR, vertColor);
}
@ -1371,7 +1408,7 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input )
GLSL_SetUniformVec2(sp, GENERIC_UNIFORM_MATERIALINFO, pStage->materialInfo);
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_MAPLIGHTSCALE, backEnd.refdef.mapLightScale);
//GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_MAPLIGHTSCALE, backEnd.refdef.mapLightScale);
//
// do multitexture
@ -1496,16 +1533,7 @@ static void RB_RenderShadowmap( shaderCommands_t *input )
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
if (backEnd.currentEntity && backEnd.currentEntity != &tr.worldEntity)
{
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, backEnd.or.transformMatrix);
}
else
{
matrix_t matrix;
Matrix16Identity(matrix);
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, matrix);
}
GLSL_SetUniformMatrix16(sp, GENERIC_UNIFORM_MODELMATRIX, backEnd.or.transformMatrix);
GLSL_SetUniformFloat(sp, GENERIC_UNIFORM_VERTEXLERP, glState.vertexAttribsInterpolation);
@ -1592,15 +1620,15 @@ void RB_StageIteratorGeneric( void )
//
if ((backEnd.viewParms.flags & VPF_DEPTHSHADOW))
{
GL_Cull( CT_TWO_SIDED );
/*
//GL_Cull( CT_TWO_SIDED );
if (input->shader->cullType == CT_TWO_SIDED)
GL_Cull( CT_TWO_SIDED );
else if (input->shader->cullType == CT_FRONT_SIDED)
GL_Cull( CT_BACK_SIDED );
else
GL_Cull( CT_FRONT_SIDED );
*/
}
else
GL_Cull( input->shader->cullType );
@ -1686,7 +1714,8 @@ void RB_StageIteratorGeneric( void )
}
}
if ((tr.sunShadows || r_testSunlight->integer) && tess.shader->sort <= SS_OPAQUE
if ((backEnd.viewParms.flags & VPF_USESUNLIGHT) && tess.shader->sort <= SS_OPAQUE
//if ((tr.sunShadows || r_forceSunlight->value > 0.0f) && tess.shader->sort <= SS_OPAQUE
&& !(tess.shader->surfaceFlags & (SURF_NODLIGHT | SURF_SKY) ) && tess.xstages[0]->glslShaderGroup == tr.lightallShader) {
ForwardSunlight();
}

View file

@ -1608,9 +1608,13 @@ static qboolean ParseShader( char **text )
// sun parms
else if ( !Q_stricmp( token, "q3map_sun" ) || !Q_stricmp( token, "q3map_sunExt" ) || !Q_stricmp( token, "q3gl2_sun" ) ) {
float a, b;
qboolean isGL2Sun = qfalse;
if (!Q_stricmp( token, "q3gl2_sun" ) )
if (!Q_stricmp( token, "q3gl2_sun" ) && r_sunShadows->integer )
{
isGL2Sun = qtrue;
tr.sunShadows = qtrue;
}
token = COM_ParseExt( text, qfalse );
tr.sunLight[0] = atof( token );
@ -1625,6 +1629,8 @@ static qboolean ParseShader( char **text )
a = atof( token );
VectorScale( tr.sunLight, a, tr.sunLight);
VectorSet( tr.sunAmbient, 0.0f, 0.0f, 0.0f);
token = COM_ParseExt( text, qfalse );
a = atof( token );
a = a / 180 * M_PI;
@ -1637,6 +1643,15 @@ static qboolean ParseShader( char **text )
tr.sunDirection[1] = sin( a ) * cos( b );
tr.sunDirection[2] = sin( b );
if (isGL2Sun)
{
token = COM_ParseExt( text, qfalse );
tr.mapLightScale = atof(token);
token = COM_ParseExt( text, qfalse );
VectorScale( tr.sunLight, atof(token), tr.sunAmbient );
}
SkipRestOfLine( text );
}
else if ( !Q_stricmp( token, "deformVertexes" ) ) {
@ -3511,7 +3526,21 @@ static void ScanAndLoadShaderFiles( void )
{
char filename[MAX_QPATH];
Com_sprintf( filename, sizeof( filename ), "scripts/%s", shaderFiles[i] );
// look for a .mtr file first
{
char *ext;
Com_sprintf( filename, sizeof( filename ), "scripts/%s", shaderFiles[i] );
if ( (ext = strrchr(filename, '.')) )
{
strcpy(ext, ".mtr");
}
if ( ri.FS_ReadFile( filename, NULL ) <= 0 )
{
Com_sprintf( filename, sizeof( filename ), "scripts/%s", shaderFiles[i] );
}
}
ri.Printf( PRINT_DEVELOPER, "...loading '%s'\n", filename );
summand = ri.FS_ReadFile( filename, (void **)&buffers[i] );

View file

@ -184,9 +184,9 @@ RB_InstantQuad
based on Tess_InstantQuad from xreal
==============
*/
void RB_InstantQuad2(vec4_t quadVerts[4], vec2_t texCoords[4], vec4_t color, shaderProgram_t *sp, vec2_t invTexRes)
void RB_InstantQuad2(vec4_t quadVerts[4], vec2_t texCoords[4])
{
GLimp_LogComment("--- RB_InstantQuad ---\n");
GLimp_LogComment("--- RB_InstantQuad2 ---\n");
tess.numVertexes = 0;
tess.numIndexes = 0;
@ -218,12 +218,6 @@ void RB_InstantQuad2(vec4_t quadVerts[4], vec2_t texCoords[4], vec4_t color, sha
RB_UpdateVBOs(ATTR_POSITION | ATTR_TEXCOORD);
GLSL_VertexAttribsState(ATTR_POSITION | ATTR_TEXCOORD);
GLSL_BindProgram(sp);
GLSL_SetUniformMatrix16(sp, TEXTURECOLOR_UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
GLSL_SetUniformVec4(sp, TEXTURECOLOR_UNIFORM_COLOR, color);
GLSL_SetUniformVec2(sp, TEXTURECOLOR_UNIFORM_INVTEXRES, invTexRes);
GLSL_SetUniformVec2(sp, TEXTURECOLOR_UNIFORM_AUTOEXPOSUREMINMAX, tr.autoExposureMinMax);
R_DrawElementsVBO(tess.numIndexes, tess.firstIndex);
@ -256,7 +250,14 @@ void RB_InstantQuad(vec4_t quadVerts[4])
invTexRes[0] = 1.0f / 256.0f;
invTexRes[1] = 1.0f / 256.0f;
RB_InstantQuad2(quadVerts, texCoords, color, &tr.textureColorShader, invTexRes);
GLSL_BindProgram(&tr.textureColorShader);
GLSL_SetUniformMatrix16(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_MODELVIEWPROJECTIONMATRIX, glState.modelviewProjection);
GLSL_SetUniformVec4(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_COLOR, color);
GLSL_SetUniformVec2(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_INVTEXRES, invTexRes);
GLSL_SetUniformVec2(&tr.textureColorShader, TEXTURECOLOR_UNIFORM_AUTOEXPOSUREMINMAX, tr.autoExposureMinMax);
RB_InstantQuad2(quadVerts, texCoords); //, color, &tr.textureColorShader, invTexRes);
}

View file

@ -54,13 +54,15 @@ static qboolean R_CullSurface( msurface_t *surf ) {
}
// don't cull for depth shadow
if ( (tr.viewParms.flags & VPF_DEPTHSHADOW ) )
/*
if ( tr.viewParms.flags & VPF_DEPTHSHADOW )
{
return qfalse;
}
*/
// shadowmaps draw back surfaces
if ( (tr.viewParms.flags & VPF_SHADOWMAP) )
if ( tr.viewParms.flags & (VPF_SHADOWMAP | VPF_DEPTHSHADOW) )
{
if (ct == CT_FRONT_SIDED)
{
@ -811,7 +813,7 @@ void R_AddWorldSurfaces (void) {
{
R_RecursiveWorldNode( tr.world->nodes, 31, 0, 0);
}
else if ( !tr.viewParms.flags & VPF_SHADOWMAP )
else if ( !(tr.viewParms.flags & VPF_SHADOWMAP) )
{
R_RecursiveWorldNode( tr.world->nodes, 15, ( 1 << tr.refdef.num_dlights ) - 1, ( 1 << tr.refdef.num_pshadows ) - 1 );
}