]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
fix brightness of fullbright entities in r_glsl 1 mode by using a 128
[xonotic/darkplaces.git] / gl_rmain.c
index c0bc61c3cb517fa47df34f7948a4a6e5aac1abe2..a2b836fa1ca158cbfd5d4d198c351a30ee4cbe45 100644 (file)
@@ -143,6 +143,7 @@ svbsp_t r_svbsp;
 
 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;
@@ -235,6 +236,11 @@ static void R_BuildBlankTextures(void)
        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;
@@ -807,7 +813,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 +827,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("glsl/default.glsl written\n");
+}
+
 extern rtexture_t *r_shadow_attenuationgradienttexture;
 extern rtexture_t *r_shadow_attenuation2dtexture;
 extern rtexture_t *r_shadow_attenuation3dtexture;
@@ -832,6 +860,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 +1036,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));
@@ -1453,6 +1485,7 @@ void gl_main_shutdown(void)
        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;
@@ -1490,6 +1523,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)
        {
@@ -3377,6 +3411,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
@@ -4640,7 +4683,7 @@ static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, msurface_t **t
        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);
@@ -4990,6 +5033,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);