From: havoc Date: Sat, 20 Sep 2003 07:34:52 +0000 (+0000) Subject: finally managed to fix the r_shadow_portallight bug (had to reverse portal handling... X-Git-Tag: xonotic-v0.1.0preview~6370 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=020ac448eb9f40a6e13ea4b4ed611ab5cdefa7ea;p=xonotic%2Fdarkplaces.git finally managed to fix the r_shadow_portallight bug (had to reverse portal handling in many old broken cases), also changed the Portal_Visibility call to take a box instead of a sphere for culling git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3479 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/gl_rsurf.c b/gl_rsurf.c index 7bc9d736..38d17b11 100644 --- a/gl_rsurf.c +++ b/gl_rsurf.c @@ -857,7 +857,7 @@ static void RSurfShader_Water_Callback(const void *calldata1, int calldata2) if (gl_textureshader && r_watershader.integer) { GL_ActiveTexture (0); - qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D); + qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D); GL_ActiveTexture (1); qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_TEXTURE_2D); qglTexEnvi (GL_TEXTURE_SHADER_NV, GL_SHADER_OPERATION_NV, GL_OFFSET_TEXTURE_2D_NV); @@ -1549,7 +1549,7 @@ static void R_DrawPortal_Callback(const void *calldata1, int calldata2) ((i & 0x0038) >> 3) * (1.0f / 7.0f) * r_colorscale, ((i & 0x01C0) >> 6) * (1.0f / 7.0f) * r_colorscale, 0.125f); - if (PlaneDiff(r_origin, (&portal->plane)) > 0) + if (PlaneDiff(r_origin, (&portal->plane)) < 0) { for (i = portal->numpoints - 1, v = varray_vertex3f;i >= 0;i--, v += 3) VectorCopy(portal->points[i].position, v); diff --git a/model_brush.c b/model_brush.c index d6a220ea..2c577105 100644 --- a/model_brush.c +++ b/model_brush.c @@ -2308,9 +2308,9 @@ static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node) // create the new portal by generating a polygon for the node plane, // and clipping it by all of the other portals(which came from nodes above this one) nodeportal = AllocPortal(); - nodeportal->plane = *node->plane; + nodeportal->plane = *plane; - nodeportalwinding = Winding_NewFromPlane(node->plane->normal[0], node->plane->normal[1], node->plane->normal[2], node->plane->dist); + nodeportalwinding = Winding_NewFromPlane(nodeportal->plane.normal[0], nodeportal->plane.normal[1], nodeportal->plane.normal[2], nodeportal->plane.dist); side = 0; // shut up compiler warning for (portal = (portal_t *)node->portals;portal;portal = portal->next[side]) { diff --git a/portals.c b/portals.c index ba7de15d..725374b1 100644 --- a/portals.c +++ b/portals.c @@ -323,7 +323,8 @@ typedef struct portalrecursioninfo_s { int exact; int numfrustumplanes; - float nradius; + vec3_t boxmins; + vec3_t boxmaxs; qbyte *surfacemark; qbyte *leafmark; model_t *model; @@ -336,6 +337,7 @@ portalrecursioninfo_t; void Portal_RecursiveFlow_ExactMarkSurfaces(portalrecursioninfo_t *info, int *mark, int nummarksurfaces, int firstclipplane, int numclipplanes) { int i, j, *elements; + vec3_t trimins, trimaxs; msurface_t *surf; surfmesh_t *surfmesh; for (i = 0;i < nummarksurfaces;i++, mark++) @@ -367,9 +369,18 @@ void Portal_RecursiveFlow_ExactMarkSurfaces(portalrecursioninfo_t *info, int *ma VectorCopy((surfmesh->vertex3f + elements[0] * 3), trianglepoints[0]); VectorCopy((surfmesh->vertex3f + elements[1] * 3), trianglepoints[1]); VectorCopy((surfmesh->vertex3f + elements[2] * 3), trianglepoints[2]); - if (PointInfrontOfTriangle(info->eye, trianglepoints[0], trianglepoints[1], trianglepoints[2]) - && Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, trianglepoints[0], 3, &portaltemppoints2[0][0], 256) >= 3) - break; + if (PointInfrontOfTriangle(info->eye, trianglepoints[0], trianglepoints[1], trianglepoints[2])) + { + trimins[0] = min(trianglepoints[0][0], min(trianglepoints[1][0], trianglepoints[2][0])); + trimaxs[0] = max(trianglepoints[0][0], max(trianglepoints[1][0], trianglepoints[2][0])); + trimins[1] = min(trianglepoints[0][1], min(trianglepoints[1][1], trianglepoints[2][1])); + trimaxs[1] = max(trianglepoints[0][1], max(trianglepoints[1][1], trianglepoints[2][1])); + trimins[2] = min(trianglepoints[0][2], min(trianglepoints[1][2], trianglepoints[2][2])); + trimaxs[2] = max(trianglepoints[0][2], max(trianglepoints[1][2], trianglepoints[2][2])); + if (BoxesOverlap(trimins, trimaxs, info->boxmins, info->boxmaxs)) + if (Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, trianglepoints[0], 3, &portaltemppoints2[0][0], 256) >= 3) + break; + } } if (j < surfmesh->numtriangles) break; @@ -412,9 +423,9 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first // follow portals into other leafs for (p = leaf->portals;p;p = p->next) { - // only flow through portals facing away from the viewer + // only flow through portals facing the viewer dist = PlaneDiff(info->eye, (&p->plane)); - if (dist < 0 && dist >= info->nradius) + if (dist < 0 && BoxesOverlap(p->past->mins, p->past->maxs, info->boxmins, info->boxmaxs)) { newpoints = Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, (float *) p->points, p->numpoints, &portaltemppoints2[0][0], 256); if (newpoints < 3) @@ -433,8 +444,8 @@ void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int first newplanes = &portalplanes[firstclipplane + numclipplanes]; for (prev = newpoints - 1, i = 0;i < newpoints;prev = i, i++) { - VectorSubtract(info->eye, portaltemppoints2[i], v1); - VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v2); + VectorSubtract(portaltemppoints2[prev], portaltemppoints2[i], v1); + VectorSubtract(info->eye, portaltemppoints2[i], v2); CrossProduct(v1, v2, newplanes[i].normal); VectorNormalizeFast(newplanes[i].normal); newplanes[i].dist = DotProduct(info->eye, newplanes[i].normal); @@ -470,7 +481,7 @@ void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node) } } -void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, float radius, float *updateleafsmins, float *updateleafsmaxs) +void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, const float *boxmins, const float *boxmaxs, float *updateleafsmins, float *updateleafsmaxs) { int i; portalrecursioninfo_t info; @@ -500,7 +511,8 @@ void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte ranoutofportalplanes = false; ranoutofportals = false; - info.nradius = -radius; + VectorCopy(boxmins, info.boxmins); + VectorCopy(boxmaxs, info.boxmaxs); info.exact = exact; info.surfacemark = surfacemark; info.leafmark = leafmark; diff --git a/portals.h b/portals.h index 92844732..6e96ce01 100644 --- a/portals.h +++ b/portals.h @@ -4,7 +4,7 @@ int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpoints); int Portal_CheckBox(model_t *model, vec3_t eye, vec3_t a, vec3_t b); -void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, float radius, float *updateleafsmins, float *updateleafsmaxs); +void Portal_Visibility(model_t *model, const vec3_t eye, qbyte *leafmark, qbyte *surfacemark, const mplane_t *frustumplanes, int numfrustumplanes, int exact, const float *boxmins, const float *boxmaxs, float *updateleafsmins, float *updateleafsmaxs); #endif diff --git a/r_shadow.c b/r_shadow.c index 160d4cca..453d0a49 100644 --- a/r_shadow.c +++ b/r_shadow.c @@ -1760,7 +1760,7 @@ void R_Shadow_NewWorldLight(vec3_t origin, float radius, vec3_t color, int style //byteleafpvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.numleafs); bytesurfacepvs = Mem_Alloc(tempmempool, cl.worldmodel->brushq1.numsurfaces); - Portal_Visibility(cl.worldmodel, e->origin, NULL/*byteleafpvs*/, bytesurfacepvs, NULL, 0, true, RadiusFromBoundsAndOrigin(e->mins, e->maxs, e->origin), e->mins, e->maxs); + Portal_Visibility(cl.worldmodel, e->origin, NULL/*byteleafpvs*/, bytesurfacepvs, NULL, 0, true, mins, maxs, e->mins, e->maxs); /* for (i = 0, leaf = cl.worldmodel->brushq1.leafs;i < cl.worldmodel->brushq1.numleafs;i++, leaf++) diff --git a/todo b/todo index 0eeeef5b..601e4d1e 100644 --- a/todo +++ b/todo @@ -12,6 +12,8 @@ -n darkplaces: server is starting before the "port" cvar is set by commandline and scripts? (yummyluv) -n darkplaces: typing ip in join game menu should show 'trying' and 'no response' after a while, or 'no network' if networking is not initialized (yummyluv) -n dpmod: make grapple off-hand (joe hill) +0 darkplaces: make a getattachmentvectors qc builtin (Supajoe) +0 darkplaces: add _reflect textures which filter use of skybox as a cubemap reflection (FrikaC) 0 darkplaces: ability to disable fopen builtin access to read /, read data/, write data/, or disable fopen builtin entirely 0 darkplaces: add DP_GFX_QUAKE3MODELTAGS, DP_GFX_SKINFILES, and any other new extensions to the wiki 0 darkplaces: add DP_LITSUPPORT extension and document it diff --git a/winding.c b/winding.c index 441bc733..24409026 100644 --- a/winding.c +++ b/winding.c @@ -94,6 +94,16 @@ winding_t *Winding_NewFromPlane(double normalx, double normaly, double normalz, VectorSubtract(org, vright, w->points[3]); VectorSubtract(w->points[3], vup, w->points[3]); +#if 0 + { + double n[3]; + TriangleNormal(w->points[0], w->points[1], w->points[2], n); + VectorNormalize(n); + if (fabs(DotProduct(n, normal) - 1) > 0.01f) + Con_Printf("%.0f %.0f %.0f (%.0f %.0f %.0f, %.0f %.0f %.0f) != %.0f %.0f %.0f (%.0f %.0f %.0f, %.0f %.0f %.0f, %.0f %.0f %.0f, %.0f %.0f %.0f)\n", normal[0], normal[1], normal[2], vright[0], vright[1], vright[2], vup[0], vup[1], vup[2], n[0], n[1], n[2], w->points[0][0], w->points[0][1], w->points[0][2], w->points[1][0], w->points[1][1], w->points[1][2], w->points[2][0], w->points[2][1], w->points[2][2], w->points[3][0], w->points[3][1], w->points[3][2]); + } +#endif + w->numpoints = 4; return w;