0
\$\begingroup\$

I'm going through a problem and I don't have a reasonable explanation for why this occurs. Basically, I have 3D scene in which there is a light source and simple plane and cube (i.e. .obj models) modeled and exported from Blender. The result with the cube is as follows:

enter image description here

The light source is located at (0,2,0) represented as a while cube and the result of the reflected light on the cube is expected. However when I import the plane model, the result is as follows:

enter image description here

The bottom of the plane should be dark if we are looking from the below of the plane but this is not the case. What things can cause this kind of behavior? Note: the code is identical for both cases. I use OpenGL and Shaders 3.3 in Windows 10. The API is GLFW.

The plane model is

# Blender v2.78 (sub 0) OBJ File: ''
# www.blender.org
mtllib plane.mtl
o Plane
v -1.000000 0.000000 1.000000
v 1.000000 0.000000 1.000000
v -1.000000 0.000000 -1.000000
v 1.000000 0.000000 -1.000000
vn 0.0000 1.0000 0.0000
usemtl None
s off
f 1//1 2//1 4//1 3//1

whereas the cube model is

# Blender v2.78 (sub 0) OBJ File: ''
# www.blender.org
mtllib cube.mtl
o Cube
v 0.500000 -0.500000 -0.500000
v 0.500000 -0.500000 0.500000
v -0.500000 -0.500000 0.500000
v -0.500000 -0.500000 -0.500000
v 0.500000 0.500000 -0.499999
v 0.499999 0.500000 0.500000
v -0.500000 0.500000 0.500000
v -0.500000 0.500000 -0.500000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 1//1 2//1 3//1 4//1
f 5//2 8//2 7//2 6//2
f 1//3 5//3 6//3 2//3
f 2//4 6//4 7//4 3//4
f 3//5 7//5 8//5 4//5
f 5//6 1//6 4//6 8//6

I use assimp library to import models in my application. The fragment shader is

#version 330 core
out vec4 FragColor;

uniform vec3 objectColor;
uniform vec3 lightColor;
uniform vec3 lightPos;

in vec3 Normal;
in vec3 FragPos;

void main()
{
    float ambientStrength = 0.1;
    vec3 ambient = ambientStrength * lightColor;


    vec3 norm = normalize(Normal);
    vec3 lightDir = normalize(lightPos - FragPos);
    float diff = max(dot(norm,lightDir), 0.0);
    vec3 diffuse = diff * lightColor;


    vec3 result = (ambient + diffuse) * objectColor;
    FragColor = vec4(result, 1.0);
}
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Just to confirm: the plane is uniformly dark on both sides? If so, that would suggest one of four things: 1) you're rendering the same face twice without flipping the normals when viewing it as a back face, 2) You have two faces that both use the same upward-pointing normals, 3) Your ambient term is too high, 4) you're using an unlit material. We'll need to see more information about your plane, scene lighting, and material/shader to know which situation you're in and how to fix it. \$\endgroup\$
    – DMGregory
    Commented Aug 9, 2017 at 16:54
  • \$\begingroup\$ @DMGregory, the plane is not dark on both sides. The normal vector is (0,1,0) vn 0.0000 1.0000 0.0000. The ambient strength is 0.1. I will add more info. \$\endgroup\$
    – CroCo
    Commented Aug 9, 2017 at 16:56
  • \$\begingroup\$ @DMGregory, please see the update. \$\endgroup\$
    – CroCo
    Commented Aug 9, 2017 at 17:12

0

You must log in to answer this question.

Browse other questions tagged .