when faces have short normals, we compute new unit-length normals

This commit is contained in:
myT 2019-09-13 01:02:47 +02:00
parent 3ae1abd69e
commit c44b13ad90
2 changed files with 30 additions and 7 deletions

View file

@ -5,6 +5,8 @@ fix: r_monitor on Linux is now 0-based and the value doesn't change incorrectly
fix: when a latched cvar's value is set to its default, the cvar is no longer marked as changed
fix: broken face normals get fixed up on map load, which helps with dynamic lights (e.g. industrial)
31 Mar 19 - 1.51

View file

@ -364,6 +364,27 @@ static void ParseFace( const dsurface_t* ds, const drawVert_t* verts, msurface_t
cv->plane.dist = DotProduct( cv->verts[0].xyz, cv->plane.normal );
SetPlaneSignbits( &cv->plane );
cv->plane.type = PlaneTypeForNormal( cv->plane.normal );
if ( numVerts >= 3 && numIndexes >= 3 && VectorLengthSquared(cv->plane.normal) < 0.01f ) {
// this face's normal is messed up, so we copy something new
vec3_t v1, v2, normal;
const int i0 = cv->indexes[0];
const int i1 = cv->indexes[1];
const int i2 = cv->indexes[2];
VectorSubtract(cv->verts[i2].xyz, cv->verts[i0].xyz, v1);
VectorSubtract(cv->verts[i1].xyz, cv->verts[i0].xyz, v2);
CrossProduct(v1, v2, normal);
VectorNormalize(normal);
for ( int i = 0; i < numVerts; ++i ) {
VectorCopy(normal, cv->verts[i].normal);
}
} else {
// copy the normal we already have
for ( int i = 0; i < numVerts; ++i ) {
VectorCopy(cv->plane.normal, cv->verts[i].normal);
}
}
}
@ -495,7 +516,7 @@ R_MergedWidthPoints
returns qtrue if there are grid points merged on a width edge
=================
*/
int R_MergedWidthPoints(srfGridMesh_t *grid, int offset) {
static int R_MergedWidthPoints(srfGridMesh_t *grid, int offset) {
int i, j;
for (i = 1; i < grid->width-1; i++) {
@ -516,7 +537,7 @@ R_MergedHeightPoints
returns qtrue if there are grid points merged on a height edge
=================
*/
int R_MergedHeightPoints(srfGridMesh_t *grid, int offset) {
static int R_MergedHeightPoints(srfGridMesh_t *grid, int offset) {
int i, j;
for (i = 1; i < grid->height-1; i++) {
@ -539,7 +560,7 @@ NOTE: never sync LoD through grid edges with merged points!
FIXME: write generalized version that also avoids cracks between a patch and one that meets half way?
=================
*/
void R_FixSharedVertexLodError_r( int start, srfGridMesh_t *grid1 ) {
static void R_FixSharedVertexLodError_r( int start, srfGridMesh_t *grid1 ) {
int j, k, l, m, n, offset1, offset2, touch;
srfGridMesh_t *grid2;
@ -651,7 +672,7 @@ This function assumes that all patches in one group are nicely stitched together
If this is not the case this function will still do its job but won't fix the highest LoD cracks.
=================
*/
void R_FixSharedVertexLodError( void ) {
static void R_FixSharedVertexLodError( void ) {
int i;
srfGridMesh_t *grid1;
@ -677,7 +698,7 @@ void R_FixSharedVertexLodError( void ) {
R_StitchPatches
===============
*/
int R_StitchPatches( int grid1num, int grid2num ) {
static int R_StitchPatches( int grid1num, int grid2num ) {
float *v1, *v2;
srfGridMesh_t *grid1, *grid2;
int k, l, m, n, offset1, offset2, row, column;
@ -1092,7 +1113,7 @@ of the patch (on the same row or column) the vertices will not be joined and cra
might still appear at that side.
===============
*/
int R_TryStitchingPatch( int grid1num ) {
static int R_TryStitchingPatch( int grid1num ) {
int j, numstitches;
srfGridMesh_t *grid1, *grid2;
@ -1123,7 +1144,7 @@ int R_TryStitchingPatch( int grid1num ) {
R_StitchAllPatches
===============
*/
void R_StitchAllPatches( void ) {
static void R_StitchAllPatches( void ) {
int i, stitched, numstitches;
srfGridMesh_t *grid1;