]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_rmain.c
cubemap filters for rtlights are now supported
[xonotic/darkplaces.git] / gl_rmain.c
index 952078c1b60a0e3e9eb8d27b93eca6f93fafc3c1..c0d23b14322d382bedc7aa9494e0b27d67487ce6 100644 (file)
@@ -583,7 +583,7 @@ void R_ShadowVolumeLighting(int visiblevolumes)
                                VectorScale(lightcolor, f, lightcolor);
                        }
 
-                       if (wl->castshadows && (gl_stencil || visiblevolumes))
+                       if (r_shadow_worldshadows.integer && wl->castshadows && (gl_stencil || visiblevolumes))
                        {
                                if (!visiblevolumes)
                                        R_Shadow_Stage_ShadowVolumes();
@@ -599,12 +599,13 @@ void R_ShadowVolumeLighting(int visiblevolumes)
 
                        if (!visiblevolumes)
                        {
-                               if (wl->castshadows && gl_stencil)
+                               if (r_shadow_worldshadows.integer && wl->castshadows && gl_stencil)
                                        R_Shadow_Stage_LightWithShadows();
                                else
                                        R_Shadow_Stage_LightWithoutShadows();
 
                                // calculate world to filter matrix
+                               //Matrix4x4_CreateFromQuakeEntity(&matrix, wl->origin[0], wl->origin[1], wl->origin[2], wl->angles[0] + cl.time * 12, wl->angles[1] + cl.time * 45, wl->angles[2], lightradius);
                                Matrix4x4_CreateFromQuakeEntity(&matrix, wl->origin[0], wl->origin[1], wl->origin[2], wl->angles[0], wl->angles[1], wl->angles[2], lightradius);
                                Matrix4x4_Invert_Simple(&matrix_worldtofilter, &matrix);
                                // calculate world to attenuationxyz/xy matrix
@@ -628,7 +629,7 @@ void R_ShadowVolumeLighting(int visiblevolumes)
                                        if (r_shadow_staticworldlights.integer)
                                                R_Shadow_DrawStaticWorldLight_Light(wl, &ent->matrix, relativelightorigin, relativeeyeorigin, lightradius, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
                                        else
-                                               ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
+                                               ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, wl->cubemap);
                                }
                                if (r_drawentities.integer)
                                {
@@ -644,7 +645,7 @@ void R_ShadowVolumeLighting(int visiblevolumes)
                                                        Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
                                                        Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
                                                        Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
-                                                       ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
+                                                       ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, wl->cubemap);
                                                }
                                        }
                                }
@@ -668,7 +669,7 @@ void R_ShadowVolumeLighting(int visiblevolumes)
                        cullradius = RadiusFromBoundsAndOrigin(clipmins, clipmaxs, rd->origin);
                        VectorScale(rd->light, (1.0f / 4096.0f), lightcolor);
 
-                       if (r_shadow_shadows.integer && (gl_stencil || visiblevolumes))
+                       if (r_shadow_dlightshadows.integer && (gl_stencil || visiblevolumes))
                        {
                                if (!visiblevolumes)
                                        R_Shadow_Stage_ShadowVolumes();
@@ -687,7 +688,7 @@ void R_ShadowVolumeLighting(int visiblevolumes)
 
                        if (!visiblevolumes)
                        {
-                               if (r_shadow_shadows.integer && gl_stencil)
+                               if (r_shadow_dlightshadows.integer && gl_stencil)
                                        R_Shadow_Stage_LightWithShadows();
                                else
                                        R_Shadow_Stage_LightWithoutShadows();
@@ -713,7 +714,7 @@ void R_ShadowVolumeLighting(int visiblevolumes)
                                        Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
                                        Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
                                        Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
-                                       ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
+                                       ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, NULL);
                                }
                                if (r_drawentities.integer)
                                {
@@ -729,7 +730,7 @@ void R_ShadowVolumeLighting(int visiblevolumes)
                                                        Matrix4x4_Concat(&matrix_modeltofilter, &matrix_worldtofilter, &ent->matrix);
                                                        Matrix4x4_Concat(&matrix_modeltoattenuationxyz, &matrix_worldtoattenuationxyz, &ent->matrix);
                                                        Matrix4x4_Concat(&matrix_modeltoattenuationz, &matrix_worldtoattenuationz, &ent->matrix);
-                                                       ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz);
+                                                       ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, lightradius / ent->scale, lightcolor, &matrix_modeltofilter, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, NULL);
                                                }
                                        }
                                }
@@ -738,10 +739,12 @@ void R_ShadowVolumeLighting(int visiblevolumes)
        }
 
        if (visiblevolumes)
+       {
                qglEnable(GL_CULL_FACE);
+               qglDisable(GL_SCISSOR_TEST);
+       }
        else
                R_Shadow_Stage_End();
-       qglDisable(GL_SCISSOR_TEST);
 }
 
 static void R_SetFrustum (void)
@@ -794,11 +797,6 @@ static void R_SetupFrame (void)
        VectorNegate(r_viewleft, r_viewright);
 
        GL_SetupView_ViewPort(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height);
-       if ((r_shadow_realtime_world.integer || r_shadow_shadows.integer) && gl_stencil)
-               GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_refdef.fov_x, r_refdef.fov_y, 1.0f);
-       else
-               GL_SetupView_Mode_Perspective(r_refdef.fov_x, r_refdef.fov_y, 1.0f, r_farclip);
-       GL_SetupView_Orientation_FromEntity(&r_refdef.viewentitymatrix);
 
        R_AnimateLight();
 }
@@ -823,7 +821,7 @@ static void R_BlendView(void)
        GL_DepthTest(false); // magic
        GL_VertexPointer(vertex3f);
        GL_Color(r_refdef.viewblend[0], r_refdef.viewblend[1], r_refdef.viewblend[2], r_refdef.viewblend[3]);
-       r = 64000;
+       r = 64;
        vertex3f[0] = r_vieworigin[0] + r_viewforward[0] * 1.5 + r_viewleft[0] * r - r_viewup[0] * r;
        vertex3f[1] = r_vieworigin[1] + r_viewforward[1] * 1.5 + r_viewleft[1] * r - r_viewup[1] * r;
        vertex3f[2] = r_vieworigin[2] + r_viewforward[2] * 1.5 + r_viewleft[2] * r - r_viewup[2] * r;
@@ -865,6 +863,9 @@ void R_RenderView (void)
        R_MoveExplosions();
        R_TimeReport("mexplosion");
 
+       qglPolygonOffset(0, 0);
+       qglEnable(GL_POLYGON_OFFSET_FILL);
+
        R_Textures_Frame();
        R_SetupFrame();
        R_SetFrustum();
@@ -882,6 +883,11 @@ void R_RenderView (void)
        R_FarClip_Start(r_vieworigin, r_viewforward, 768.0f);
        R_MarkEntities();
        r_farclip = R_FarClip_Finish() + 256.0f;
+       if (gl_stencil && ((r_shadow_realtime_world.integer && r_shadow_worldshadows.integer) || ((r_shadow_realtime_world.integer || r_shadow_realtime_dlight.integer) && r_shadow_dlightshadows.integer)))
+               GL_SetupView_Mode_PerspectiveInfiniteFarClip(r_refdef.fov_x, r_refdef.fov_y, 1.0f);
+       else
+               GL_SetupView_Mode_Perspective(r_refdef.fov_x, r_refdef.fov_y, 1.0f, r_farclip);
+       GL_SetupView_Orientation_FromEntity(&r_refdef.viewentitymatrix);
        R_TimeReport("markentity");
 
        qglDepthFunc(GL_LEQUAL);
@@ -905,11 +911,8 @@ void R_RenderView (void)
        R_DrawModels();
        R_TimeReport("models");
 
-       if (r_shadow_realtime_world.integer || r_shadow_realtime_dlight.integer)
-       {
-               R_ShadowVolumeLighting(false);
-               R_TimeReport("dynlight");
-       }
+       R_ShadowVolumeLighting(false);
+       R_TimeReport("rtlights");
 
        R_DrawLightningBeams();
        R_TimeReport("lightning");
@@ -943,6 +946,9 @@ void R_RenderView (void)
 
        R_Mesh_Finish();
        R_TimeReport("meshfinish");
+
+       qglPolygonOffset(0, 0);
+       qglDisable(GL_POLYGON_OFFSET_FILL);
 }
 
 /*