Implement tangent normals and switch to using basic diffuse shader

This commit is contained in:
2024-09-01 22:30:04 +01:00
parent 84fbb711e1
commit cf8c681474
4 changed files with 81 additions and 127 deletions

View File

@@ -5,7 +5,6 @@
#include "render.h"
#include "shaders.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
@@ -19,7 +18,11 @@ enum {
TINY_EXIT_MODEL_LOAD_FAILED,
};
int main(void) {
int tinyrenderer(void);
int main(void) { return tinyrenderer(); }
int tinyrenderer(void) {
Arena *arena = NULL;
if (!wapp_mem_arena_init(&arena, GB(10))) {
return TINY_EXIT_ARENA_INIT_FAILED;
@@ -33,23 +36,15 @@ int main(void) {
}
Model obj = load_obj_file(arena, RESOURCE("head.obj"), RESOURCE("head.pnm"),
RESOURCE("head_nm.pnm"));
RESOURCE("head_nm_tangent.pnm"));
if (IS_INVALID_MODEL(obj)) {
return TINY_EXIT_MODEL_LOAD_FAILED;
}
PhongMaterial material = {
.ambient = 0.3f,
.diffuse = 1.5f,
.specular = 2.0f,
.shininess = 1.5f,
};
obj.material = material;
load_shaders();
clear_buffer(&(render.img), &bg);
render_model(&obj, &render, perspective_phong, RENDER_TYPE_SHADED, teal);
render_model(&obj, &render, perspective_diffuse, RENDER_TYPE_SHADED, teal);
save_image(&(render.img), "result.pam");
wapp_mem_arena_destroy(&arena);