Inverted (Negated) Normals

Started by bogieman987, January 19, 2015, 01:32:32

Previous topic - Next topic

bogieman987

Can anyone tell me if the following data for a cube, has the normals pointing outwards.

The format is .obj
# Blender v2.72 (sub 0) OBJ File: ''
# www.blender.org
mtllib Cube2.mtl
o Cube.001
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
vt 0.250043 0.500000
vt 0.500000 0.500000
vt 0.250043 0.749957
vt 0.250043 0.250043
vt 0.250043 0.000087
vt 0.500000 0.250043
vt 0.500000 0.749957
vt 0.500000 0.999913
vt 0.250044 0.999913
vt 0.749957 0.250043
vt 0.000087 0.250043
vt 0.500000 0.000087
vt 0.749957 0.500000
vt 0.000087 0.500000
vn 0.000000 -0.000000 1.000000
vn 0.000000 0.000000 -1.000000
vn 0.000000 -1.000000 -0.000000
vn 0.000000 1.000000 0.000000
vn -1.000000 -0.000000 -0.000000
vn 1.000000 0.000000 0.000000
usemtl Material.001
s off
f 1/1/1 3/2/1 2/3/1
f 4/4/2 6/5/2 5/6/2
f 7/7/3 8/8/3 6/9/3
f 1/1/4 4/4/4 5/6/4
f 2/3/3 7/7/3 6/9/3
f 5/6/5 8/10/5 3/2/5
f 6/11/6 4/4/6 1/1/6
f 5/6/4 3/2/4 1/1/4
f 3/2/1 7/7/1 2/3/1
f 6/5/2 8/12/2 5/6/2
f 8/10/5 7/13/5 3/2/5
f 1/1/6 2/14/6 6/11/6

Reason I'm asking is that I'm trying to figure out the root of an issue where it seems the normals are inverted, whether it's due to how I'm loading it, or if the exporter for Blender is messed up I don't know. But if this works fine for others without any modification upon loading then I'll assume it's potentially an issue with how I'm parsing the data.

To see the normals I visualized them by using a geometry shader and making new lines pretty much like this: input position + normal vector * length.

Also, would it also show that the normals are inverted if when I try and do some diffuse shading the models stay completely black, regardless of light source location.

Will soon be an Oracle Certified Associate :D

quew8

From looking at the data, I can tell you that the normals are inverted. In Blender you can right click whilst in edit mode with the whole mesh selected and there is a button (somewhere) to "Recalculate Normals" and in the options of that function there is a tick box with "inside" or "outside". You want "outside". Actually it might be two different buttons. Either way...

However, inverted normals (btw I think "negated" would be a better description) wouldn't make diffuse lighting black all over. The face that points away from the light would be lit as if it were the face on the opposite side which points towards the light (ignoring a slight difference in attenuation).

Also protip, if you want to "see" simple normals for testing you don't need to mess around with geometry shaders. Instead you can, in the fragment shader, set the frag colour to the frag's normal. Ie
gl_FragColor = vec4(fragNormal.xyz, 1);

abcdef

Your winding order could be the issue

void glCullFaceââ,¬â€¹(GLenum modeââ,¬â€¹);


which takes either

GL_CCW (Default)
GL_CW


Maybe try switching to GL_CW to see if it helps (if it does then it was making the internal faces visible rather than the external before switching)

bogieman987

There was an issue with the winding order, though, with the new cube, there isn't. So at least that's not a major concern.

Anyways, here's a new cube, one with the normals outside, and the other with them inside.
Could you see if they produce different results or not, as for me, the normals seem to be negated on both, oddly enough.

And as a last ditch effort, how would I go about positifying (Is that even a word?) the normals?

Oh and thanks for the pro-tip, I've stuc pretty much with modern OpenGL & GLSL as much as I can, so I didn't know that :)

Outside:
# Blender v2.72 (sub 0) OBJ File: ''
# www.blender.org
o Cube_Cube.001
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
vt 0.500000 0.749957
vt 0.500000 0.500000
vt 0.749957 0.500000
vt 0.250043 0.749957
vt 0.250043 0.500000
vt 0.000087 0.749957
vt 0.000087 0.500000
vt 0.500000 0.000087
vt 0.500000 0.250043
vt 0.250043 0.250043
vt 0.500000 0.999913
vt 0.749957 0.749957
vt 0.250043 0.000087
vt 0.250043 0.999913
vn -0.577300 0.577300 -0.577300
vn -0.577300 -0.577300 -0.577300
vn -0.577300 -0.577300 0.577300
vn 0.577300 0.577300 -0.577300
vn 0.577300 -0.577300 -0.577300
vn 0.577300 0.577300 0.577300
vn 0.577300 -0.577300 0.577300
vn -0.577300 0.577300 0.577300
s 1
f 6/1/1 2/2/2 1/3/3
f 7/4/4 3/5/5 2/2/2
f 8/6/6 4/7/7 3/5/5
f 5/8/8 1/9/3 4/10/7
f 2/2/2 3/5/5 4/10/7
f 7/4/4 6/1/1 5/11/8
f 5/12/8 6/1/1 1/3/3
f 6/1/1 7/4/4 2/2/2
f 7/4/4 8/6/6 3/5/5
f 8/13/6 5/8/8 4/10/7
f 1/9/3 2/2/2 4/10/7
f 8/14/6 7/4/4 5/11/8


Inside:
# Blender v2.72 (sub 0) OBJ File: ''
# www.blender.org
o Cube_Cube.001
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
vt 0.500000 0.749957
vt 0.749957 0.500000
vt 0.500000 0.500000
vt 0.250043 0.749957
vt 0.250043 0.500000
vt 0.000087 0.749957
vt 0.000087 0.500000
vt 0.500000 0.000087
vt 0.250043 0.250043
vt 0.500000 0.250043
vt 0.500000 0.999913
vt 0.749957 0.749957
vt 0.250043 0.000087
vt 0.250043 0.999913
vn 0.577300 -0.577300 0.577300
vn 0.577300 0.577300 -0.577300
vn 0.577300 0.577300 0.577300
vn -0.577300 -0.577300 0.577300
vn -0.577300 0.577300 0.577300
vn -0.577300 -0.577300 -0.577300
vn -0.577300 0.577300 -0.577300
vn 0.577300 -0.577300 -0.577300
s 1
f 6/1/1 1/2/2 2/3/3
f 7/4/4 2/3/3 3/5/5
f 8/6/6 3/5/5 4/7/7
f 5/8/8 4/9/7 1/10/2
f 2/3/3 4/9/7 3/5/5
f 7/4/4 5/11/8 6/1/1
f 5/12/8 1/2/2 6/1/1
f 6/1/1 2/3/3 7/4/4
f 7/4/4 3/5/5 8/6/6
f 8/13/6 4/9/7 5/8/8
f 1/10/2 4/9/7 2/3/3
f 8/14/6 5/11/8 7/4/4
Will soon be an Oracle Certified Associate :D

quew8

So the problem now is that you have got per vertex normals rather than per face.

A quick Google tells me that to solve this you want to tell Blender to use flat shading instead of smooth shading (coincidently that is what the "s 1" line means). In edit mode, select the mesh, and go "Mesh->Faces->Shade Flat" then try exporting again. With outside normals.

bogieman987

So there's no issues with the outside box, besides the flat/smooth shading thing?

Because for me it still comes out black when I try to visualize the normals on it.
I've double checked the shaders, they do work as I've tried and successfully visualized the UV co-ordinates.

I'm going to go over the code that imports the damn thing, I've a feeling that the issue may be there
Will soon be an Oracle Certified Associate :D

quew8

Those normals should give you something. Not just black. None of these normals should have been giving you black when you try to visualize them.

bogieman987

Ah right, if that's the case, then it more than likely is to do with how I'm parsing the data and/or setting up the vertices.
Will soon be an Oracle Certified Associate :D