1
\$\begingroup\$

I've made a .obj reader in c++ and I've tried rendering some models. I've got the whole concept from here: https://www.youtube.com/watch?v=KMWUjNE0fYI&list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP&index=9

So I've tried to copy the export settings in blender what the guy used in the video (I'm not experienced in modelling so I had troubles because I have a newer version) and I've split every edge so they staied sharp even with the smooth shader. What my model looks like in blender: enter image description here

I'm not sure if this is a texture or lighting bug. The models that the guy provides in the video work just fine.

Edit:

My drawing code is this:

shader->Enable();
shader->SetUniformMat4f("vw_matrix", viewMatrix);
m_Model->GetVAO().Bind();
m_Model->GetIBO().Bind();
glActiveTexture(GL_TEXTURE0);
m_Texture->Bind();
glDrawElements(GL_TRIANGLES, m_Model->GetIBO().GetCount(), GL_UNSIGNED_INT, 0);
m_Texture->Unbind();
m_Model->GetVAO().Unbind();
m_Model->GetIBO().Unbind();
shader->Disable();

Export settings:

  • Write Normals
  • Include UVs
  • Triangulate faces
  • Objects as OBJ objects

Edit2:

I've added a pic how the model looks without edge split (above).

My vertex shader:

#version 400 core

in vec3 position;
in vec2 textureCoords;
in vec3 normal;

out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out vec3 toLightVector;

uniform mat4 pr_matrix = mat4(1.0);
uniform mat4 vw_matrix = mat4(1.0);
uniform mat4 ml_matrix = mat4(1.0);
uniform vec3 lightPosition;

void main(void)
{
    vec4 worldPosition = ml_matrix * vec4(position, 1.0);
    gl_Position = pr_matrix * vw_matrix * worldPosition;
    pass_textureCoords = textureCoords;

    surfaceNormal = (ml_matrix * vec4(normal, 0.0)).xyz;
    toLightVector = lightPosition - worldPosition.xyz;
}
\$\endgroup\$
  • \$\begingroup\$ So, correct me if I'm wrong, the models that the guy in the video uses render fine with your code, but none of your own models do? \$\endgroup\$ – Superdoggy Aug 20 '15 at 21:37
  • \$\begingroup\$ @Superdoggy Yes, exactly. \$\endgroup\$ – Peter Lenkefi Aug 20 '15 at 21:38
  • \$\begingroup\$ Okay, in blender, try selecting everything, going to the toolbar (if it's not open, press "T") and going to Shading/UVs and press "Recalculate". Can you tell me if that works? \$\endgroup\$ – Superdoggy Aug 20 '15 at 21:40
  • \$\begingroup\$ Right, give me a minute please. \$\endgroup\$ – Peter Lenkefi Aug 20 '15 at 21:41
  • 1
    \$\begingroup\$ Okay. Just wondering. It almost looks as if some of your normals are flipped, so I was curious to see if that was the problem. Could you possibly include your drawing code and your Blender export settings into your question? It will be easier to help you if we don't have to guess. :P \$\endgroup\$ – Superdoggy Aug 20 '15 at 21:51
1
\$\begingroup\$
  1. Go to edit mode
  2. Select all vertices (a)
  3. Press Ctrl + n (this recalculates all normals for all faces)

export again and see if it behaves the way you want it

If that did not work, do

  1. Go to edit mode
  2. Select all vertices (b, blender keeps a tab of the hotkeys you use and increment them by 1 for every use)
  3. Press w, select "remove doubles" (or duplicates, something to that effect)
\$\endgroup\$
0
\$\begingroup\$

I believe your triangles are not all clockwise (or ccw) this is the cause of the lighting rendering them differently.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.