Added method to load normal maps and moved pbr to it's own function
This commit is contained in:
parent
2cd954dc9a
commit
cd382435a8
3 changed files with 22 additions and 13 deletions
|
|
@ -26,7 +26,7 @@ uniform int tick;
|
|||
uniform sampler2D texture_diffuse1;
|
||||
uniform sampler2D texture_diffuse2;
|
||||
uniform sampler2D texture_rma1;
|
||||
|
||||
uniform sampler2D texture_normal1;
|
||||
|
||||
// PBR functions from learnOpenGL.com
|
||||
const float PI = 3.14159265359;
|
||||
|
|
@ -70,16 +70,8 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
|||
return ggx1 * ggx2;
|
||||
}
|
||||
|
||||
void main()
|
||||
vec3 PBR(vec3 albedo, float roughness, float metallic, float ao)
|
||||
{
|
||||
vec3 albedo;
|
||||
albedo.r = pow(texture(texture_diffuse1, ourTexCoord).r, 2.2);
|
||||
albedo.g = pow(texture(texture_diffuse1, ourTexCoord).g, 2.2);
|
||||
albedo.b = pow(texture(texture_diffuse1, ourTexCoord).b, 2.2);
|
||||
float roughness = texture(texture_rma1, ourTexCoord).r;
|
||||
float metallic = texture(texture_rma1, ourTexCoord).g;
|
||||
float ao = texture(texture_rma1, ourTexCoord).b;
|
||||
|
||||
// Establish ambient lighting
|
||||
float ambientStrength = 0.1;
|
||||
|
||||
|
|
@ -125,7 +117,18 @@ void main()
|
|||
vec3 color = ambient + Lo;
|
||||
|
||||
color = color / (color + vec3(1.0));
|
||||
color = pow(color, vec3(1.0/2.2));
|
||||
|
||||
FragColor = vec4(color, 0.0);
|
||||
return pow(color, vec3(1.0/2.2));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 albedo;
|
||||
albedo.r = pow(texture(texture_diffuse1, ourTexCoord).r, 2.2);
|
||||
albedo.g = pow(texture(texture_diffuse1, ourTexCoord).g, 2.2);
|
||||
albedo.b = pow(texture(texture_diffuse1, ourTexCoord).b, 2.2);
|
||||
float roughness = texture(texture_rma1, ourTexCoord).r;
|
||||
float metallic = texture(texture_rma1, ourTexCoord).g;
|
||||
float ao = texture(texture_rma1, ourTexCoord).b;
|
||||
|
||||
FragColor = vec4(PBR(albedo, roughness, metallic, ao), 0.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ void Mesh::setupMesh() {
|
|||
void Mesh::draw(ShaderLoader &shader) {
|
||||
unsigned int diffuseNr = 1;
|
||||
unsigned int rmaNr = 1;
|
||||
unsigned int normalNr = 1;
|
||||
for (unsigned int i = 0; i < textures.size(); i++) {
|
||||
// activate proper texture unit before binding
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
|
|
@ -52,6 +53,8 @@ void Mesh::draw(ShaderLoader &shader) {
|
|||
number = std::to_string(diffuseNr++);
|
||||
else if (name == "texture_rma")
|
||||
number = std::to_string(rmaNr++);
|
||||
else if (name == "texture_normal")
|
||||
number = std::to_string(normalNr++);
|
||||
|
||||
shader.setInt((name + number).c_str(), i);
|
||||
glBindTexture(GL_TEXTURE_2D, textures[i].id);
|
||||
|
|
|
|||
|
|
@ -97,6 +97,9 @@ Mesh Model::processMesh(aiMesh *mesh, const aiScene *scene) {
|
|||
std::vector<Texture> diffuseMaps = loadMaterialTextures(
|
||||
material, aiTextureType_DIFFUSE, "texture_diffuse");
|
||||
textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end());
|
||||
std::vector<Texture> normalMaps =
|
||||
loadMaterialTextures(material, aiTextureType_NORMALS, "texture_normal");
|
||||
textures.insert(textures.end(), normalMaps.begin(), normalMaps.end());
|
||||
|
||||
// WARNING: As assimp updates to keep up with obj's mtl format
|
||||
// aiTextureType_sheen may become incorrect. Using sheen because assimp maps
|
||||
|
|
|
|||
Loading…
Reference in a new issue