Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Opengl bad lighting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 09 June 2013 - 09:26 AM

I'm getting bad lighting and was woundering if anyone can tell me why.

 

I use a shader, and import/render models in obj format(normal,verts). I don't know what GL_SMOOTH vs. GL_FLAT does, because I used both and neither have any effect. I'm 90% sure my .obj model exported from blender gives me per-vertex normal and not per-face normal, so I don't think that's the problem. Why doesn't my opengl look like my blender render(with GL_SMOOTH on)?

 

Opengl program:

 

j9sruq.jpg

 

Blender render (with GL_SMOOTH on):

16ifuxz.jpg



Sponsor:

#2 polyfrag   Crossbones+   -  Reputation: 1874

Like
0Likes
Like

Posted 09 June 2013 - 01:35 PM

Specular highlights (shininess)? Different shadowing opacity?

[edit] And you're not interpolating the normals of shared vertices.

#3 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 09 June 2013 - 05:03 PM

Specular highlights (shininess)? Different shadowing opacity?

[edit] And you're not interpolating the normals of shared vertices.

 

Sorry, i'm only dealing with the specular component right now, even though blender produces all 3 components. There are no shadows.

 

How would I go about interpolating the normals of shared vertices?



#4 polyfrag   Crossbones+   -  Reputation: 1874

Like
0Likes
Like

Posted 09 June 2013 - 05:24 PM

If they're at various distances from each other you'd need Gouraud shading/interpolation. Haven't tried it.

http://www.gamedev.net/blog/906/entry-2256401-lightmapping-curved-csg-surfaces/

But you can get away with making a list of all the face normals shared by a vertex and then get the average. Don't forget to renormalize.

#5 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 09 June 2013 - 06:34 PM

I'm using a shader which I believe does per-pixel shading(Gourand) on its own.

 

The way I'm rendering vertex and normal in an .obj model is like this, which associates 1 normal with all 3 vertices, does that look like the problem?

for all faces in model{
    
glBegin(GL_TRIANGLES);
glColor4f(colors[faces[i]->colorNum-1]->r,colors[faces[i]->colorNum-1]->g,colors[faces[i]->colorNum-1]->b,1.0);
glNormal3f(normals[faces[i]->facenum-1]->x,normals[faces[i]->facenum-1]->x,normals[faces[i]->facenum-1]->z);
glVertex3f(vertex[faces[i]->faces[0]-1]->x,vertex[faces[i]->faces[0]-1]->y,vertex[faces[i]->faces[0]-1]->z);
glVertex3f(vertex[faces[i]->faces[1]-1]->x,vertex[faces[i]->faces[1]-1]->y,vertex[faces[i]->faces[1]-1]->z);
glVertex3f(vertex[faces[i]->faces[2]-1]->x,vertex[faces[i]->faces[2]-1]->y,vertex[faces[i]->faces[2]-1]->z);
glEnd();
}


#6 polyfrag   Crossbones+   -  Reputation: 1874

Like
1Likes
Like

Posted 09 June 2013 - 07:15 PM

It doesn't matter if the shader does per-pixel shading if the normals are per-face. You'll need to blend them yourself. If you have attenuation or something though that will show up in per-pixel.

#7 marcClintDion   Members   -  Reputation: 431

Like
2Likes
Like

Posted 10 June 2013 - 03:51 AM

GL_SMOOTH and GL_FLAT are old fixed function commands for set-ups that don't have user defined shader programs written using either GLSL, or CG, if you are using a programmable shader those commands will do nothing. They will be by-passed. There is a program for loading .obj models on the following site. http://www.dhpoware.com/demos/glObjViewer.html It handles normals correctly when exported from Blender and can handle generating them when the normals are not present in the .obj. Also the problem that you are having may be related to the default export settings in Blender. The default Blender .obj export settings do not export normals. You do look ambitious about solving this programmatically so I wish you luck with that and bid you adieu.


Consider it pure joy, my brothers and sisters, whenever you face trials of many kinds, because you know that the testing of your faith produces perseverance. Let perseverance finish its work so that you may be mature and complete, not lacking anything.


#8 Shawn619   Members   -  Reputation: 342

Like
0Likes
Like

Posted 10 June 2013 - 09:03 AM

GL_SMOOTH and GL_FLAT are old fixed function commands for set-ups that don't have user defined shader programs written using either GLSL, or CG, if you are using a programmable shader those commands will do nothing. They will be by-passed.

There is a program for loading .obj models on the following site.
http://www.dhpoware.com/demos/glObjViewer.html

It handles normals correctly when exported from Blender and can handle generating them when the normals are not present in the .obj.

Also the problem that you are having may be related to the default export settings in Blender. The default Blender .obj export settings do not export normals.

You do look ambitious about solving this programmatically so I wish you luck with that and bid you adieu.

 

Oh ok, FLAT and SMOOTH make sense now. I have figured out that the .obj loader that I had written is incapable of rendering smooth models, only flat. Thanks!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS