rtexture_t *r_texture_blanknormalmap;
rtexture_t *r_texture_white;
+rtexture_t *r_texture_grey128;
rtexture_t *r_texture_black;
rtexture_t *r_texture_notexture;
rtexture_t *r_texture_whitecube;
data[2] = 255;
data[3] = 255;
r_texture_white = R_LoadTexture2D(r_main_texturepool, "blankwhite", 1, 1, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
+ data[0] = 128;
+ data[1] = 128;
+ data[2] = 128;
+ data[3] = 255;
+ r_texture_grey128 = R_LoadTexture2D(r_main_texturepool, "blankgrey128", 1, 1, data, TEXTYPE_RGBA, TEXF_PRECACHE, NULL);
data[0] = 0;
data[1] = 0;
data[2] = 0;
qglUseProgramObjectARB(0);CHECKGLERROR
}
else
- Con_Printf("permutation%s failed for shader %s, some features may not work properly!\n", permutationname, "glsl/default.glsl");
+ Con_Printf("permutation%s failed for shader %s, some features may not work properly!\n", permutationname, filename);
if (shaderstring)
Mem_Free(shaderstring);
}
memset(r_glsl_permutations, 0, sizeof(r_glsl_permutations));
}
+void R_GLSL_DumpShader_f(void)
+{
+ int i;
+
+ qfile_t *file = FS_Open("glsl/default.glsl", "w", false, false);
+ if(!file)
+ {
+ Con_Printf("failed to write to glsl/default.glsl\n");
+ return;
+ }
+
+ FS_Print(file, "// The engine may define the following macros:\n");
+ FS_Print(file, "// #define VERTEX_SHADER\n// #define GEOMETRY_SHADER\n// #define FRAGMENT_SHADER\n");
+ for (i = 0;permutationinfo[i][0];i++)
+ FS_Printf(file, "// %s", permutationinfo[i][0]);
+ FS_Print(file, "\n");
+ FS_Print(file, builtinshaderstring);
+ FS_Close(file);
+
+ Con_Printf("glsl/default.glsl written\n");
+}
+
extern rtexture_t *r_shadow_attenuationgradienttexture;
extern rtexture_t *r_shadow_attenuation2dtexture;
extern rtexture_t *r_shadow_attenuation3dtexture;
// fragment shader on features that are not being used
const char *shaderfilename = NULL;
unsigned int permutation = 0;
+ rtexture_t *nmap;
r_glsl_permutation = NULL;
// TODO: implement geometry-shader based shadow volumes someday
if (rsurface.rtlight)
if (r_glsl_permutation->loc_DiffuseScale >= 0) qglUniform1fARB(r_glsl_permutation->loc_DiffuseScale, r_refdef.lightmapintensity * 2.0f);
if (r_glsl_permutation->loc_SpecularScale >= 0) qglUniform1fARB(r_glsl_permutation->loc_SpecularScale, r_refdef.lightmapintensity * specularscale * 2.0f);
}
- if (r_glsl_permutation->loc_Texture_Normal >= 0) R_Mesh_TexBind(0, R_GetTexture(rsurface.texture->currentskinframe->nmap));
+ nmap = rsurface.texture->currentskinframe->nmap;
+ if (gl_lightmaps.integer)
+ nmap = r_texture_blanknormalmap;
+ if (r_glsl_permutation->loc_Texture_Normal >= 0) R_Mesh_TexBind(0, R_GetTexture(nmap));
if (r_glsl_permutation->loc_Texture_Color >= 0) R_Mesh_TexBind(1, R_GetTexture(rsurface.texture->basetexture));
if (r_glsl_permutation->loc_Texture_Gloss >= 0) R_Mesh_TexBind(2, R_GetTexture(rsurface.texture->glosstexture));
//if (r_glsl_permutation->loc_Texture_Cube >= 0 && permutation & SHADERPERMUTATION_MODE_LIGHTSOURCE) R_Mesh_TexBindCubeMap(3, R_GetTexture(rsurface.rtlight->currentcubemap));
R_FreeTexturePool(&r_main_texturepool);
r_texture_blanknormalmap = NULL;
r_texture_white = NULL;
+ r_texture_grey128 = NULL;
r_texture_black = NULL;
r_texture_whitecube = NULL;
r_texture_normalizationcube = NULL;
r_main_mempool = Mem_AllocPool("Renderer", 0, NULL);
Cmd_AddCommand("r_glsl_restart", R_GLSL_Restart_f, "unloads GLSL shaders, they will then be reloaded as needed");
+ Cmd_AddCommand("r_glsl_dumpshader", R_GLSL_DumpShader_f, "dumps the engine internal default.glsl shader into glsl/default.glsl");
// FIXME: the client should set up r_refdef.fog stuff including the fogmasktable
if (gamemode == GAME_NEHAHRA)
{
- slopex = 1.0 / r_view.frustum_x;
- slopey = 1.0 / r_view.frustum_y;
- VectorMA(r_view.forward, -slopex, r_view.left, r_view.frustum[0].normal);
- VectorMA(r_view.forward, slopex, r_view.left, r_view.frustum[1].normal);
- VectorMA(r_view.forward, -slopey, r_view.up , r_view.frustum[2].normal);
- VectorMA(r_view.forward, slopey, r_view.up , r_view.frustum[3].normal);
- VectorCopy(r_view.forward, r_view.frustum[4].normal);
- VectorNormalize(r_view.frustum[0].normal);
- VectorNormalize(r_view.frustum[1].normal);
- VectorNormalize(r_view.frustum[2].normal);
- VectorNormalize(r_view.frustum[3].normal);
- r_view.frustum[0].dist = DotProduct (r_view.origin, r_view.frustum[0].normal);
- r_view.frustum[1].dist = DotProduct (r_view.origin, r_view.frustum[1].normal);
- r_view.frustum[2].dist = DotProduct (r_view.origin, r_view.frustum[2].normal);
- r_view.frustum[3].dist = DotProduct (r_view.origin, r_view.frustum[3].normal);
- r_view.frustum[4].dist = DotProduct (r_view.origin, r_view.frustum[4].normal) + r_refdef.nearclip;
+ if (r_view.useperspective)
+ {
+ slopex = 1.0 / r_view.frustum_x;
+ slopey = 1.0 / r_view.frustum_y;
+ VectorMA(r_view.forward, -slopex, r_view.left, r_view.frustum[0].normal);
+ VectorMA(r_view.forward, slopex, r_view.left, r_view.frustum[1].normal);
+ VectorMA(r_view.forward, -slopey, r_view.up , r_view.frustum[2].normal);
+ VectorMA(r_view.forward, slopey, r_view.up , r_view.frustum[3].normal);
+ VectorCopy(r_view.forward, r_view.frustum[4].normal);
+
+ // calculate frustum corners, which are used to calculate deformed frustum planes for shadow caster culling
+ VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, -1024 * slopex, r_view.left, -1024 * slopey, r_view.up, r_view.frustumcorner[0]);
+ VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, 1024 * slopex, r_view.left, -1024 * slopey, r_view.up, r_view.frustumcorner[1]);
+ VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, -1024 * slopex, r_view.left, 1024 * slopey, r_view.up, r_view.frustumcorner[2]);
+ VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, 1024 * slopex, r_view.left, 1024 * slopey, r_view.up, r_view.frustumcorner[3]);
+
+ r_view.frustum[0].dist = DotProduct (r_view.origin, r_view.frustum[0].normal);
+ r_view.frustum[1].dist = DotProduct (r_view.origin, r_view.frustum[1].normal);
+ r_view.frustum[2].dist = DotProduct (r_view.origin, r_view.frustum[2].normal);
+ r_view.frustum[3].dist = DotProduct (r_view.origin, r_view.frustum[3].normal);
+ r_view.frustum[4].dist = DotProduct (r_view.origin, r_view.frustum[4].normal) + r_refdef.nearclip;
+ }
+ else
+ {
+ VectorScale(r_view.left, -r_view.ortho_x, r_view.frustum[0].normal);
+ VectorScale(r_view.left, r_view.ortho_x, r_view.frustum[1].normal);
+ VectorScale(r_view.up, -r_view.ortho_y, r_view.frustum[2].normal);
+ VectorScale(r_view.up, r_view.ortho_y, r_view.frustum[3].normal);
+ VectorCopy(r_view.forward, r_view.frustum[4].normal);
+ r_view.frustum[0].dist = DotProduct (r_view.origin, r_view.frustum[0].normal) + r_view.ortho_x;
+ r_view.frustum[1].dist = DotProduct (r_view.origin, r_view.frustum[1].normal) + r_view.ortho_x;
+ r_view.frustum[2].dist = DotProduct (r_view.origin, r_view.frustum[2].normal) + r_view.ortho_y;
+ r_view.frustum[3].dist = DotProduct (r_view.origin, r_view.frustum[3].normal) + r_view.ortho_y;
+ r_view.frustum[4].dist = DotProduct (r_view.origin, r_view.frustum[4].normal) + r_refdef.nearclip;
+ }
+
PlaneClassify(&r_view.frustum[0]);
PlaneClassify(&r_view.frustum[1]);
PlaneClassify(&r_view.frustum[2]);
PlaneClassify(&r_view.frustum[3]);
PlaneClassify(&r_view.frustum[4]);
- // calculate frustum corners, which are used to calculate deformed frustum planes for shadow caster culling
- VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, -1024 * slopex, r_view.left, -1024 * slopey, r_view.up, r_view.frustumcorner[0]);
- VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, 1024 * slopex, r_view.left, -1024 * slopey, r_view.up, r_view.frustumcorner[1]);
- VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, -1024 * slopex, r_view.left, 1024 * slopey, r_view.up, r_view.frustumcorner[2]);
- VectorMAMAMAM(1, r_view.origin, 1024, r_view.forward, 1024 * slopex, r_view.left, 1024 * slopey, r_view.up, r_view.frustumcorner[3]);
-
// LordHavoc: note to all quake engine coders, Quake had a special case
// for 90 degrees which assumed a square view (wrong), so I removed it,
// Quake2 has it disabled as well.
void R_SetupView(const matrix4x4_t *matrix)
{
if (!r_view.useperspective)
- GL_SetupView_Mode_Ortho(r_view.x, r_view.y, r_view.x + r_view.width, r_view.y + r_view.height, -r_refdef.farclip, r_refdef.farclip);
+ GL_SetupView_Mode_Ortho(-r_view.ortho_x, -r_view.ortho_y, r_view.ortho_x, r_view.ortho_y, -r_refdef.farclip, r_refdef.farclip);
else if (r_refdef.rtworldshadows || r_refdef.rtdlightshadows)
GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_view.frustum_x, r_view.frustum_y, r_refdef.nearclip);
else
{
// use an alternate animation if the entity's frame is not 0,
// and only if the texture has an alternate animation
- if (ent->frame != 0 && t->anim_total[1])
+ if (ent->frame2 != 0 && t->anim_total[1])
t = t->anim_frames[1][(t->anim_total[1] >= 2) ? ((int)(r_refdef.time * 5.0f) % t->anim_total[1]) : 0];
else
t = t->anim_frames[0][(t->anim_total[0] >= 2) ? ((int)(r_refdef.time * 5.0f) % t->anim_total[0]) : 0];
t->specularscale = r_shadow_gloss2intensity.value;
}
+ // lightmaps mode looks bad with dlights using actual texturing, so turn
+ // off the colormap and glossmap, but leave the normalmap on as it still
+ // accurately represents the shading involved
+ if (gl_lightmaps.integer && !(t->currentmaterialflags & MATERIALFLAG_BLENDED))
+ {
+ t->basetexture = r_texture_white;
+ t->specularscale = 0;
+ }
+
t->currentpolygonfactor = r_refdef.polygonfactor;
t->currentpolygonoffset = r_refdef.polygonoffset;
// submodels are biased to avoid z-fighting with world surfaces that they
GL_Color(rsurface.texture->currentlayers[0].color[0], rsurface.texture->currentlayers[0].color[1], rsurface.texture->currentlayers[0].color[2], rsurface.texture->currentlayers[0].color[3]);
if (rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT)
{
- R_Mesh_TexBind(7, R_GetTexture(r_texture_white));
+ R_Mesh_TexBind(7, R_GetTexture(r_texture_grey128));
if (r_glsl_permutation->loc_Texture_Deluxemap >= 0)
R_Mesh_TexBind(8, R_GetTexture(r_texture_blanknormalmap));
R_Mesh_ColorPointer(NULL, 0, 0);
GL_DepthMask(writedepth);
GL_Color(1,1,1,1);
GL_AlphaTest(false);
+ // use lightmode 0 (fullbright or lightmap) or 2 (model lighting)
+ rsurface.lightmode = ((rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT) || rsurface.modeltexcoordlightmap2f != NULL) ? 0 : 2;
R_Mesh_ColorPointer(NULL, 0, 0);
memset(&m, 0, sizeof(m));
m.tex[0] = R_GetTexture(r_texture_white);
else if (rsurface.texture->currentnumlayers)
{
// write depth for anything we skipped on the depth-only pass earlier
- if (!writedepth && (rsurface.texture->currentmaterialflags & (MATERIALFLAG_BLENDED | MATERIALFLAG_ALPHATEST)))
+ if (rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
writedepth = true;
GL_DepthRange(0, (rsurface.texture->currentmaterialflags & MATERIALFLAG_SHORTDEPTHRANGE) ? 0.0625 : 1);
GL_PolygonOffset(rsurface.texture->currentpolygonfactor, rsurface.texture->currentpolygonoffset);