PBR is now implemented
This commit is contained in:
parent
4ee8d24f18
commit
2cd954dc9a
6 changed files with 31 additions and 40 deletions
Binary file not shown.
|
After Width: | Height: | Size: 2.3 MiB |
Binary file not shown.
|
|
@ -14,5 +14,7 @@ map_Bump 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
|
||||
map_Ps wooden box and barrel/boxes_DefaultMaterial_AO.jpg
|
||||
map_RMA wooden box and barrel/boxes_DefaultMaterial_ORM.jpg
|
||||
# map_Ps wooden box and barrel/boxes_DefaultMaterial_AO.jpg
|
||||
map_Ps wooden box and barrel/boxes_DefaultMaterial_RMA.jpg
|
||||
map_RMA wooden box and barrel/boxes_DefaultMaterial_RMA.jpg
|
||||
map_ORM wooden box and barrel/boxes_DefaultMaterial_ORM.jpg
|
||||
|
|
|
|||
|
|
@ -20,19 +20,13 @@ uniform int tick;
|
|||
|
||||
//float metallic = 0.3f;
|
||||
//float roughness = 0.3f;
|
||||
float ao = 0.8f;
|
||||
//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_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;
|
||||
uniform sampler2D texture_rma1;
|
||||
|
||||
|
||||
// PBR functions from learnOpenGL.com
|
||||
const float PI = 3.14159265359;
|
||||
|
|
@ -41,6 +35,7 @@ vec3 fresnelSchlick(float cosTheta, vec3 F0)
|
|||
{
|
||||
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
||||
}
|
||||
|
||||
float DistributionGGX(vec3 N, vec3 H, float roughness)
|
||||
{
|
||||
float a = roughness*roughness;
|
||||
|
|
@ -77,16 +72,21 @@ float GeometrySmith(vec3 N, vec3 V, vec3 L, float roughness)
|
|||
|
||||
void main()
|
||||
{
|
||||
vec3 albedo = vec3(texture(texture_diffuse1, ourTexCoord));
|
||||
float metallic = 1 - texture(texture_metalness1, ourTexCoord).r;
|
||||
float roughness = 1 - texture(texture_roughness1, ourTexCoord).r;
|
||||
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;
|
||||
|
||||
// Establish a temporary hard coded light position
|
||||
vec3 lightPosition = vec3( (sin(tick / 600.0)*2), 1 + sin(tick / 600.0)*2, 2.0);
|
||||
vec3 lightPosition = vec3( (sin(tick / 1000.0)*2), 1 + sin(tick / 600.0)*2, 2.0);
|
||||
//vec3 lightColor = vec3(1.0, 1.0, 1.0) - sin(tick / 90);
|
||||
vec3 lightColor = vec3(1.0, 1.0, 1.0);
|
||||
vec3 lightColor = vec3(23.47, 21.31, 20.79);
|
||||
|
||||
// Normal light maths
|
||||
vec3 N = normalize(ourNormCoord);
|
||||
|
|
|
|||
15
src/Mesh.cpp
15
src/Mesh.cpp
|
|
@ -41,10 +41,7 @@ void Mesh::setupMesh() {
|
|||
|
||||
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;
|
||||
unsigned int rmaNr = 1;
|
||||
for (unsigned int i = 0; i < textures.size(); i++) {
|
||||
// activate proper texture unit before binding
|
||||
glActiveTexture(GL_TEXTURE0 + i);
|
||||
|
|
@ -53,14 +50,8 @@ void Mesh::draw(ShaderLoader &shader) {
|
|||
std::string name = textures[i].type;
|
||||
if (name == "texture_diffuse")
|
||||
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++);
|
||||
else if (name == "texture_roughness")
|
||||
number = std::to_string(roughNr++);
|
||||
else if (name == "texture_sheen")
|
||||
number = std::to_string(sheenNr++);
|
||||
else if (name == "texture_rma")
|
||||
number = std::to_string(rmaNr++);
|
||||
|
||||
shader.setInt((name + number).c_str(), i);
|
||||
glBindTexture(GL_TEXTURE_2D, textures[i].id);
|
||||
|
|
|
|||
|
|
@ -97,18 +97,16 @@ 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> 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());
|
||||
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());
|
||||
|
||||
// WARNING: As assimp updates to keep up with obj's mtl format
|
||||
// aiTextureType_sheen may become incorrect. Using sheen because assimp maps
|
||||
// map_Ps to both RMA and sheen, and doesn't seem to use mtl's map_RMA
|
||||
// anywhere and I can't find an RMA texture type in this version of the
|
||||
// library.
|
||||
// https://github.com/assimp/assimp/commit/19371af6e65608ffc968df646bf20278e6d99414
|
||||
std::vector<Texture> rmaMaps =
|
||||
loadMaterialTextures(material, aiTextureType_SHEEN, "texture_rma");
|
||||
textures.insert(textures.end(), rmaMaps.begin(), rmaMaps.end());
|
||||
}
|
||||
return Mesh(vertices, indecies, textures);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue