]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
fix double bright models bug (LightPoint returns 2x color, and RSurf_SetColorPointer...
[xonotic/darkplaces.git] / gl_rmain.c
index 656aa1182d4716c987126a223608e9b757f2f910..e050153b780b06992218849947fd7733d575e5e4 100644 (file)
@@ -105,7 +105,9 @@ cvar_t r_bloom_blur = {CVAR_SAVE, "r_bloom_blur", "8"};
 cvar_t r_bloom_resolution = {CVAR_SAVE, "r_bloom_resolution", "320"};
 cvar_t r_bloom_power = {CVAR_SAVE, "r_bloom_power", "4"};
 
-cvar_t developer_texturelogging = {0, "developer_texturelogging", "1"};
+cvar_t r_smoothnormals_areaweighting = {0, "r_smoothnormals_areaweighting", "1"};
+
+cvar_t developer_texturelogging = {0, "developer_texturelogging", "0"};
 
 cvar_t gl_lightmaps = {0, "gl_lightmaps", "0"};
 
@@ -473,7 +475,7 @@ void gl_main_newmap(void)
        if (cl.worldmodel)
        {
                strlcpy(entname, cl.worldmodel->name, sizeof(entname));
-               l = strlen(entname) - 4;
+               l = (int)strlen(entname) - 4;
                if (l >= 0 && !strcmp(entname + l, ".bsp"))
                {
                        strcpy(entname + l, ".ent");
@@ -513,6 +515,7 @@ void GL_Main_Init(void)
        Cvar_RegisterVariable(&r_bloom_blur);
        Cvar_RegisterVariable(&r_bloom_resolution);
        Cvar_RegisterVariable(&r_bloom_power);
+       Cvar_RegisterVariable(&r_smoothnormals_areaweighting);
        Cvar_RegisterVariable(&developer_texturelogging);
        Cvar_RegisterVariable(&gl_lightmaps);
        if (gamemode == GAME_NEHAHRA || gamemode == GAME_NEXUIZ || gamemode == GAME_TENEBRAE)
@@ -579,7 +582,6 @@ void Render_Init(void)
 {
        gl_backend_init();
        R_Textures_Init();
-       Mod_RenderInit();
        R_MeshQueue_Init();
        GL_Main_Init();
        GL_Draw_Init();
@@ -593,6 +595,7 @@ void Render_Init(void)
        UI_Init();
        Sbar_Init();
        R_LightningBeams_Init();
+       Mod_RenderInit();
 }
 
 /*
@@ -1527,7 +1530,7 @@ void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture
                        rsurface_svector3f = varray_svector3f;
                        rsurface_tvector3f = varray_tvector3f;
                        rsurface_normal3f = varray_normal3f;
-                       Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f);
+                       Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
                }
                // a single autosprite surface can contain multiple sprites...
                VectorClear(forward);
@@ -1564,7 +1567,7 @@ void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture
                        rsurface_svector3f = varray_svector3f;
                        rsurface_tvector3f = varray_tvector3f;
                        rsurface_normal3f = varray_normal3f;
-                       Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f);
+                       Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_texcoordtexture2f, surface->groupmesh->data_element3i + surface->num_firsttriangle * 3, rsurface_svector3f, rsurface_tvector3f, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
                }
                Matrix4x4_Transform(&ent->inversematrix, r_viewforward, forward);
                Matrix4x4_Transform(&ent->inversematrix, r_viewright, right);
@@ -1603,13 +1606,13 @@ void RSurf_SetColorPointer(const entity_render_t *ent, const msurface_t *surface
                vec4_t ambientcolor4f;
                vec3_t diffusecolor;
                vec3_t diffusenormal;
-               if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, r, g, b, a, false))
+               if (R_LightModel(ambientcolor4f, diffusecolor, diffusenormal, ent, r*0.5f, g*0.5f, b*0.5f, a, false))
                {
                        rsurface_lightmapcolor4f = varray_color4f;
                        if (rsurface_normal3f == NULL)
                        {
                                rsurface_normal3f = varray_normal3f;
-                               Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle, rsurface_normal3f);
+                               Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface_vertex3f, surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle, rsurface_normal3f, r_smoothnormals_areaweighting.integer);
                        }
                        R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, surface->groupmesh->num_vertices, rsurface_vertex3f + 3 * surface->num_firstvertex, rsurface_normal3f + 3 * surface->num_firstvertex, rsurface_lightmapcolor4f + 4 * surface->num_firstvertex);
                        r = 1;
@@ -2044,11 +2047,11 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        if (waterscrolling)
                                m.texmatrix[0] = r_waterscrollmatrix;
                        m.pointer_color = varray_color4f;
-                       colorscale = 1;
+                       colorscale = 2;
                        if (gl_combine.integer)
                        {
                                m.texrgbscale[0] = 2;
-                               colorscale *= 0.5f;
+                               colorscale = 1;
                        }
                        // transparent is not affected by r_lightmapintensity
                        if (!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
@@ -2105,11 +2108,11 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                        if (waterscrolling)
                                m.texmatrix[0] = r_waterscrollmatrix;
                        m.pointer_color = varray_color4f;
-                       colorscale = 1;
+                       colorscale = 2;
                        if (gl_combine.integer)
                        {
                                m.texrgbscale[0] = 2;
-                               colorscale *= 0.5f;
+                               colorscale *= 1;
                        }
                        // transparent is not affected by r_lightmapintensity
                        if (!(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
@@ -2169,10 +2172,10 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                m.texmatrix[0] = r_waterscrollmatrix;
                        m.pointer_color = varray_color4f;
                        colorscale = 1;
-                       if (gl_combine.integer)
+                       if (gl_combine.integer && (ent->colormod[0] > 1 || ent->colormod[1] > 1 || ent->colormod[2] > 1))
                        {
-                               m.texrgbscale[0] = 2;
-                               colorscale *= 0.5f;
+                               m.texrgbscale[0] = 4;
+                               colorscale = 0.25f;
                        }
                        R_Mesh_State(&m);
                        colorscale *= r_ambient.value * (1.0f / 64.0f);
@@ -2221,10 +2224,9 @@ static void R_DrawTextureSurfaceList(const entity_render_t *ent, texture_t *text
                                m.texmatrix[0] = r_waterscrollmatrix;
                        m.pointer_color = varray_color4f;
                        R_Mesh_State(&m);
-                       colorscale = 1;
-                       r = ent->colormod[0] * colorscale;
-                       g = ent->colormod[1] * colorscale;
-                       b = ent->colormod[2] * colorscale;
+                       r = 1;
+                       g = 1;
+                       b = 1;
                        a = texture->currentalpha;
                        applycolor = r != 1 || g != 1 || b != 1 || a != 1;
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)