@@ -326,12 +326,10 @@ static int is_back_facing(vec3_t ndc_coords[3]) {
326
326
* for viewport transformation, see subsection 2.12.1 of
327
327
* https://www.khronos.org/registry/OpenGL/specs/es/2.0/es_full_spec_2.0.pdf
328
328
*/
329
- static vec3_t viewport_transform (int width_ , int height_ , vec3_t ndc_coord ) {
330
- float width = (float )width_ ;
331
- float height = (float )height_ ;
332
- float x = (ndc_coord .x + 1 ) * 0.5f * width ; /* [-1, 1] -> [0, w] */
333
- float y = (ndc_coord .y + 1 ) * 0.5f * height ; /* [-1, 1] -> [0, h] */
334
- float z = (ndc_coord .z + 1 ) * 0.5f ; /* [-1, 1] -> [0, 1] */
329
+ static vec3_t viewport_transform (int width , int height , vec3_t ndc_coord ) {
330
+ float x = (ndc_coord .x + 1 ) * 0.5f * (float )width ; /* [-1, 1] -> [0, w] */
331
+ float y = (ndc_coord .y + 1 ) * 0.5f * (float )height ; /* [-1, 1] -> [0, h] */
332
+ float z = (ndc_coord .z + 1 ) * 0.5f ; /* [-1, 1] -> [0, 1] */
335
333
return vec3_new (x , y , z );
336
334
}
337
335
@@ -346,11 +344,8 @@ static int max_integer(int a, int b) {
346
344
}
347
345
348
346
static bbox_t find_bounding_box (vec2_t abc [3 ], int width , int height ) {
349
- vec2_t a = abc [0 ];
350
- vec2_t b = abc [1 ];
351
- vec2_t c = abc [2 ];
352
- vec2_t min = vec2_min (vec2_min (a , b ), c );
353
- vec2_t max = vec2_max (vec2_max (a , b ), c );
347
+ vec2_t min = vec2_min (vec2_min (abc [0 ], abc [1 ]), abc [2 ]);
348
+ vec2_t max = vec2_max (vec2_max (abc [0 ], abc [1 ]), abc [2 ]);
354
349
bbox_t bbox ;
355
350
bbox .min_x = max_integer ((int )ceil (min .x ), 0 );
356
351
bbox .min_y = max_integer ((int )ceil (min .y ), 0 );
@@ -397,10 +392,10 @@ static vec3_t calculate_weights(vec2_t abc[3], vec2_t p) {
397
392
* https://www.khronos.org/registry/OpenGL/specs/es/2.0/es_full_spec_2.0.pdf
398
393
*/
399
394
static float interpolate_depth (float screen_depths [3 ], vec3_t weights ) {
400
- float depth0 = screen_depths [0 ];
401
- float depth1 = screen_depths [1 ];
402
- float depth2 = screen_depths [2 ];
403
- return depth0 * weights . x + depth1 * weights . y + depth2 * weights . z ;
395
+ float depth0 = screen_depths [0 ] * weights . x ;
396
+ float depth1 = screen_depths [1 ] * weights . y ;
397
+ float depth2 = screen_depths [2 ] * weights . z ;
398
+ return depth0 + depth1 + depth2 ;
404
399
}
405
400
406
401
/*
0 commit comments