From a19627d2c9f794b81d69aefb2c7a20d3f5d63fab Mon Sep 17 00:00:00 2001 From: James Canete Date: Thu, 26 Apr 2012 13:20:17 +0000 Subject: [PATCH] Change R_SubdividePatchToGrid() to subdivide patches more evenly --- reaction/Reaction-ChangeLog | 1 + reaction/code/renderergl2/tr_curve.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/reaction/Reaction-ChangeLog b/reaction/Reaction-ChangeLog index a23d71cf..e1f5244b 100644 --- a/reaction/Reaction-ChangeLog +++ b/reaction/Reaction-ChangeLog @@ -1,3 +1,4 @@ +- Change R_SubdividePatchToGrid() to subdivide patches more evenly - Calculate tangent space in fragment shader instead of storing per vertex - Fix sun flare with sky portals. Sun flare must be inside sky portal. - Speed up tone mapping diff --git a/reaction/code/renderergl2/tr_curve.c b/reaction/code/renderergl2/tr_curve.c index 9add905e..1f01a1d8 100644 --- a/reaction/code/renderergl2/tr_curve.c +++ b/reaction/code/renderergl2/tr_curve.c @@ -520,6 +520,7 @@ srfGridMesh_t *R_SubdividePatchToGrid( int width, int height, float errorTable[2][MAX_GRID_SIZE]; int numTriangles; static srfTriangle_t triangles[(MAX_GRID_SIZE-1)*(MAX_GRID_SIZE-1)*2]; + int consecutiveComplete; for ( i = 0 ; i < width ; i++ ) { for ( j = 0 ; j < height ; j++ ) { @@ -533,8 +534,10 @@ srfGridMesh_t *R_SubdividePatchToGrid( int width, int height, errorTable[dir][j] = 0; } + consecutiveComplete = 0; + // horizontal subdivisions - for ( j = 0 ; j + 2 < width ; j += 2 ) { + for ( j = 0 ; ; j = (j + 2) % (width - 2) ) { // check subdivided midpoints against control points // FIXME: also check midpoints of adjacent patches against the control points @@ -576,20 +579,30 @@ srfGridMesh_t *R_SubdividePatchToGrid( int width, int height, // if all the points are on the lines, remove the entire columns if ( maxLen < 0.1f ) { errorTable[dir][j+1] = 999; + consecutiveComplete++; + // if we go over the whole grid twice without adding any columns, stop + if (consecutiveComplete >= (width - 2)) + break; continue; } // see if we want to insert subdivided columns if ( width + 2 > MAX_GRID_SIZE ) { errorTable[dir][j+1] = 1.0f/maxLen; - continue; // can't subdivide any more + break; // can't subdivide any more } if ( maxLen <= r_subdivisions->value ) { errorTable[dir][j+1] = 1.0f/maxLen; + consecutiveComplete++; + // if we go over the whole grid twice without adding any columns, stop + if (consecutiveComplete >= (width - 2)) + break; continue; // didn't need subdivision } + consecutiveComplete = 0; + errorTable[dir][j+2] = 1.0f/maxLen; // insert two columns and replace the peak @@ -607,9 +620,8 @@ srfGridMesh_t *R_SubdividePatchToGrid( int width, int height, ctrl[i][j + 3] = next; } - // back up and recheck this set again, it may need more subdivision - j -= 2; - + // skip the new one, we'll get it on the next pass + j += 2; } Transpose( width, height, ctrl );