Added roughness

This commit is contained in:
Warwick 2022-07-25 10:56:58 +01:00
parent 58eb18354c
commit 4ee8d24f18
8 changed files with 24 additions and 15 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 980 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 952 KiB

View file

@ -12,5 +12,7 @@ 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_Pr wooden box and barrel/boxes_DefaultMaterial_Roughness.jpg
map_Pm wooden box and barrel/boxes_DefaultMaterial_Metallic.jpg
map_Ps wooden box and barrel/boxes_DefaultMaterial_AO.jpg
map_RMA wooden box and barrel/boxes_DefaultMaterial_ORM.jpg

View file

@ -12,14 +12,14 @@ uniform int tick;
//vec3 WorldPos = vec3(0.0f, 0.0f, 0.0f);
//vec3 CameraPos = vec3(0.0f, 0.0f, -1.0f);
//TODO: make these values rely on associated textures.
vec3 albedo = vec3(0.8f, 0.8f, 0.8f);
//vec3 albedo = vec3(0.8f, 0.8f, 0.8f);
//float metallic = sin(tick / 60 * 0.3f);
//float roughness = sin(tick / 60 * 0.3f);
//float ao = sin(tick / 60 * 0.8f);
//float metallic = 0.3f;
float roughness = 0.3f;
//float roughness = 0.3f;
float ao = 0.8f;
// Handle multiple textures from the Mesh Object (Might not even be used)
@ -29,6 +29,10 @@ uniform sampler2D texture_specular1;
uniform sampler2D texture_specular2;
uniform sampler2D texture_metalness1;
uniform sampler2D texture_metalness2;
uniform sampler2D texture_roughness1;
uniform sampler2D texture_roughness2;
uniform sampler2D texture_sheen1;
uniform sampler2D texture_sheen2;
// PBR functions from learnOpenGL.com
const float PI = 3.14159265359;
@ -73,9 +77,9 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
void main()
{
//albedo = vec3(texture(texture_diffuse1, ourTexCoord));
// float metallic = 1 - texture(texture_metalness1, ourTexCoord).r;
vec3 albedo = vec3(texture(texture_diffuse1, ourTexCoord));
float metallic = 1 - texture(texture_metalness1, ourTexCoord).r;
float roughness = 1 - texture(texture_roughness1, ourTexCoord).r;
// Establish ambient lighting
float ambientStrength = 0.1;
@ -123,5 +127,5 @@ void main()
color = color / (color + vec3(1.0));
color = pow(color, vec3(1.0/2.2));
FragColor = texture(texture_diffuse1, ourTexCoord) * vec4(color, 0.0);
FragColor = vec4(color, 0.0);
}

View file

@ -43,6 +43,8 @@ void Mesh::draw(ShaderLoader &shader) {
unsigned int diffuseNr = 1;
unsigned int specularNr = 1;
unsigned int metalNr = 1;
unsigned int roughNr = 1;
unsigned int sheenNr = 1;
for (unsigned int i = 0; i < textures.size(); i++) {
// activate proper texture unit before binding
glActiveTexture(GL_TEXTURE0 + i);
@ -55,9 +57,10 @@ void Mesh::draw(ShaderLoader &shader) {
number = std::to_string(specularNr++);
else if (name == "texture_metalness")
number = std::to_string(metalNr++);
error.log(("material." + name + number).c_str() + std::string(" ") +
std::to_string(i) + " " + std::to_string(textures[i].id));
else if (name == "texture_roughness")
number = std::to_string(roughNr++);
else if (name == "texture_sheen")
number = std::to_string(sheenNr++);
shader.setInt((name + number).c_str(), i);
glBindTexture(GL_TEXTURE_2D, textures[i].id);

View file

@ -103,12 +103,13 @@ Mesh Model::processMesh(aiMesh *mesh, const aiScene *scene) {
std::vector<Texture> metalMaps = loadMaterialTextures(
material, aiTextureType_METALNESS, "texture_metalness");
textures.insert(textures.end(), metalMaps.begin(), metalMaps.end());
std::vector<Texture> roughMaps = loadMaterialTextures(
material, aiTextureType_DIFFUSE_ROUGHNESS, "texture_roughness");
textures.insert(textures.end(), roughMaps.begin(), roughMaps.end());
std::vector<Texture> sheenMaps = loadMaterialTextures(
material, aiTextureType_AMBIENT_OCCLUSION, "texture_sheen");
textures.insert(textures.end(), sheenMaps.begin(), sheenMaps.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);
}
@ -151,7 +152,6 @@ 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());