Flip the Y texture coordinate when loading the OBJ model
This commit is contained in:
parent
cee57282cb
commit
185f44252f
@ -56,7 +56,7 @@ Model load_obj_file(Arena *arena, const char *filename, const char *texture,
|
|||||||
} else if (strncmp(identifier, "vt", 8) == 0) {
|
} else if (strncmp(identifier, "vt", 8) == 0) {
|
||||||
sscanf(line + 2, "%f %f", &u, &v);
|
sscanf(line + 2, "%f %f", &u, &v);
|
||||||
coord.u = u;
|
coord.u = u;
|
||||||
coord.v = v;
|
coord.v = 1.0f - v;
|
||||||
list_append(V2f, arena, model.texture_coordinates, coord);
|
list_append(V2f, arena, model.texture_coordinates, coord);
|
||||||
} else if (strncmp(identifier, "f", 8) == 0) {
|
} else if (strncmp(identifier, "f", 8) == 0) {
|
||||||
sscanf(line + 2, "%lu/%lu/%lu %lu/%lu/%lu %lu/%lu/%lu", &fp0, &tx0, &vn0,
|
sscanf(line + 2, "%lu/%lu/%lu %lu/%lu/%lu %lu/%lu/%lu", &fp0, &tx0, &vn0,
|
||||||
|
@ -94,7 +94,7 @@ internal FragmentResult phong_shader_fragment(void *shader,
|
|||||||
V3f norm;
|
V3f norm;
|
||||||
if (model->normal) {
|
if (model->normal) {
|
||||||
u64 nm_x = data->tex_coords.u * model->normal->width;
|
u64 nm_x = data->tex_coords.u * model->normal->width;
|
||||||
u64 nm_y = (1.0f - data->tex_coords.v) * model->normal->height;
|
u64 nm_y = data->tex_coords.v * model->normal->height;
|
||||||
|
|
||||||
Colour pixel = get_pixel(Colour, model->normal, nm_x, nm_y);
|
Colour pixel = get_pixel(Colour, model->normal, nm_x, nm_y);
|
||||||
hnorm = (V4f){
|
hnorm = (V4f){
|
||||||
@ -118,7 +118,7 @@ internal FragmentResult phong_shader_fragment(void *shader,
|
|||||||
Colour output;
|
Colour output;
|
||||||
if (model->texture) {
|
if (model->texture) {
|
||||||
u64 tx_x = data->tex_coords.u * model->texture->width;
|
u64 tx_x = data->tex_coords.u * model->texture->width;
|
||||||
u64 tx_y = (1.0f - data->tex_coords.v) * model->texture->height;
|
u64 tx_y = data->tex_coords.v * model->texture->height;
|
||||||
output = get_pixel(Colour, model->texture, tx_x, tx_y);
|
output = get_pixel(Colour, model->texture, tx_x, tx_y);
|
||||||
} else {
|
} else {
|
||||||
output = *colour;
|
output = *colour;
|
||||||
|
Loading…
Reference in New Issue
Block a user