]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
make r_shadows 3 mode mostly match lighting conditions of the lightmaps
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 6 Oct 2002 16:51:35 +0000 (16:51 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 6 Oct 2002 16:51:35 +0000 (16:51 +0000)
r_shadows 3 mode now checks SURF_SHADOWCAST and SURF_SHADOWLIGHT flags

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2512 d7cf8633-e32d-0410-b094-e92efae38249

gl_rsurf.c
model_brush.c
model_brush.h
r_shadow.c

index 5593a63ae23673e75a7c08ced722055a3e0b9091..749e2238c14ac195717559e75af50e9a29ff6f67 100644 (file)
@@ -1864,21 +1864,24 @@ void R_Model_Brush_DrawShadowVolume (entity_render_t *ent, vec3_t relativelighto
        lightradius2 = lightradius * lightradius;
        for (i = 0, surf = ent->model->surfaces + ent->model->firstmodelsurface;i < ent->model->nummodelsurfaces;i++, surf++)
        {
-               f = PlaneDiff(relativelightorigin, surf->plane);
-               if (surf->flags & SURF_PLANEBACK)
-                       f = -f;
-               // draw shadows only for backfaces
-               projectdistance = lightradius + f;
-               if (projectdistance >= 0.1 && projectdistance < lightradius)
+               if (surf->flags & SURF_SHADOWCAST)
                {
-                       VectorSubtract(relativelightorigin, surf->poly_center, temp);
-                       if (DotProduct(temp, temp) < (surf->poly_radius2 + lightradius2))
+                       f = PlaneDiff(relativelightorigin, surf->plane);
+                       if (surf->flags & SURF_PLANEBACK)
+                               f = -f;
+                       // draw shadows only for backfaces
+                       projectdistance = lightradius + f;
+                       if (projectdistance >= 0.1 && projectdistance < lightradius)
                        {
-                               for (mesh = surf->mesh;mesh;mesh = mesh->chain)
+                               VectorSubtract(relativelightorigin, surf->poly_center, temp);
+                               if (DotProduct(temp, temp) < (surf->poly_radius2 + lightradius2))
                                {
-                                       R_Mesh_ResizeCheck(mesh->numverts * 2);
-                                       memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4]));
-                                       R_Shadow_Volume(mesh->numverts, mesh->numtriangles, varray_vertex, mesh->index, mesh->triangleneighbors, relativelightorigin, lightradius, projectdistance, visiblevolume);
+                                       for (mesh = surf->mesh;mesh;mesh = mesh->chain)
+                                       {
+                                               R_Mesh_ResizeCheck(mesh->numverts * 2);
+                                               memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4]));
+                                               R_Shadow_Volume(mesh->numverts, mesh->numtriangles, varray_vertex, mesh->index, mesh->triangleneighbors, relativelightorigin, lightradius, projectdistance, visiblevolume);
+                                       }
                                }
                        }
                }
@@ -1898,22 +1901,25 @@ void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, f
        GL_UseColorArray();
        for (i = 0, surf = ent->model->surfaces + ent->model->firstmodelsurface;i < ent->model->nummodelsurfaces;i++, surf++)
        {
-               f = PlaneDiff(relativelightorigin, surf->plane);
-               if (surf->flags & SURF_PLANEBACK)
-                       f = -f;
-               if (f >= -0.1 && f < lightradius)
+               if (surf->flags & SURF_SHADOWLIGHT)
                {
-                       f = PlaneDiff(modelorg, surf->plane);
+                       f = PlaneDiff(relativelightorigin, surf->plane);
                        if (surf->flags & SURF_PLANEBACK)
                                f = -f;
-                       if (f > 0)
+                       if (f >= -0.1 && f < lightradius)
                        {
-                               for (mesh = surf->mesh;mesh;mesh = mesh->chain)
+                               f = PlaneDiff(modelorg, surf->plane);
+                               if (surf->flags & SURF_PLANEBACK)
+                                       f = -f;
+                               if (f > 0)
                                {
-                                       R_Mesh_ResizeCheck(mesh->numverts);
-                                       memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4]));
-                                       R_Shadow_Light(mesh->numverts, mesh->normals, relativelightorigin, lightradius, lightdistbias, lightsubtract, lightcolor);
-                                       R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index);
+                                       for (mesh = surf->mesh;mesh;mesh = mesh->chain)
+                                       {
+                                               R_Mesh_ResizeCheck(mesh->numverts);
+                                               memcpy(varray_vertex, mesh->verts, mesh->numverts * sizeof(float[4]));
+                                               R_Shadow_Light(mesh->numverts, mesh->normals, relativelightorigin, lightradius, lightdistbias, lightsubtract, lightcolor);
+                                               R_Mesh_Draw(mesh->numverts, mesh->numtriangles, mesh->index);
+                                       }
                                }
                        }
                }
index 44bb23ffca98aa5fac17d5c399e1aa70f0ba8bf2..a499fd4c0f40384e3f516c03fcb06435939d24f2 100644 (file)
@@ -427,7 +427,7 @@ static void Mod_LoadTextures (lump_t *l)
                {
                        tx->flags |= SURF_LIGHTMAP;
                        if (!tx->fogtexture)
-                               tx->flags |= SURF_CLIPSOLID;
+                               tx->flags |= SURF_SHADOWCAST | SURF_SHADOWLIGHT;
                        tx->shader = &Cshader_wall_lightmap;
                }
 
@@ -1187,7 +1187,7 @@ void Mod_ProcessLightList(void)
        qbyte *pvs;
        for (lnum = 0, e = loadmodel->lights;lnum < loadmodel->numlights;lnum++, e++)
        {
-               e->cullradius2 = DotProduct(e->light, e->light) * (1.0f / (8192.0f * 8192.0f)) / (e->falloff * e->falloff) + 4096.0f;
+               e->cullradius2 = DotProduct(e->light, e->light) / (e->falloff * e->falloff * 8192.0f * 8192.0f);// + 4096.0f;
                if (e->cullradius2 > 4096.0f * 4096.0f)
                        e->cullradius2 = 4096.0f * 4096.0f;
                e->cullradius = sqrt(e->cullradius2);
@@ -1287,7 +1287,7 @@ void Mod_ProcessLightList(void)
                        svworld = Mod_ShadowBrush_NewWorld(loadmodel->mempool);
                        for (j = 0, surf = loadmodel->surfaces + loadmodel->firstmodelsurface;j < loadmodel->nummodelsurfaces;j++, surf++)
                        {
-                               if (!(surf->flags & SURF_CLIPSOLID))
+                               if (!(surf->flags & SURF_SHADOWCAST))
                                        continue;
                                f = DotProduct(e->origin, surf->plane->normal) - surf->plane->dist;
                                if (surf->flags & SURF_PLANEBACK)
@@ -1442,7 +1442,7 @@ void Mod_ProcessLightList(void)
 #if 1
                                for (j = 0, surf = loadmodel->surfaces + loadmodel->firstmodelsurface;j < loadmodel->nummodelsurfaces;j++, surf++)
                                {
-                                       if (!(surf->flags & SURF_CLIPSOLID))
+                                       if (!(surf->flags & SURF_SHADOWCAST))
                                                continue;
                                        /*
                                        if (surf->poly_maxs[0] < e->mins[0]
@@ -1541,7 +1541,7 @@ void Mod_ProcessLightList(void)
                                for (j = 0;j < e->numsurfaces;j++)
                                {
                                        surf = e->surfaces[j];
-                                       if (!(surf->flags & SURF_CLIPSOLID))
+                                       if (!(surf->flags & SURF_SHADOWCAST))
                                                continue;
                                        f = DotProduct(e->origin, surf->plane->normal) - surf->plane->dist;
                                        if (surf->flags & SURF_PLANEBACK)
@@ -3459,7 +3459,7 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
                        // (only used for shadow volumes)
                        mod->shadowmesh = Mod_ShadowMesh_Begin(originalloadmodel->mempool);
                        for (j = 0, surf = &mod->surfaces[mod->firstmodelsurface];j < mod->nummodelsurfaces;j++, surf++)
-                               if (surf->flags & SURF_CLIPSOLID)
+                               if (surf->flags & SURF_SHADOWCAST)
                                        Mod_ShadowMesh_AddPolygon(originalloadmodel->mempool, mod->shadowmesh, surf->poly_numverts, surf->poly_verts);
                        mod->shadowmesh = Mod_ShadowMesh_Finish(originalloadmodel->mempool, mod->shadowmesh);
                        Mod_ShadowMesh_CalcBBox(mod->shadowmesh, mod->shadowmesh_mins, mod->shadowmesh_maxs, mod->shadowmesh_center, &mod->shadowmesh_radius);
index ff58a377092b6d9c308bc6ff530d45fb6317a022..e928269894be7f585f5c86792db4e76ad598a096 100644 (file)
@@ -120,6 +120,8 @@ texture_t;
 #define SURF_DRAWFULLBRIGHT 0x200
 #define SURF_LIGHTBOTHSIDES 0x400
 #define SURF_CLIPSOLID 0x800 // this polygon can obscure other polygons
+#define SURF_SHADOWCAST 0x1000 // this polygon can cast stencil shadows
+#define SURF_SHADOWLIGHT 0x2000 // this polygon can be lit by stencil shadowing
 
 typedef struct
 {
index 4aa7b5aa41b3bf69a9b0d8daa8da1e60c78e8578..07fcb218408e8a3bc5f0146cbdd58adc0b17b4e0 100644 (file)
@@ -13,10 +13,10 @@ rtexturepool_t *r_shadow_texturepool;
 rtexture_t *r_shadow_attenuationtexture;
 
 cvar_t r_shadow1 = {0, "r_shadow1", "16"};
-cvar_t r_shadow2 = {0, "r_shadow2", "2"};
+cvar_t r_shadow2 = {0, "r_shadow2", "4"};
 cvar_t r_shadow3 = {0, "r_shadow3", "65536"};
 cvar_t r_shadow4 = {0, "r_shadow4", "1"};
-cvar_t r_shadow5 = {0, "r_shadow5", "0.05"};
+cvar_t r_shadow5 = {0, "r_shadow5", "0"};
 cvar_t r_shadow6 = {0, "r_shadow6", "1"};
 
 void r_shadow_start(void)
@@ -318,7 +318,7 @@ void R_Shadow_Stage_ShadowVolumes(void)
        qglColorMask(0, 0, 0, 0);
        qglDisable(GL_BLEND);
        qglDepthMask(0);
-       qglDepthFunc(GL_LEQUAL);
+       qglDepthFunc(GL_LESS);
        qglClearStencil(0);
        qglClear(GL_STENCIL_BUFFER_BIT);
        qglEnable(GL_STENCIL_TEST);