Jump to content
  • Advertisement
Sign in to follow this  

OpenGL My Bspline Surface Illumination is strange

This topic is 925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys, this is my first topic in GameDev.

I'm studying computer science and I like computer graphics very much.


My program: A Bspline Surface being illuminated by OpenGL 4.0 and GLSL. I implemented a fragment and vertex shader, my own Ambient+Diffuse+Specular light setup. Also, I have a little colored cube used as a Point Light.


The problem: I don't know if my normal vectors are correct (maybe something else is wrong, Im clueless), because my illumination feels wrong. To explain, I'm gonna use some images. 


Ok, lets begin.

Image 1 - My mesh model with zero rotations. Y axis is used to represent the surface height.

[spoiler][attachment=32142:Image 1 - Modeled Mesh.png][/spoiler]


Image 2 - From here, my mesh is rotated by 90 degrees in X axis. I'm using one normal (0, 0, 1) for every triangle. Light seems ok.

[spoiler][attachment=32143:Image 2 - One Normal.png][/spoiler]


Image 3 - Just in case, you can see the mesh's triangles here.

[spoiler][attachment=32144:Image 3 - Triangles.png][/spoiler]


Image 4 - Strange stuff starts here. I don't know if that edge is being illuminated correctly.

[spoiler][attachment=32148:Image 4 - One Normal.png][/spoiler]


Image 5 - Now, I'm calculating a normal for every triangle. To do so, I created planes with every triangle to find normals by using vectorial product.

[spoiler][attachment=32149:Image 5 - Multiple Normals.png][/spoiler]


Image 6 - Zooming in, you can see that my illumination is not smooth (like in Image 2).

[spoiler][attachment=32151:Image 6 - Multiple Normals.png][/spoiler]


Share this post

Link to post
Share on other sites

If recomputed normals do not have the issue, you have simply wrong normals on the mesh. You computed flat normals, you need to have smooth normals to have gradienting light like in picture 2. This is done by averaging all flat (triangle) normals that are on triangles that vertex is a part of.

Share this post

Link to post
Share on other sites
I don't know how your shader does work but if every normal are pointing to the same direction then the edge illumination looks wrong when lit by a point light.
The light amount depends on normal and depth. Since normal is constant and depth doesn't vary by a wide margin you should get a similar halo as when your light is in the middle of the surface, and not this penumbra.
Another argument is that since depth is continuous and diffuse is too, you should get continuous illumination but here there's a visible boundary.

Share this post

Link to post
Share on other sites


Yeah, using one normal for this mesh is so wrong.


Guys, I tried what @JohnnyCode said, averaging normals for every vertex. My illumination is very smooth now.

[spoiler][attachment=32161:Averaged Normals.png][/spoiler]


We can see now that the edge is working better.



To average my normals, I had to check how I was drawing my triangles. I found out that I was using GL_TRIANGLES.



That said, I had a problem to solve: Almost every vertex had shared triangles. In this picture, the orange vertex has only 1 triangle associated, the blue ones have 3 and the red ones have 6. 



The drawing style GL_TRIANGLES made me use 6 vertexes for the same position (red cases)! 

To find the average normal, I looped through the entire mesh to find vertexes with the same position, for each vertex!

I suppose this is a zero optimized algorithm, but it worked out.

Edited by estevan95

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!