Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Y normals (for directional lighting) seems backwards? #75

Closed
trusktr opened this issue May 29, 2017 · 4 comments
Closed

My Y normals (for directional lighting) seems backwards? #75

trusktr opened this issue May 29, 2017 · 4 comments

Comments

@trusktr
Copy link
Contributor

trusktr commented May 29, 2017

When making directional lighting, I found that for normals of a face that faces upwards (which is in the positive Y direction right?) that my normal is 0, -1, 0, which seems to be backwards? I thought it would be +1 on the Y axis, since positive is up. For example, here's the normals for each side of my cube, (the cube sides are perpendicular to the XYZ axes), and it seems that "top" and "bottoms" face normals are backwards:

        const normals = [
            [0,0,1, ], // front face
            [-1,0,0, ], // left face
            [1,0,0,], // right face
            [0,0,-1,], // back face
            [0,-1,0, ], // top face
            [0,1,0,], // bottom face
        ]

Here's the full code.

Here's how the cubes are created, the sides are just perpenducular/parallel to axes.

As you can see, the top face is created 5th, and the top-face normal is also fifth in the above normals array, then the normals are mapped to the vertices.

I thought that the top face, which faces upwards, would have vertex normals of 0,1,0, and the bottom face would have vertex normals of 0,-1,0.

Why might it be opposite?

@trusktr
Copy link
Contributor Author

trusktr commented May 29, 2017

The full working example can be seen here: https://trusktr.io (for now).

@trusktr
Copy link
Contributor Author

trusktr commented May 29, 2017

@greggman oh oh!! Is it because the ordering of my vertices is clockwise (so the right hand rule would make the normal point downward)?

Does the normal direction become opposite if we reverse the ordering of the vertices?

@trusktr
Copy link
Contributor Author

trusktr commented May 29, 2017

Ah, yep, I forgot that in the webgl-3d-orthographic lesson the order of the vertices determines front/back of the triangle, which determines direction of the normal.

@trusktr trusktr closed this as completed May 29, 2017
@greggman
Copy link
Member

greggman commented May 29, 2017

No, the normal doesn't flip based on the clockwise or counterclockwise unless you are computing the normal. You're not computing the normal you're supplying it precomputed. As for your question you should ask this on Stack Overflow and if you want debugging help you should make a minimal example.

Here's a simple cube
https://jsfiddle.net/greggman/ksu95xjj/

The top face's normal is [0, 1, 0]. The bottom is [0, -1, 0] as you'd expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants