Make normal maps optional

This commit is contained in:
SeanOMik 2022-09-30 17:01:14 -04:00
parent 9a3240b25f
commit 366ab19544
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
3 changed files with 13 additions and 10 deletions

View File

@ -172,7 +172,7 @@ int main(int argc, char *argv[]) {
// entity.add_component<se::ModelComponent>("examples/dev_testing/resources/viper/viper.obj"); // entity.add_component<se::ModelComponent>("examples/dev_testing/resources/viper/viper.obj");
// entity.add_component<se::ModelComponent>("examples/dev_testing/resources/halot/chief.fbx"); // entity.add_component<se::ModelComponent>("examples/dev_testing/resources/halot/chief.fbx");
//entity.add_component<se::ModelComponent>("examples/dev_testing/resources/planks/planks.fbx", simpleengine::gfx::ModelProcessingFlags::MdlProcFlag_CALCULATE_TANGENT_SPACE); // entity.add_component<se::ModelComponent>("examples/dev_testing/resources/planks/planks.fbx", simpleengine::gfx::ModelProcessingFlags::MdlProcFlag_CALCULATE_TANGENT_SPACE);
entity.add_component<se::ModelComponent>("examples/dev_testing/resources/bricks/bricks.fbx", simpleengine::gfx::ModelProcessingFlags::MdlProcFlag_CALCULATE_TANGENT_SPACE); entity.add_component<se::ModelComponent>("examples/dev_testing/resources/bricks/bricks.fbx", simpleengine::gfx::ModelProcessingFlags::MdlProcFlag_CALCULATE_TANGENT_SPACE);
// entity.add_component<se::ModelComponent>("examples/dev_testing/resources/scientist/scientist.fbx"); // entity.add_component<se::ModelComponent>("examples/dev_testing/resources/scientist/scientist.fbx");

View File

@ -24,6 +24,7 @@ struct Material {
sampler2D specular_map; sampler2D specular_map;
// TODO: Make Optional // TODO: Make Optional
bool has_normal_map;
sampler2D normal_map; sampler2D normal_map;
float ambient_strength; float ambient_strength;
@ -53,11 +54,14 @@ vec3 calculate_lighting() {
//float ambient_strength = 0.1; //float ambient_strength = 0.1;
vec3 ambient = u_material.ambient_strength * u_light_color; vec3 ambient = u_material.ambient_strength * u_light_color;
// Apply the normal map to the lighting. vec3 normal = vs_world_normal;
vec3 normal = vs_normal;
// Check if the normal map is set before trying to apply it.
if (u_material.has_normal_map) {
normal = texture(u_material.normal_map, vs_texcoord).rgb; normal = texture(u_material.normal_map, vs_texcoord).rgb;
normal = normal * 2.0 - 1.0; normal = normal * 2.0 - 1.0;
normal = normalize(vs_tbn * normal); normal = normalize(vs_tbn * normal);
}
// Diffuse // Diffuse
vec3 norm = normalize(normal); vec3 norm = normalize(normal);
@ -72,7 +76,7 @@ vec3 calculate_lighting() {
float spec = pow(max(dot(view_dir, reflect_dir), -0.f), 32 * u_material.shine_factor); float spec = pow(max(dot(view_dir, reflect_dir), -0.f), 32 * u_material.shine_factor);
vec3 specular = specular_strength * (spec * u_material.specular_strength) * u_light_color; vec3 specular = specular_strength * (spec * u_material.specular_strength) * u_light_color;
// Check if the specular map is set before trying to set it // Check if the specular map is set before trying to apply it.
if (u_material.has_specular_map) { if (u_material.has_specular_map) {
specular = specular * texture(u_material.specular_map, vs_texcoord).r; specular = specular * texture(u_material.specular_map, vs_texcoord).r;
} }

View File

@ -138,14 +138,13 @@ namespace simpleengine::gfx {
if (normal_maps != material->textures.end()) { if (normal_maps != material->textures.end()) {
auto normal = normal_maps->second.front(); auto normal = normal_maps->second.front();
//shader.set_uniform_int("u_material.has_normal_map", 1, false); shader.set_uniform_int("u_material.has_normal_map", 1, false);
shader.set_uniform_int("u_material.normal_map", 2, false); shader.set_uniform_int("u_material.normal_map", 2, false);
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
normal->bind(); normal->bind();
} else { } else {
//shader.set_uniform_int("u_material.has_normal_map", 0, false); shader.set_uniform_int("u_material.has_normal_map", 0, false);
std::cout << "No normal map for model!" << std::endl;
} }
} }