Make normal maps optional
This commit is contained in:
parent
9a3240b25f
commit
366ab19544
|
@ -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/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/scientist/scientist.fbx");
|
||||
|
|
|
@ -24,6 +24,7 @@ struct Material {
|
|||
sampler2D specular_map;
|
||||
|
||||
// TODO: Make Optional
|
||||
bool has_normal_map;
|
||||
sampler2D normal_map;
|
||||
|
||||
float ambient_strength;
|
||||
|
@ -53,11 +54,14 @@ vec3 calculate_lighting() {
|
|||
//float ambient_strength = 0.1;
|
||||
vec3 ambient = u_material.ambient_strength * u_light_color;
|
||||
|
||||
// Apply the normal map to the lighting.
|
||||
vec3 normal = vs_normal;
|
||||
vec3 normal = vs_world_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 = normal * 2.0 - 1.0;
|
||||
normal = normalize(vs_tbn * normal);
|
||||
}
|
||||
|
||||
// Diffuse
|
||||
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);
|
||||
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) {
|
||||
specular = specular * texture(u_material.specular_map, vs_texcoord).r;
|
||||
}
|
||||
|
|
|
@ -138,14 +138,13 @@ namespace simpleengine::gfx {
|
|||
if (normal_maps != material->textures.end()) {
|
||||
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);
|
||||
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
normal->bind();
|
||||
} else {
|
||||
//shader.set_uniform_int("u_material.has_normal_map", 0, false);
|
||||
std::cout << "No normal map for model!" << std::endl;
|
||||
shader.set_uniform_int("u_material.has_normal_map", 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue