medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 160046f721c555f5d5af793d9ce0c5ca71181383
parent ab6c98400312486a653c2700da10c2a0437cd4da
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Nov 13 22:21:15 +0200

Warnings, helpful comment

Diffstat:
pp.cc | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/pp.cc b/pp.cc @@ -62,6 +62,8 @@ static void compute_horizons( } static void compute_normals( const array2d< u8 > heightmap, array2d< v3 > normals ) { + // estimate the gradient at each point by doing central differences on + // each axis, then cross the tangent and bitangent to find the normal for( size_t y = 0; y < heightmap.h; y++ ) { for( size_t x = 0; x < heightmap.w; x++ ) { size_t x_plus_one = x + 1; @@ -74,8 +76,14 @@ static void compute_normals( const array2d< u8 > heightmap, array2d< v3 > normal if( y == 0 ) y_minus_one = y; if( y == heightmap.h - 1 ) y_plus_one = y; - v3 tangent( checked_cast< float >( x_plus_one - x_minus_one ), 0.0f, heightmap( x_plus_one, y ) - heightmap( x_minus_one, y ) ); - v3 bitangent( 0.0f, checked_cast< float >( y_plus_one - y_minus_one ), heightmap( x, y_plus_one ) - heightmap( x, y_minus_one ) ); + v3 tangent( + checked_cast< float >( x_plus_one - x_minus_one ), + 0.0f, + checked_cast< float >( heightmap( x_plus_one, y ) - heightmap( x_minus_one, y ) ) ); + v3 bitangent( + 0.0f, + checked_cast< float >( y_plus_one - y_minus_one ), + checked_cast< float >( heightmap( x, y_plus_one ) - heightmap( x, y_minus_one ) ) ); normals( x, y ) = normalize( cross( tangent, bitangent ) ); }