Skip to content

Commit

Permalink
update assets data.
Browse files Browse the repository at this point in the history
  • Loading branch information
gg-z committed Aug 16, 2019
1 parent 6559c16 commit 086c844
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
Binary file removed assets/assets.rar
Binary file not shown.
Binary file added assets/nrm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed exe/face_rendering.rar
Binary file not shown.
52 changes: 51 additions & 1 deletion src/includes/ind/loaders.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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,
Expand Down Expand Up @@ -34,14 +81,17 @@ 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);
poly->ns.clear(); poly->ns.reserve(num_verts);
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) {

Expand Down
23 changes: 11 additions & 12 deletions src/includes/ind/renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 1 addition & 1 deletion src/renderer_hm/face.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void LoadRes(World* world, std::string obj_path, std::string nrm_path ) {

world->lights = std::make_unique<std::vector<DirLightDesc>>(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;
Expand Down

0 comments on commit 086c844

Please sign in to comment.