]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
lighthalf related transpoly cleanup
[xonotic/darkplaces.git] / gl_rmain.c
index d48dec0a4561f7acf6574bf6b8f4e8c88a10437a..753f34e798945f2013c83e5384646dc5d78ca2a4 100644 (file)
@@ -33,7 +33,7 @@ int                   r_framecount;           // used for dlight push checking
 
 mplane_t       frustum[4];
 
-int                    c_brush_polys, c_alias_polys;
+int                    c_brush_polys, c_alias_polys, c_light_polys, c_nodes, c_leafs;
 
 qboolean       envmap;                         // true during envmap command capture 
 
@@ -75,9 +75,9 @@ cvar_t        r_speeds = {"r_speeds","0"};
 cvar_t r_speeds2 = {"r_speeds2","0"};
 cvar_t r_fullbright = {"r_fullbright","0"};
 //cvar_t       r_lightmap = {"r_lightmap","0"};
-//cvar_t       r_shadows = {"r_shadows","0"};
+cvar_t r_shadows = {"r_shadows","0"};
 cvar_t r_wateralpha = {"r_wateralpha","1"};
-//cvar_t       r_dynamic = {"r_dynamic","1"};
+cvar_t r_dynamic = {"r_dynamic","1"};
 cvar_t r_novis = {"r_novis","0"};
 cvar_t r_waterripple = {"r_waterripple","0"};
 cvar_t r_fullbrights = {"r_fullbrights", "1"};
@@ -85,7 +85,6 @@ cvar_t        r_fullbrights = {"r_fullbrights", "1"};
 //cvar_t       gl_cull = {"gl_cull","1"};
 //cvar_t       gl_affinemodels = {"gl_affinemodels","0"};
 //cvar_t       gl_polyblend = {"gl_polyblend","1"};
-//cvar_t       gl_flashblend = {"gl_flashblend","0"};
 cvar_t gl_playermip = {"gl_playermip","0"};
 //cvar_t       gl_nocolors = {"gl_nocolors","0"};
 //cvar_t       gl_keeptjunctions = {"gl_keeptjunctions","1"};
@@ -95,6 +94,7 @@ cvar_t        brightness = {"brightness", "1.0", TRUE}; // LordHavoc: a method of opera
 cvar_t gl_lightmode = {"gl_lightmode", "1", TRUE}; // LordHavoc: overbright lighting
 //cvar_t       r_dynamicwater = {"r_dynamicwater", "1"};
 //cvar_t       r_dynamicbothsides = {"r_dynamicbothsides", "1"}; // LordHavoc: can disable dynamic lighting of backfaces, but quake maps are weird so it doesn't always work right...
+cvar_t r_farclip = {"r_farclip", "6144"};
 
 cvar_t gl_fogenable = {"gl_fogenable", "0"};
 cvar_t gl_fogdensity = {"gl_fogdensity", "0.25"};
@@ -513,29 +513,14 @@ void R_DrawSpriteModel (entity_t *e)
 
        if (e->model->flags & EF_FULLBRIGHT || e->effects & EF_FULLBRIGHT)
        {
-               if (lighthalf)
-               {
-                       shadecolor[0] = e->colormod[0] * 128;
-                       shadecolor[1] = e->colormod[1] * 128;
-                       shadecolor[2] = e->colormod[2] * 128;
-               }
-               else
-               {
-                       shadecolor[0] = e->colormod[0] * 255;
-                       shadecolor[1] = e->colormod[1] * 255;
-                       shadecolor[2] = e->colormod[2] * 255;
-               }
+               shadecolor[0] = e->colormod[0] * 255;
+               shadecolor[1] = e->colormod[1] * 255;
+               shadecolor[2] = e->colormod[2] * 255;
        }
        else
        {
                R_LightPoint (shadecolor, e->origin);
                R_DynamicLightPointNoMask(shadecolor, e->origin);
-               if (lighthalf)
-               {
-                       shadecolor[0] *= e->colormod[0] * 0.5;
-                       shadecolor[1] *= e->colormod[1] * 0.5;
-                       shadecolor[2] *= e->colormod[2] * 0.5;
-               }
        }
 
        // LordHavoc: interpolated sprite rendering
@@ -804,8 +789,7 @@ void R_DrawAliasFrame (aliashdr_t *paliashdr)
                glColor3f (1,1,1);
        }
 
-       /*
-       if (r_shadows.value && !(currententity->effects & EF_ADDITIVE) && currententity != &cl.viewent)
+       if (!fogenabled && r_shadows.value && !(currententity->effects & EF_ADDITIVE) && currententity != &cl.viewent)
        {
                // flatten it to make a shadow
                float *av = aliasvert + 2, l = lightspot[2] + 0.125;
@@ -839,7 +823,6 @@ void R_DrawAliasFrame (aliashdr_t *paliashdr)
                glEnable (GL_TEXTURE_2D);
                glColor3f (1,1,1);
        }
-       */
 
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable (GL_BLEND);
@@ -1020,8 +1003,7 @@ void R_DrawQ2AliasFrame (md2mem_t *pheader)
                glColor3f (1,1,1);
        }
 
-       /*
-       if (r_shadows.value && !(currententity->effects & EF_ADDITIVE) && currententity != &cl.viewent)
+       if (!fogenabled && r_shadows.value && !(currententity->effects & EF_ADDITIVE) && currententity != &cl.viewent)
        {
                int i;
                float *av = aliasvert + 2, l = lightspot[2] + 0.125;
@@ -1086,13 +1068,15 @@ void R_DrawQ2AliasFrame (md2mem_t *pheader)
                glEnable (GL_TEXTURE_2D);
                glColor3f (1,1,1);
        }
-       */
 
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable (GL_BLEND);
        glDepthMask(1);
 }
 
+int modeldlightbits[8];
+extern int r_dlightframecount;
+
 /*
 =================
 R_DrawAliasModel
@@ -1122,6 +1106,16 @@ void R_DrawAliasModel (entity_t *e, int cull)
        VectorCopy (currententity->origin, r_entorigin);
        VectorSubtract (r_origin, r_entorigin, modelorg);
 
+       {
+               mleaf_t *leaf = Mod_PointInLeaf (currententity->origin, cl.worldmodel);
+               if (leaf->dlightframe == r_dlightframecount)
+                       for (i = 0;i < 8;i++)
+                               modeldlightbits[i] = leaf->dlightbits[i];
+               else
+                       for (i = 0;i < 8;i++)
+                               modeldlightbits[i] = 0;
+       }
+
        // get lighting information
 
        if (currententity->model->flags & EF_FULLBRIGHT || currententity->effects & EF_FULLBRIGHT)
@@ -1181,11 +1175,11 @@ void R_DrawAliasModel (entity_t *e, int cull)
 
        // we can't dynamically colormap textures, so they are cached
        // seperately for the players.  Heads are just uncolored.
-       if (currententity->colormap != vid.colormap/* && !gl_nocolors.value*/)
+       if (currententity->colormap != 0 /*vid.colormap*/ /* && !gl_nocolors.value*/)
        {
                i = currententity - cl_entities;
                if (i >= 1 && i<=cl.maxclients /* && !strcmp (currententity->model->name, "progs/player.mdl") */)
-                   glBindTexture(GL_TEXTURE_2D, playertextures - 1 + i);
+                       glBindTexture(GL_TEXTURE_2D, playertextures - 1 + i);
        }
 
 //     if (gl_affinemodels.value)
@@ -1327,7 +1321,10 @@ void R_SetupFrame (void)
 {
 // don't allow cheats in multiplayer
        if (cl.maxclients > 1)
+       {
                Cvar_Set ("r_fullbright", "0");
+               Cvar_Set ("r_ambient", "0");
+       }
 
        R_AnimateLight ();
 
@@ -1349,12 +1346,14 @@ void R_SetupFrame (void)
 
        c_brush_polys = 0;
        c_alias_polys = 0;
+       c_light_polys = 0;
+       c_nodes = 0;
+       c_leafs = 0;
 
 }
 
 
-void MYgluPerspective( GLdouble fovy, GLdouble aspect,
-                    GLdouble zNear, GLdouble zFar )
+void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar )
 {
    GLdouble xmin, xmax, ymin, ymax;
 
@@ -1416,7 +1415,7 @@ void R_SetupGL (void)
 //     if (skyname[0]) // skybox enabled?
 //             MYgluPerspective (r_refdef.fov_y,  screenaspect,  4,  r_skyboxsize.value*1.732050807569 + 256); // this is size*sqrt(3) + 256
 //     else
-               MYgluPerspective (r_refdef.fov_y,  screenaspect,  4,  6144);
+               MYgluPerspective (r_refdef.fov_y,  screenaspect,  4,  r_farclip.value);
 
        glCullFace(GL_FRONT);
 
@@ -1552,6 +1551,10 @@ R_RenderView
 r_refdef must be set before the first call
 ================
 */
+extern qboolean intimerefresh;
+extern qboolean skyisvisible;
+extern void R_Sky();
+extern void UploadLightmaps();
 void R_RenderView (void)
 {
 //     double currtime, temptime;
@@ -1564,7 +1567,6 @@ void R_RenderView (void)
        lighthalf = gl_lightmode.value;
 
        FOG_framebegin();
-       transpolyclear();
 
 //     if (r_speeds2.value)
 //     {
@@ -1579,16 +1581,30 @@ void R_RenderView (void)
        R_SetupFrame ();
        R_SetFrustum ();
        R_SetupGL ();
+
+       skypolyclear();
+       wallpolyclear();
+       transpolyclear();
+       skyisvisible = false;
+
        R_MarkLeaves ();        // done here so we know if we're in water
        R_DrawWorld ();         // adds static entities to the list
-       S_ExtraUpdate ();       // don't let sound get messed up if going slow
-       wallpolyclear();
+       if (!intimerefresh)
+               S_ExtraUpdate ();       // don't let sound get messed up if going slow
        R_DrawEntitiesOnList1 (); // BSP models
+
+       skypolyrender(); // fogged sky polys, affects depth
+       if (skyname[0] && skyisvisible && !fogenabled)
+               R_Sky(); // does not affect depth, draws over the sky polys
+
+       UploadLightmaps();
        wallpolyrender();
+
        R_DrawEntitiesOnList2 (); // other models
 //     R_RenderDlights ();
        R_DrawViewModel ();
        R_DrawParticles ();
+
        transpolyrender();
 
        FOG_frameend();