Jump to content
  • Advertisement
Sign in to follow this  
Trazy33

OpenGL Got a problem with Phong Shading

This topic is 1489 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

Hey guys,

 

Me and a colleage are using c++ and opengl (compatibility profile for learning purposes) at my university and we implemented phong shading for point lights. Now we should program a little game, so we decided to create a simple space invaders clone.

 

For a start, we simply put a few GL_TRIANLE pyramid objects with a texture on the screen and everything looks fine, but if we activate the phong shading, suddenly the textures all turn grey and we can't find out why? There is one point light in the middle of the screen and the phong shading was implemented for point lights.

 

Interesting fact: if we import a 3ds model in there, the shading works normal, it just won't work on the openGL created primitves?!

 

(Btw: we are using a custom (Visual Studio 2013 Ultimate) project framework with GLUT, GLee and more libraries already built in.)

 

Here are some pictures of what i mean:

 

[sharedmedia=gallery:albums:812]

 

We are still openGL beginners, so be gentle with us, thank you!

 

regards,

Share this post


Link to post
Share on other sites
Advertisement

If it works with 3DS models then I'd check the normals on your generated pyramid objects. Do you have ambient lighting as well? Because it almost looks like you have no normals and then attempt to apply lighting, obliterating all the material colors to black, and then adding in some sort of ambient term. Can you post your shader code?

Share this post


Link to post
Share on other sites

We have ambient properties of the light, textures, materials set as well yes. You can find the vertex/fragment shader code in the gallery postet above.

Share this post


Link to post
Share on other sites

I can't see the problem from the code you posted. I recommend you try to debug the shader code by assigning intermediate values directly the the output color.

 

For example, try to assign vertexNormal directly to gl_FragColor to make sure that the normals aren't zero and that they look correct. If they look correct do the same with  lightDirection and eyeDirection to make sure their values look correct too. You can also return intermediate values from calcualteSimplePointLight, such as 'diffuse' to make sure that looks correct too.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!