summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Release/SoftShadeRoom.exebin133632 -> 130560 bytes
-rw-r--r--src/example/03_texture/03_texture.c21
-rw-r--r--src/extend/mesh.c42
-rw-r--r--src/main.c2
4 files changed, 42 insertions, 23 deletions
diff --git a/Release/SoftShadeRoom.exe b/Release/SoftShadeRoom.exe
index 34fe03d..db29a49 100644
--- a/Release/SoftShadeRoom.exe
+++ b/Release/SoftShadeRoom.exe
Binary files differ
diff --git a/src/example/03_texture/03_texture.c b/src/example/03_texture/03_texture.c
index a7857fa..5afb3de 100644
--- a/src/example/03_texture/03_texture.c
+++ b/src/example/03_texture/03_texture.c
@@ -94,27 +94,28 @@ EXAMPLE void ondraw_texture(void*data) {
*/
/*render mech*/
- //ssr_setuniformtex(0, mech_albedo);
- //ssr_setuniformtex(1, mech_normal);
- //ssr_setuniformtex(2, mech_roughness);
- //ssr_setuniformtex(3, mech_metalness);
- //ssr_bindvertices(mech_mesh->vertices, mech_mesh->vert_count, mech_mesh->triangles, mech_mesh->tris_count);
- //ssr_draw(PRIMITIVE_TRIANGLE);
+ ssr_setuniformtex(0, mech_albedo);
+ ssr_setuniformtex(1, mech_normal);
+ ssr_setuniformtex(2, mech_roughness);
+ ssr_setuniformtex(3, mech_metalness);
+ ssr_bindvertices(mech_mesh->vertices, mech_mesh->vert_count, mech_mesh->triangles, mech_mesh->tris_count);
+ ssr_draw(PRIMITIVE_TRIANGLE);
+
/*
ssr_setstencilfunc(STENCILFUNC_EQUAL, 1, 0xff);
ssr_setstencilop(STENCILOP_KEEP, STENCILOP_KEEP, STENCILOP_KEEP);
*/
/*render yingham*/
-// ssr_setuniformtex(0, yingham_albedo);
-// ssr_bindvertices(yingham_mesh->vertices, yingham_mesh->vert_count, yingham_mesh->triangles, yingham_mesh->tris_count);
-// ssr_draw(PRIMITIVE_TRIANGLE);
+ ssr_setuniformtex(0, yingham_albedo);
+ ssr_bindvertices(yingham_mesh->vertices, yingham_mesh->vert_count, yingham_mesh->triangles, yingham_mesh->tris_count);
+ ssr_draw(PRIMITIVE_TRIANGLE);
/*render ground*/
ssr_setuniformtex(0, ground_albedo);
ssr_bindvertices(ground_mesh->vertices, ground_mesh->vert_count, ground_mesh->triangles, ground_mesh->tris_count);
ssr_draw(PRIMITIVE_TRIANGLE);
- draw_tbn(ground_mesh, VISUAL_ALL, 10);
+ //draw_tbn(mech_mesh, VISUAL_ALL, 4);
//ssr_setuniformtex(0, cyborg_albedo);
//ssr_bindvertices(cyborg_mesh->vertices, cyborg_mesh->vert_count, cyborg_mesh->triangles, cyborg_mesh->tris_count);
diff --git a/src/extend/mesh.c b/src/extend/mesh.c
index e7685e6..90e8bf5 100644
--- a/src/extend/mesh.c
+++ b/src/extend/mesh.c
@@ -203,9 +203,19 @@ typedef struct {
Triangle* triangles; // triangles list
} MeshInfo;
+void free_mesh_info(MeshInfo* mesh) {
+ for (int i = 0; i < darray_size(mesh->vertices); ++i) {
+ darray_free(mesh->vertices[i].related_triangles);
+ }
+ darray_free(mesh->vertices);
+ darray_free(mesh->triangles);
+}
+
void calc_face_tanget(MeshInfo* mesh);
void calc_vertex_tangnet(MeshInfo* mesh);
+Mesh* build_mesh(MeshInfo* mesh_info);
+
Mesh* mesh_loadfromobj(const char* path) {
Vec3* position_list = NULL;
Vec3* normal_list = NULL;
@@ -268,7 +278,6 @@ Mesh* mesh_loadfromobj(const char* path) {
int vert_count = 0;
- //Mesh temp_mesh = {0};
MeshInfo mesh_info = {0};
for (int i = 0; i < darray_size(face_list); ++i)
@@ -322,26 +331,35 @@ Mesh* mesh_loadfromobj(const char* path) {
darray_push(mesh_info.triangles, triangle);
}
+#ifdef GENERATE_TANGNET
calc_face_tanget(&mesh_info);
calc_vertex_tangnet(&mesh_info);
+#endif
+
+ Mesh* mesh = build_mesh(&mesh_info);
+
+ free_mesh_info(&mesh_info);
+ return mesh;
+}
+
+Mesh* build_mesh(MeshInfo* mesh_info) {
Mesh* mesh = malloc(sizeof(Mesh));
- int num_of_face = darray_size(mesh_info.triangles) ;
+ int num_of_face = darray_size(mesh_info->triangles);
mesh->triangles = malloc(num_of_face * 3 * sizeof(uint));
- for (int i = 0; i < darray_size(mesh_info.triangles); ++i) {
- mesh->triangles[3 * i] = mesh_info.triangles[i].vertices[0];
- mesh->triangles[3 * i + 1] = mesh_info.triangles[i].vertices[1];
- mesh->triangles[3 * i + 2] = mesh_info.triangles[i].vertices[2];
+ for (int i = 0; i < darray_size(mesh_info->triangles); ++i) {
+ mesh->triangles[3 * i] = mesh_info->triangles[i].vertices[0];
+ mesh->triangles[3 * i + 1] = mesh_info->triangles[i].vertices[1];
+ mesh->triangles[3 * i + 2] = mesh_info->triangles[i].vertices[2];
}
mesh->tris_count = num_of_face;
- mesh->vertices = malloc(sizeof(Vert) * darray_size(mesh_info.vertices));
- for (int i = 0; i < darray_size(mesh_info.vertices); ++i) {
- mesh->vertices[i] = mesh_info.vertices[i].props;
+ mesh->vertices = malloc(sizeof(Vert) * darray_size(mesh_info->vertices));
+ for (int i = 0; i < darray_size(mesh_info->vertices); ++i) {
+ mesh->vertices[i] = mesh_info->vertices[i].props;
}
- mesh->vert_count = darray_size(mesh_info.vertices);
-
+ mesh->vert_count = darray_size(mesh_info->vertices);
return mesh;
-}
+}
void calc_face_tanget(MeshInfo* mesh) {
MeshVertexInfo* vertices = mesh->vertices;
diff --git a/src/main.c b/src/main.c
index 6ded680..850951b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -78,7 +78,7 @@ int main(int argc, char* argv[]) {
CameraConfig cam_config = {
{0, 10, 800},
{0, 0, 0},
- 60, SCREEN_WIDTH / SCREEN_HEIGHT, 0.1, 2000,
+ 60, SCREEN_WIDTH / SCREEN_HEIGHT, 0.1, 10000,
{5, 5}, {150, 150},
4000,
};