Got a problem with Phong Shading

Started by
2 comments, last by HappyCoder 9 years, 10 months ago

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,

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?

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.

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.

My current game project Platform RPG

This topic is closed to new replies.

Advertisement