X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=gl_rmain.c;h=791adb33ee6b3a3146d3b350aec50cd30aebcbc8;hb=19885358f4bd80bc7ed85931b766a197e54ce3a1;hp=65c5b946c94f9a3b57178b169fe4f777c5ca7e8f;hpb=1c835329b08d0c8d2255465e485a1cd3cacd478b;p=xonotic%2Fdarkplaces.git diff --git a/gl_rmain.c b/gl_rmain.c index 65c5b946..791adb33 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -807,7 +807,7 @@ void R_GLSL_CompilePermutation(const char *filename, int permutation) 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); } @@ -821,6 +821,28 @@ void R_GLSL_Restart_f(void) 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("data/default.glsl written\n"); +} + extern rtexture_t *r_shadow_attenuationgradienttexture; extern rtexture_t *r_shadow_attenuation2dtexture; extern rtexture_t *r_shadow_attenuation3dtexture; @@ -832,6 +854,7 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl // 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) @@ -1007,7 +1030,10 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl 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)); @@ -1490,6 +1516,7 @@ void GL_Main_Init(void) 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) { @@ -1942,21 +1969,27 @@ static void R_View_SetFrustum(void) 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.x - r_view.width, r_view.frustum[0].normal); - VectorScale(r_view.left, r_view.x , r_view.frustum[1].normal); - VectorScale(r_view.up, -r_view.y - r_view.height , r_view.frustum[2].normal); - VectorScale(r_view.up, r_view.y , r_view.frustum[3].normal); + 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; } - 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; PlaneClassify(&r_view.frustum[0]); PlaneClassify(&r_view.frustum[1]); PlaneClassify(&r_view.frustum[2]); @@ -2003,7 +2036,7 @@ void R_View_Update(void) 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 @@ -3249,7 +3282,7 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t) { // 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]; @@ -3371,6 +3404,15 @@ void R_UpdateTextureInfo(const entity_render_t *ent, texture_t *t) 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 @@ -4984,6 +5026,8 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur 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); @@ -5008,7 +5052,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur 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);