]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
r_shadows is now ignored when in r_shadow_realtime mode
[xonotic/darkplaces.git] / gl_rmain.c
index 24c9baa056c896a373b90581408c14f15e44402c..490568bb07b0d2b6dcc35b5310e62a2c457b683d 100644 (file)
@@ -52,7 +52,7 @@ unsigned short d_lightstylevalue[256];
 cvar_t r_drawentities = {0, "r_drawentities","1"};
 cvar_t r_drawviewmodel = {0, "r_drawviewmodel","1"};
 cvar_t r_shadows = {CVAR_SAVE, "r_shadows", "1"};
-cvar_t r_staticworldlights = {0, "r_staticworldlights", "1"};
+cvar_t r_shadow_staticworldlights = {0, "r_shadow_staticworldlights", "1"};
 cvar_t r_speeds = {0, "r_speeds","0"};
 cvar_t r_fullbright = {0, "r_fullbright","0"};
 cvar_t r_wateralpha = {CVAR_SAVE, "r_wateralpha","1"};
@@ -221,14 +221,14 @@ void GL_Main_Init(void)
        Cvar_RegisterVariable (&r_drawentities);
        Cvar_RegisterVariable (&r_drawviewmodel);
        Cvar_RegisterVariable (&r_shadows);
-       Cvar_RegisterVariable (&r_staticworldlights);
+       Cvar_RegisterVariable (&r_shadow_staticworldlights);
        Cvar_RegisterVariable (&r_speeds);
        Cvar_RegisterVariable (&r_fullbrights);
        Cvar_RegisterVariable (&r_wateralpha);
        Cvar_RegisterVariable (&r_dynamic);
        Cvar_RegisterVariable (&r_fullbright);
        Cvar_RegisterVariable (&r_textureunits);
-       if (gamemode == GAME_NEHAHRA)
+       if (gamemode == GAME_NEHAHRA || gamemode == GAME_NEXIUZ)
                Cvar_SetValue("r_fullbrights", 0);
        R_RegisterModule("GL_Main", gl_main_start, gl_main_shutdown, gl_main_newmap);
 }
@@ -577,6 +577,7 @@ int R_DrawBrushModelsSky (void)
 R_DrawViewModel
 =============
 */
+/*
 void R_DrawViewModel (void)
 {
        entity_render_t *ent;
@@ -593,6 +594,7 @@ void R_DrawViewModel (void)
        R_UpdateEntLights(ent);
        ent->model->Draw(ent);
 }
+*/
 
 void R_DrawNoModel(entity_render_t *ent);
 void R_DrawModels ()
@@ -603,7 +605,6 @@ void R_DrawModels ()
        if (!r_drawentities.integer)
                return;
 
-       R_DrawViewModel();
        for (i = 0;i < r_refdef.numentities;i++)
        {
                ent = r_refdef.entities[i];
@@ -823,7 +824,10 @@ void R_ShadowVolumeLighting (int visiblevolumes)
                memset(&m, 0, sizeof(m));
                m.blendfunc1 = GL_ONE;
                m.blendfunc2 = GL_ONE;
+               if (r_shadow_realtime.integer >= 3)
+                       m.depthdisable = true;
                R_Mesh_State(&m);
+               qglDisable(GL_CULL_FACE);
                GL_Color(0.0 * r_colorscale, 0.0125 * r_colorscale, 0.1 * r_colorscale, 1);
        }
        else
@@ -890,10 +894,11 @@ void R_ShadowVolumeLighting (int visiblevolumes)
 
                if (!visiblevolumes)
                        R_Shadow_Stage_ShadowVolumes();
-               if (wl->shadowvolume && r_staticworldlights.integer)
-                       R_Shadow_DrawWorldLightShadowVolume(&cl_entities[0].render.matrix, wl);
+               ent = &cl_entities[0].render;
+               if (wl->shadowvolume && r_shadow_staticworldlights.integer)
+                       R_Shadow_DrawWorldLightShadowVolume(&ent->matrix, wl);
                else
-                       R_TestAndDrawShadowVolume(&cl_entities[0].render, wl->origin, cullradius, lightradius, clipmins, clipmaxs);
+                       R_TestAndDrawShadowVolume(ent, wl->origin, cullradius / ent->scale, lightradius / ent->scale, clipmins, clipmaxs);
                if (r_drawentities.integer)
                {
                        for (i = 0;i < r_refdef.numentities;i++)
@@ -903,7 +908,7 @@ void R_ShadowVolumeLighting (int visiblevolumes)
                                 && ent->maxs[1] >= wl->mins[1] && ent->mins[1] <= wl->maxs[1]
                                 && ent->maxs[2] >= wl->mins[2] && ent->mins[2] <= wl->maxs[2]
                                 && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
-                                       R_TestAndDrawShadowVolume(r_refdef.entities[i], wl->origin, cullradius, lightradius, clipmins, clipmaxs);
+                                       R_TestAndDrawShadowVolume(r_refdef.entities[i], wl->origin, cullradius / ent->scale, lightradius / ent->scale, clipmins, clipmaxs);
                        }
                }
 
@@ -918,7 +923,7 @@ void R_ShadowVolumeLighting (int visiblevolumes)
                                if (wl->numsurfaces)
                                        R_Model_Brush_DrawLightForSurfaceList(ent, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, wl->surfaces, wl->numsurfaces);
                                else
-                                       ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius, lightcolor);
+                                       ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor);
                        }
                        if (r_drawentities.integer)
                        {
@@ -933,27 +938,7 @@ void R_ShadowVolumeLighting (int visiblevolumes)
                                        {
                                                Matrix4x4_Transform(&ent->inversematrix, wl->origin, relativelightorigin);
                                                Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
-                                               ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius, lightcolor);
-                                       }
-                               }
-                       }
-
-                       if (R_Shadow_Stage_EraseShadowVolumes())
-                       {
-                               if (wl->shadowvolume && r_staticworldlights.integer)
-                                       R_Shadow_DrawWorldLightShadowVolume(&cl_entities[0].render.matrix, wl);
-                               else
-                                       R_TestAndDrawShadowVolume(&cl_entities[0].render, wl->origin, cullradius, lightradius, clipmins, clipmaxs);
-                               if (r_drawentities.integer)
-                               {
-                                       for (i = 0;i < r_refdef.numentities;i++)
-                                       {
-                                               ent = r_refdef.entities[i];
-                                               if (ent->maxs[0] >= wl->mins[0] && ent->mins[0] <= wl->maxs[0]
-                                                && ent->maxs[1] >= wl->mins[1] && ent->mins[1] <= wl->maxs[1]
-                                                && ent->maxs[2] >= wl->mins[2] && ent->mins[2] <= wl->maxs[2]
-                                                && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
-                                                       R_TestAndDrawShadowVolume(r_refdef.entities[i], wl->origin, cullradius, lightradius, clipmins, clipmaxs);
+                                               ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor);
                                        }
                                }
                        }
@@ -976,7 +961,7 @@ void R_ShadowVolumeLighting (int visiblevolumes)
 
                if (!visiblevolumes)
                        R_Shadow_Stage_ShadowVolumes();
-               if (sl->shadowvolume && r_staticworldlights.integer)
+               if (sl->shadowvolume && r_shadow_staticworldlights.integer)
                        R_DrawWorldLightShadowVolume(&cl_entities[0].render.matrix, sl->shadowvolume);
                else
                        R_TestAndDrawShadowVolume(&cl_entities[0].render, sl->origin, cullradius, lightradius);
@@ -1020,24 +1005,6 @@ void R_ShadowVolumeLighting (int visiblevolumes)
                                        }
                                }
                        }
-
-                       R_Shadow_Stage_EraseShadowVolumes();
-                       if (sl->shadowvolume && r_staticworldlights.integer)
-                               R_DrawWorldLightShadowVolume(&cl_entities[0].render.matrix, sl->shadowvolume);
-                       else
-                               R_TestAndDrawShadowVolume(&cl_entities[0].render, sl->origin, cullradius, lightradius);
-                       if (r_drawentities.integer)
-                       {
-                               for (i = 0;i < r_refdef.numentities;i++)
-                               {
-                                       ent = r_refdef.entities[i];
-                                       if (ent->maxs[0] >= sl->mins[0] && ent->mins[0] <= sl->maxs[0]
-                                       && ent->maxs[1] >= sl->mins[1] && ent->mins[1] <= sl->maxs[1]
-                                       && ent->maxs[2] >= sl->mins[2] && ent->mins[2] <= sl->maxs[2]
-                                       && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
-                                               R_TestAndDrawShadowVolume(r_refdef.entities[i], sl->origin, cullradius, lightradius);
-                               }
-                       }
                }
        }
        */
@@ -1061,14 +1028,15 @@ void R_ShadowVolumeLighting (int visiblevolumes)
 
                if (!visiblevolumes)
                        R_Shadow_Stage_ShadowVolumes();
-               R_TestAndDrawShadowVolume(&cl_entities[0].render, rd->origin, cullradius, lightradius, clipmins, clipmaxs);
+               ent = &cl_entities[0].render;
+               R_TestAndDrawShadowVolume(ent, rd->origin, cullradius / ent->scale, lightradius / ent->scale, clipmins, clipmaxs);
                if (r_drawentities.integer)
                {
                        for (i = 0;i < r_refdef.numentities;i++)
                        {
                                ent = r_refdef.entities[i];
                                if (ent != rd->ent && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
-                                       R_TestAndDrawShadowVolume(ent, rd->origin, cullradius, lightradius, clipmins, clipmaxs);
+                                       R_TestAndDrawShadowVolume(ent, rd->origin, cullradius / ent->scale, lightradius / ent->scale, clipmins, clipmaxs);
                        }
                }
 
@@ -1080,7 +1048,7 @@ void R_ShadowVolumeLighting (int visiblevolumes)
                        {
                                Matrix4x4_Transform(&ent->inversematrix, rd->origin, relativelightorigin);
                                Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
-                               ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius, lightcolor);
+                               ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor);
                        }
                        if (r_drawentities.integer)
                        {
@@ -1092,21 +1060,7 @@ void R_ShadowVolumeLighting (int visiblevolumes)
                                        {
                                                Matrix4x4_Transform(&ent->inversematrix, rd->origin, relativelightorigin);
                                                Matrix4x4_Transform(&ent->inversematrix, r_origin, relativeeyeorigin);
-                                               ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius, lightcolor);
-                                       }
-                               }
-                       }
-
-                       if (R_Shadow_Stage_EraseShadowVolumes())
-                       {
-                               R_TestAndDrawShadowVolume(&cl_entities[0].render, rd->origin, cullradius, lightradius, clipmins, clipmaxs);
-                               if (r_drawentities.integer)
-                               {
-                                       for (i = 0;i < r_refdef.numentities;i++)
-                                       {
-                                               ent = r_refdef.entities[i];
-                                               if (ent != rd->ent && !(ent->effects & EF_ADDITIVE) && ent->alpha == 1)
-                                                       R_TestAndDrawShadowVolume(ent, rd->origin, cullradius, lightradius, clipmins, clipmaxs);
+                                               ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor);
                                        }
                                }
                        }
@@ -1115,6 +1069,7 @@ void R_ShadowVolumeLighting (int visiblevolumes)
 
        if (!visiblevolumes)
                R_Shadow_Stage_End();
+       qglEnable(GL_CULL_FACE);
        qglDisable(GL_SCISSOR_TEST);
 }
 
@@ -1226,7 +1181,7 @@ void R_RenderView (void)
                }
                else if (!gl_stencil)
                {
-                       Con_Printf("Stencil not enabled, turning off r_shadow_realtime, please type vid_stencil 1;vid_restart and try again\n");
+                       Con_Printf("Stencil not enabled, turning off r_shadow_realtime, please type vid_stencil 1;vid_bitsperpixel 32;vid_restart and try again\n");
                        Cvar_SetValueQuick(&r_shadow_realtime, 0);
                }
                else if (!gl_combine.integer)
@@ -1288,7 +1243,7 @@ void R_RenderView (void)
        R_DrawModels(r_shadow_lightingmode > 0);
        R_TimeReport("models");
 
-       if (r_shadows.integer == 1)
+       if (r_shadows.integer == 1 && r_shadow_lightingmode <= 0)
        {
                R_DrawFakeShadows();
                R_TimeReport("fakeshadow");
@@ -1320,7 +1275,7 @@ void R_RenderView (void)
 
        R_MeshQueue_Render();
        R_MeshQueue_EndScene();
-       if (r_shadow_realtime.integer == 2)
+       if (r_shadow_realtime.integer >= 2)
        {
                R_ShadowVolumeLighting(true);
                R_TimeReport("shadowvolume");
@@ -1445,7 +1400,7 @@ void R_DrawNoModel(entity_render_t *ent)
        //      R_DrawNoModelCallback(ent, 0);
 }
 
-void R_CalcBeamVerts (float *vert, vec3_t org1, vec3_t org2, float width)
+void R_CalcBeamVerts (float *vert, const vec3_t org1, const vec3_t org2, float width)
 {
        vec3_t right1, right2, diff, normal;