Almost got metallisism working I just don't know what's up with the textures again.
This commit is contained in:
parent
7e3a7f0df7
commit
1e5544ce1f
14 changed files with 1708 additions and 22 deletions
Binary file not shown.
|
After Width: | Height: | Size: 980 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.5 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.4 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 696 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 952 KiB |
BIN
data/models/wooden_boxbarrel/wooden_box_and_barrel.blend
Normal file
BIN
data/models/wooden_boxbarrel/wooden_box_and_barrel.blend
Normal file
Binary file not shown.
16
data/models/wooden_boxbarrel/wooden_box_and_barrel.mtl
Normal file
16
data/models/wooden_boxbarrel/wooden_box_and_barrel.mtl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Blender MTL File: 'wooden_box_and_barrel.blend'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Material.001
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
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
|
||||
map_Kd wooden box and barrel/boxes_DefaultMaterial_BaseColor.png
|
||||
map_Ns wooden box and barrel/boxes_DefaultMaterial_Roughness.png
|
||||
map_Pm wooden box and barrel/boxes_DefaultMaterial_Metallic.png
|
||||
1650
data/models/wooden_boxbarrel/wooden_box_and_barrel.obj
Normal file
1650
data/models/wooden_boxbarrel/wooden_box_and_barrel.obj
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -3,10 +3,10 @@ out vec4 FragColor;
|
|||
|
||||
in vec2 ourTexCoord;
|
||||
in vec3 ourNormCoord;
|
||||
in vec3 FragPos;
|
||||
in vec3 WorldPos;
|
||||
|
||||
// TODO: make temporary hard coded world/camera pos dynamic
|
||||
uniform vec3 WorldPos ;
|
||||
//uniform vec3 WorldPos ;
|
||||
uniform vec3 CameraPos;
|
||||
uniform int tick;
|
||||
//vec3 WorldPos = vec3(0.0f, 0.0f, 0.0f);
|
||||
|
|
@ -18,16 +18,17 @@ vec3 albedo = vec3(0.8f, 0.8f, 0.8f);
|
|||
//float roughness = sin(tick / 60 * 0.3f);
|
||||
//float ao = sin(tick / 60 * 0.8f);
|
||||
|
||||
float metallic = 0.3f;
|
||||
//float metallic = 0.3f;
|
||||
float roughness = 0.3f;
|
||||
float ao = 0.8f;
|
||||
|
||||
// Handle multiple textures from the Mesh Object (Might not even be used)
|
||||
uniform sampler2D texture_diffuse1;
|
||||
uniform sampler2D texture_diffuse2;
|
||||
uniform sampler2D texture_diffuse3;
|
||||
uniform sampler2D texture_specular1;
|
||||
uniform sampler2D texture_specular2;
|
||||
uniform sampler2D texture_metalness1;
|
||||
uniform sampler2D texture_metalness2;
|
||||
|
||||
// PBR functions from learnOpenGL.com
|
||||
const float PI = 3.14159265359;
|
||||
|
|
@ -73,6 +74,7 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
|||
void main()
|
||||
{
|
||||
//albedo = vec3(texture(texture_diffuse1, ourTexCoord));
|
||||
float metallic = texture(texture_metalness1, ourTexCoord).r;
|
||||
// Establish ambient lighting
|
||||
float ambientStrength = 0.1;
|
||||
|
||||
|
|
@ -119,6 +121,7 @@ void main()
|
|||
color = color / (color + vec3(1.0));
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
|
||||
//FragColor = vec4(CameraPos, 1.0);
|
||||
//FragColor = texture(texture_diffuse1, ourTexCoord);
|
||||
//FragColor = texture(texture_metalness1, ourTexCoord);
|
||||
FragColor = texture(texture_diffuse1, ourTexCoord) * vec4(color, 0.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ uniform mat4 Model;
|
|||
|
||||
out vec2 ourTexCoord;
|
||||
out vec3 ourNormCoord;
|
||||
out vec3 FragPos;
|
||||
out vec3 WorldPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -17,5 +17,5 @@ void main()
|
|||
ourTexCoord = aTexCoord;
|
||||
|
||||
// Calculate position of fragment
|
||||
FragPos = vec3(Model * vec4(aPos, 1.0));
|
||||
WorldPos = vec3(Model * vec4(aPos, 1.0));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ void Mesh::setupMesh() {
|
|||
void Mesh::draw(ShaderLoader &shader) {
|
||||
unsigned int diffuseNr = 1;
|
||||
unsigned int specularNr = 1;
|
||||
unsigned int metalNr = 1;
|
||||
for (unsigned int i = 0; i < textures.size(); i++) {
|
||||
// activate proper texture unit before binding
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
|
|
@ -52,9 +53,15 @@ void Mesh::draw(ShaderLoader &shader) {
|
|||
number = std::to_string(diffuseNr++);
|
||||
else if (name == "texture_specular")
|
||||
number = std::to_string(specularNr++);
|
||||
else if (name == "texture_metalness")
|
||||
number = std::to_string(metalNr++);
|
||||
|
||||
shader.setFloat(("material." + name + number).c_str(), i);
|
||||
error.log(("material." + name + number).c_str() + std::string(" ") +
|
||||
std::to_string(i) + " " + std::to_string(textures[i].id));
|
||||
|
||||
shader.setInt(("material." + name + number).c_str(), i);
|
||||
glBindTexture(GL_TEXTURE_2D, textures[i].id);
|
||||
// error.log(std::to_string(i));
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ Model::Model(std::vector<Mesh> meshes) { this->meshes = meshes; }
|
|||
void Model::draw(ShaderLoader &shader) {
|
||||
for (unsigned int i = 0; i < this->meshes.size(); i++) {
|
||||
shader.setMat4("Model", this->model);
|
||||
shader.setVec3("WorldPos", this->position);
|
||||
this->meshes[i].draw(shader);
|
||||
}
|
||||
}
|
||||
|
|
@ -101,7 +100,15 @@ Mesh Model::processMesh(aiMesh *mesh, const aiScene *scene) {
|
|||
std::vector<Texture> specularMaps = loadMaterialTextures(
|
||||
material, aiTextureType_SPECULAR, "texture_specular");
|
||||
textures.insert(textures.end(), specularMaps.begin(), specularMaps.end());
|
||||
std::vector<Texture> metalMaps = loadMaterialTextures(
|
||||
material, aiTextureType_METALNESS, "texture_metalness");
|
||||
textures.insert(textures.end(), metalMaps.begin(), metalMaps.end());
|
||||
}
|
||||
error.log("Model");
|
||||
error.log(textures[0].path);
|
||||
error.log(std::to_string(textures[0].id));
|
||||
error.log(textures[1].path);
|
||||
error.log(std::to_string(textures[1].id));
|
||||
return Mesh(vertices, indecies, textures);
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +151,7 @@ unsigned int Model::loadTextureFromFile(std::string file,
|
|||
std::string directory) {
|
||||
// Use sdl2_image to load the texture.
|
||||
unsigned int texture;
|
||||
error.log(file);
|
||||
SDL_Surface *image = IMG_Load((directory + file).c_str());
|
||||
if (image == nullptr) {
|
||||
error.crash("SDL2_image was unable to load a texture", IMG_GetError());
|
||||
|
|
|
|||
28
src/main.cpp
28
src/main.cpp
|
|
@ -69,15 +69,17 @@ int main(int argc, char **argv) {
|
|||
ShaderLoader shader(ROOT_DIR "data/shaders/pbrVertex.glsl",
|
||||
ROOT_DIR "data/shaders/pbrFragment.glsl");
|
||||
|
||||
Model backpack(std::string(ROOT_DIR) +
|
||||
std::string("data/models/backpack/backpack.obj"));
|
||||
Model cube(ROOT_DIR "data/models/cube/cube.obj");
|
||||
Model gun(ROOT_DIR "data/models/gun/Cerberus_LP.FBX");
|
||||
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));
|
||||
gun.resize(glm::vec3(0.02f, 0.02f, 0.02f));
|
||||
gun.rotate(glm::radians(-90.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
// Model backpack(std::string(ROOT_DIR) +
|
||||
// std::string("data/models/backpack/backpack.obj"));
|
||||
// Model cube(ROOT_DIR "data/models/cube/cube.obj");
|
||||
// Model gun(ROOT_DIR "data/models/gun/Cerberus_LP.FBX");
|
||||
Model boxbarrel(ROOT_DIR
|
||||
"data/models/wooden_boxbarrel/wooden_box_and_barrel.obj");
|
||||
// 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));
|
||||
// gun.resize(glm::vec3(0.02f, 0.02f, 0.02f));
|
||||
// gun.rotate(glm::radians(-90.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// Create player camera object
|
||||
PlayerCamera camera;
|
||||
|
|
@ -121,10 +123,10 @@ int main(int argc, char **argv) {
|
|||
shader.setInt("tick", SDL_GetTicks());
|
||||
|
||||
// Draw Meshes
|
||||
cube.draw(shader);
|
||||
backpack.draw(shader);
|
||||
gun.draw(shader);
|
||||
|
||||
// cube.draw(shader);
|
||||
// backpack.draw(shader);
|
||||
// gun.draw(shader);
|
||||
boxbarrel.draw(shader);
|
||||
// Finally render everything
|
||||
shader.use();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue