PDA

View Full Version : 2 problems (specular, materials)



KylBlz
09-09-2010, 03:10 PM
Hello all,

I have 2 problems that are probably being caused by the same thing so i decided to make one thread about it. For starters, I'm using a ported openGL implementation called PSPGL (for sony psp) so this problem may just be the lib.

Moving on, specular lighting doesnt work at all. i have modeled my object in a freeware program called Anim8or. It has a simple material interface like so:
http://www.anim8or.com/manual/dialogs/dlg_material.jpg
As you can see, its all here: ambient, diffuse, specular, emission, roughness (which is GL_SHININESS), and brilliance (which im not implementing)



glMaterialfv(GL_FRONT, GL_AMBIENT, &ambient[0]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, &diffuse[0]);
glMaterialfv(GL_FRONT, GL_SPECULAR, &specular[0]);
glMaterialfv(GL_FRONT, GL_EMISSION, &emissive[0]);
glMaterialf(GL_FRONT, GL_SHININESS, &Roughness);

Here im setting all the components, each array above has R,G,B,A components in the form of GLfloat. Roughness is of course a GLint.

Here is my light source:

static light light0 = {
{0.2f, 0.2f, 0.2f, 1.0f}, // ambient
{1.0f, 1.0f, 1.0f, 1.0f}, // diffuse
{1.0f, 1.0f, 1.0f, 1.0f}, // specular
{1.0f, 0.5f, 1.0f, 0.0f}, // position
};
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, light0.ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0.diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light0.specular);
glLightfv(GL_LIGHT0, GL_POSITION, light0.position);
Which leads me to my inquiry, WHY ISNT SPECULAR WORKING?

Now that you know the basic material setting code (the first code block) you may help with the second problem.

I have a grass texture, and a water texture. I have a grass material (uses grass texture), water material (uses water texture), and a metal material (uses NO texture). However, it seems as though the metal material inherits the ambient color of the previous material. When i switch to the metal material from grass, it is green, when i switch from water, it is blue! its apparent that im setting the ambient color.. so i dont know why its happening.

The metal material is the reason for the specular issue, as it relys heavily on it.

Sorry for the verboseness of this request.

ZbuffeR
09-09-2010, 03:37 PM
WHY ISNT SPECULAR WORKING
No idea. Can you post a picture of your specular looks ?
Do you provide correct normals, with enough tesselation (as old style GL needs a lot of vertices to show somewhat correct specular shading).
Ie read "2. Poor Tessellation Hurts Lighting" here :
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

As for the metal material, make sure you disable texturing before drawing with it, otherwise the last used texture ... well will still be used (and without texture coordinates so it will look like a constant color from the last texcoord).

KylBlz
09-09-2010, 04:46 PM
Anim8or computes all the normals for you, and does a very good job of it. the object is made of about 200 polygons.. IMO there are enough polys to facilitate specular lighting.

This model uses 3 materials, brown handle, dark metal, and chrome. both metallic textures look flat because the material relys on heavy specular lighting to look like metal.

here are 2 pictures, the first one is how its supposed to look, the second is how it looks on my psp:
http://img827.imageshack.us/img827/96/88053088.jpg
The diffuse lighitng is working OK as you can see in the brown handle, however its darker because there is no specular highlight.

Edit: lol yes, i modeled knifegun, and its awesome ;P