diff --git a/data/models/wooden_boxbarrel/wooden_box_and_barrel.mtl b/data/models/wooden_boxbarrel/wooden_box_and_barrel.mtl index 243438b..c1672a5 100644 --- a/data/models/wooden_boxbarrel/wooden_box_and_barrel.mtl +++ b/data/models/wooden_boxbarrel/wooden_box_and_barrel.mtl @@ -10,7 +10,7 @@ Ke 0.000000 0.000000 0.000000 Ni 1.450000 d 1.000000 illum 2 -map_Bump wooden box and barrel/boxes_DefaultMaterial_Normal.png +norm wooden box and barrel/boxes_DefaultMaterial_Normal.png map_Kd wooden box and barrel/boxes_DefaultMaterial_BaseColor.png map_Pr wooden box and barrel/boxes_DefaultMaterial_Roughness.jpg map_Pm wooden box and barrel/boxes_DefaultMaterial_Metallic.jpg diff --git a/data/shaders/pbrFragment.glsl b/data/shaders/pbrFragment.glsl index 73a5d8f..de490f5 100644 --- a/data/shaders/pbrFragment.glsl +++ b/data/shaders/pbrFragment.glsl @@ -126,5 +126,9 @@ void main() float metallic = texture(texture_rma1, ourTexCoord).g; float ao = texture(texture_rma1, ourTexCoord).b; + // Normals + // load and invert normal + vec3 normal = normalize(texture(texture_normal1, ourTexCoord).rgb * 2.0 - 1.0); + FragColor = vec4(PBR(albedo, roughness, metallic, ao), 1.0); } diff --git a/data/shaders/pbrVertex.glsl b/data/shaders/pbrVertex.glsl index 7e9d0b3..6ddd0af 100644 --- a/data/shaders/pbrVertex.glsl +++ b/data/shaders/pbrVertex.glsl @@ -8,8 +8,13 @@ uniform mat4 Model; out vec2 ourTexCoord; out vec3 ourNormCoord; + +//Pbr out vec3 WorldPos; +//Normals +out mat3 TBN; + void main() { gl_Position = MVP * Model * vec4(aPos, 1.0); diff --git a/src/Model.cpp b/src/Model.cpp index 6c84518..9c67d49 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -15,10 +15,14 @@ void Model::translate(glm::vec3 translation) { // set worldspace postition glm::mat4 trans = glm::mat4(1.0f); trans = glm::translate(trans, translation); - this->position = trans * this->position; + glm::vec3 position = trans * this->position; // set model transform - this->model = glm::translate(glm::mat4(1.0f), glm::vec3(this->position)); + this->model = glm::translate(glm::mat4(1.0f), glm::vec3(position)); + + // set position based on the current model + // TODO: turn this into a function if readability becomes an issue + this->position = model * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); } void Model::resize(glm::vec3 scale) { // set worldspace postition diff --git a/src/main.cpp b/src/main.cpp index 1ccf33d..e9740c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,6 +79,7 @@ int main(int argc, char **argv) { // Model gun(ROOT_DIR "data/models/gun/Cerberus_LP.FBX"); Model boxbarrel(ROOT_DIR "data/models/wooden_boxbarrel/wooden_box_and_barrel.obj"); + boxbarrel.translate(glm::vec3(0.0f, -1.0f, 0.0f)); // cube.translate(glm::vec3(3.0f, 0.0f, -1.0f)); // backpack.translate(glm::vec3(-3.0f, 0.0f, 0.0f)); // gun.translate(glm::vec3(0.0f, 1.0f, 0.0f));