diff --git a/assets/assets.rar b/assets/assets.rar deleted file mode 100644 index efb50d7..0000000 Binary files a/assets/assets.rar and /dev/null differ diff --git a/assets/nrm.png b/assets/nrm.png new file mode 100644 index 0000000..7be57c0 Binary files /dev/null and b/assets/nrm.png differ diff --git a/exe/face_rendering.rar b/exe/face_rendering.rar deleted file mode 100644 index c7b1b70..0000000 Binary files a/exe/face_rendering.rar and /dev/null differ diff --git a/src/includes/ind/loaders.cc b/src/includes/ind/loaders.cc index 028ad6a..61ec609 100644 --- a/src/includes/ind/loaders.cc +++ b/src/includes/ind/loaders.cc @@ -7,6 +7,53 @@ #define TINYOBJLOADER_IMPLEMENTATION #include "tiny_obj_loader.h" +void GenNormal(tinyobj::attrib_t &shape, tinyobj::mesh_t &mesh, float angle) { + + const float pi = 3.14159; + /* calculate the cosine of the angle (in degrees) */ + float cos_angle = cos(angle * pi / 180.0); + + + /* allocate space for new normals */ + shape.normals.resize(shape.vertices.size()); + for (size_t i = 0; i < shape.vertices.size(); i++) + shape.normals[i] = 0; + + std::vector count(shape.vertices.size()/3,0); + glm::vec3 u, v, n; + for (size_t i = 0; i < mesh.indices.size(); i += 3) { + + unsigned int indexX = 3 * mesh.indices[i].vertex_index; + unsigned int indexY = 3 * mesh.indices[i+1].vertex_index; + unsigned int indexZ = 3 * mesh.indices[i+2].vertex_index; + + mesh.indices[i].normal_index = mesh.indices[i].vertex_index; + mesh.indices[i+1].normal_index = mesh.indices[i+1].vertex_index; + mesh.indices[i+2].normal_index = mesh.indices[i+2].vertex_index; + + u[0] = shape.vertices[indexY + 0] - + shape.vertices[indexX + 0]; + u[1] = shape.vertices[indexY + 1] - + shape.vertices[indexX + 1]; + u[2] = shape.vertices[indexY + 2] - + shape.vertices[indexX + 2]; + + v[0] = shape.vertices[indexZ + 0] - + shape.vertices[indexX + 0]; + v[1] = shape.vertices[indexZ + 1] - + shape.vertices[indexX + 1]; + v[2] = shape.vertices[indexZ + 2] - + shape.vertices[indexX + 2]; + + n = glm::cross(u, v); n = glm::normalize(n); count[int(indexX / 3)] += 1; + shape.normals[indexX] += n.x; shape.normals[indexX + 1] += n.y; shape.normals[indexX + 2] += n.z; + shape.normals[indexY] += n.x; shape.normals[indexY + 1] += n.y; shape.normals[indexY + 2] += n.z; + shape.normals[indexZ] += n.x; shape.normals[indexZ + 1] += n.y; shape.normals[indexZ + 2] += n.z; + } + + for (size_t i = 0; i < shape.vertices.size(); i++) + shape.normals[i] /= count[int(i / 3)]; +} void ReadObjFile( std::string objpath, @@ -34,7 +81,7 @@ void ReadObjFile( IND_ASSERT(is_success, ""); IND_ASSERT(shapes.size() == 1, "Only one shape at a time."); - + auto &mesh = shapes.front().mesh; auto num_verts = mesh.num_face_vertices.size() * 3; poly->ps.clear(); poly->ps.reserve(num_verts); @@ -42,6 +89,9 @@ void ReadObjFile( poly->ts.clear(); poly->ts.reserve(num_verts / 3 * 2); poly->tgts.clear(); poly->tgts.reserve(num_verts); + if (attrib.normals.size() == 0) + GenNormal(attrib, mesh, 90); + for (std::size_t kthvert = 0; kthvert < size_t(num_verts/3); ++kthvert) { diff --git a/src/includes/ind/renderer.cc b/src/includes/ind/renderer.cc index 5c2a4e1..a7ef17b 100644 --- a/src/includes/ind/renderer.cc +++ b/src/includes/ind/renderer.cc @@ -17,21 +17,20 @@ Renderer::Renderer( s_beta = 0.18; albedo = 0.7; - lht_color[0] = 0.9; lht_color[1] = 0.9; lht_color[2] = 0.9; - obj_color[0] = 0.9; - obj_color[1] = 0.9; - obj_color[2] = 0.9; - amb_color[0] = 0.2; - amb_color[1] = 0.2; - amb_color[2] = 0.2; - spec_color[0] = 0.5; - spec_color[1] = 0.5; - spec_color[2] = 0.5; - - Kd = 0.8f; + obj_color[0] = 0.7; + obj_color[1] = 0.7; + obj_color[2] = 0.7; + amb_color[0] = 0.34; + amb_color[1] = 0.34; + amb_color[2] = 0.34; + spec_color[0] = 0.24; + spec_color[1] = 0.24; + spec_color[2] = 0.24; + + Kd = 0.85f; } diff --git a/src/renderer_hm/face.cc b/src/renderer_hm/face.cc index a44c003..4765adf 100644 --- a/src/renderer_hm/face.cc +++ b/src/renderer_hm/face.cc @@ -57,7 +57,7 @@ void LoadRes(World* world, std::string obj_path, std::string nrm_path ) { world->lights = std::make_unique>(1); for (size_t i = 0; i < world->lights.get()->size(); i++) { - world->lights->at(i).dir = glm::vec3(1, -1, 0); + world->lights->at(i).dir = glm::vec3(1, 1, 0.4); world->lights->at(i).color = glm::vec3(1.0f); world->lights->at(i).shadow_w = kWindowWidth*4; world->lights->at(i).shadow_h = kWindowHeight*4;