Skip to content

Commit

Permalink
Refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
zauonlok committed Apr 8, 2020
1 parent c4d50ec commit 4c9c833
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions renderer/core/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,10 @@ static int is_back_facing(vec3_t ndc_coords[3]) {
* for viewport transformation, see subsection 2.12.1 of
* https://www.khronos.org/registry/OpenGL/specs/es/2.0/es_full_spec_2.0.pdf
*/
static vec3_t viewport_transform(int width_, int height_, vec3_t ndc_coord) {
float width = (float)width_;
float height = (float)height_;
float x = (ndc_coord.x + 1) * 0.5f * width; /* [-1, 1] -> [0, w] */
float y = (ndc_coord.y + 1) * 0.5f * height; /* [-1, 1] -> [0, h] */
float z = (ndc_coord.z + 1) * 0.5f; /* [-1, 1] -> [0, 1] */
static vec3_t viewport_transform(int width, int height, vec3_t ndc_coord) {
float x = (ndc_coord.x + 1) * 0.5f * (float)width; /* [-1, 1] -> [0, w] */
float y = (ndc_coord.y + 1) * 0.5f * (float)height; /* [-1, 1] -> [0, h] */
float z = (ndc_coord.z + 1) * 0.5f; /* [-1, 1] -> [0, 1] */
return vec3_new(x, y, z);
}

Expand All @@ -346,11 +344,8 @@ static int max_integer(int a, int b) {
}

static bbox_t find_bounding_box(vec2_t abc[3], int width, int height) {
vec2_t a = abc[0];
vec2_t b = abc[1];
vec2_t c = abc[2];
vec2_t min = vec2_min(vec2_min(a, b), c);
vec2_t max = vec2_max(vec2_max(a, b), c);
vec2_t min = vec2_min(vec2_min(abc[0], abc[1]), abc[2]);
vec2_t max = vec2_max(vec2_max(abc[0], abc[1]), abc[2]);
bbox_t bbox;
bbox.min_x = max_integer((int)ceil(min.x), 0);
bbox.min_y = max_integer((int)ceil(min.y), 0);
Expand Down Expand Up @@ -397,10 +392,10 @@ static vec3_t calculate_weights(vec2_t abc[3], vec2_t p) {
* https://www.khronos.org/registry/OpenGL/specs/es/2.0/es_full_spec_2.0.pdf
*/
static float interpolate_depth(float screen_depths[3], vec3_t weights) {
float depth0 = screen_depths[0];
float depth1 = screen_depths[1];
float depth2 = screen_depths[2];
return depth0 * weights.x + depth1 * weights.y + depth2 * weights.z;
float depth0 = screen_depths[0] * weights.x;
float depth1 = screen_depths[1] * weights.y;
float depth2 = screen_depths[2] * weights.z;
return depth0 + depth1 + depth2;
}

/*
Expand Down

0 comments on commit 4c9c833

Please sign in to comment.