PDA

View Full Version : Shininess



Pops
05-13-2002, 11:24 PM
I'm rendering a nice looking car in my app and want it to look like the light is shining off the bodywork and windows (I'm not really interested in true reflections), I have played around with this but canít get any results.
Can someone please tell me the steps I should use to get this kind of effect.

Thanks

Teofuzz
05-14-2002, 12:16 AM
You can blend a texture (representing a sky for example) over the reflective parts using sphere mapping.
To obtain good results you need a good number of faces.
bye!
fz

Pops
05-14-2002, 12:35 AM
Thanks

Is their no way to achieve this using the material and lighting settings?
I only want it to look kind of shiny using the easiest method.

I assumed GL_SHININESS would do something like what I want, but I cant get any results.

Mazy
05-14-2002, 01:05 AM
GL_SHININESS only controls how big the specular point should be. You should be able to se the difference when you change from 1 to 40 to 128 but only if you have set specular color in the material to something else than 0,0,0 that is the default.. (white should be fine)

but to get reflection of the enviroonment (needed to get a real looking reflective material, like chrome objects and stuff) just apply spheremapping or reflectionmapping(cubemaps)

/mikael

blender
05-14-2002, 02:03 AM
I'm also using shine stuff in my model with sphere mapping, but would you happend to know how to 'move' the shine texture over my model witehout using glTranslate ot glRotate?
By that I mean the effect that was in Kingpin if you can remember: when you just looked around the weapon shined nicely.

Bob
05-14-2002, 02:05 AM
To get a good result with OpenGL's lighting system, you also need to tesselate your object into faily small triangles. This is because OpenGL calculate lighting per vertex, and not per pixel. The larger the shininess, the smaller the highlight, and the more you need to tesselate your object. If you can't tesselate your object as much as needed, a reflection texture is a very good solution.

Pops
05-14-2002, 02:35 AM
i dont really want the scenery to be reflected in the car. I just want it to look like the light is shining on a matt object. what i really would like is for the spots that would reflect the light directly to the camera to look brighter than the rest of the car.

Mazy
05-14-2002, 02:49 AM
the if you have a high tessellated object, specular would to it, else, you can do a map with a white dot on it ( white to black gradient from the middle and out) to simulate the light and get more accurat result.


Edit:

And to just move the light, rotate the texture matrix of the textureunit holding the light texture



[This message has been edited by Mazy (edited 05-14-2002).]

Pops
05-14-2002, 02:59 AM
I have not experimented with tessellated objects and have no idea what they are.
My car has around 5000 polys (I think they are all triangles but my app can deal with any number of points for a face) and a texture applied from one 32 bit TGA (for windows) and one 24 bit TGA for the rest of the car. At the moment my windows are completely transparent and I would like the light to shine on the windows when the angle is correct. Can this be done easly?

Tazar
05-14-2002, 04:53 AM
If you want bright highlights on your objects,
http://www.gametutorials.com has a tutorial on specular lighting... and its quite easy! That might be what you want.

Pops
05-14-2002, 05:37 AM
Thanks Tazar, thatís exactly what I wanted. Still more questions though. In the code the light settings are not set (I could only find glEnable(GL_LIGHT0) and glEnable(GL_LIGHTING).
Do you have to use and special settings for this to work.
Here is what I have so far:

//initialisation
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_SPECULAR);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
GLfloat LightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, LightDiffuse);
glLightfv(GL_LIGHT1, GL_SHININESS, LightDiffuse);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);

//drawing routine
GLfloat specularColor[3] = {1.0, 1.0, 1.0};
float g_Shine = 50.0;

glBindTexture(GL_TEXTURE_2D, texture[textureNumber]);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &g_Shine);

glColor3ub(255, 255, 255);

glBegin(GL_POLYGON);

for(int a=0; a<numVects; a++)
{
glNormal3d(Normal[a].x, Normal[a].y, Normal[a].z);
glTexCoord2f(TexCoords[a].x, TexCoords[a].y);
glVertex3d(Vects[a].x, Vects[a].y, Vects[a].z);
}

glEnd();

this is pretty much how it is in the example code but I still donít get the quote ďintense white light created on shiny objects, like metalic surfacesĒ

Am I missing something?

Old GLman
05-14-2002, 08:07 AM
Hello,

Hi, yes, your car is textured so it wont work because OpenGL doesnt apply specular highlights after you map the texture. Its in the FAQ under the Texture section. Its really easy to fix though, just call



#ifdef GL_EXT_separate_specular_color
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPA RATE_SPECULAR_COLOR);
#endif


Ofcourse you want to test to make sure the extension is supported.

yakuza
05-14-2002, 08:14 AM
Ahh, good call OldGLman. http://www.opengl.org/discussion_boards/ubb/smile.gif

Also, I don't think this is a valid light parameter, so you can probably remove this:



glLightfv(GL_LIGHT1, GL_SHININESS, LightDiffuse);


[This message has been edited by yakuza (edited 05-14-2002).]

Miguel_dup1
05-14-2002, 08:43 AM
As OLD OGLman said specular lights dont apply to textures directly...
But this is a way around this...

First you have to draw your scene without texture to get the specular highlight and another time to get the final result... Then you blend them... All of these sounds like a huge overhead...

So, you could have something like this...

glLightModelxx( GL_LIGHT_MODEL_AMBIENT, color );

glLightxx( GL_LIGHT0, GL_DIFFUSE, color );
glLightxx( GL_LIGHT0, GL_SPECULAR, color );
glLightxx( GL_LIGHT0, GL_POSITION, position );

glMaterialxx( GL_FRONT, GL_AMBIENT, color );
glMaterialxx( GL_FRONT, GL_DIFFUSE, color );
glMaterialxx( GL_FRONT, GL_SPECULAR, color );
glMaterialxx( GL_FRONT, GL_SHINENESS, 128 );


glColorxx( color );

//your polygons...

glRectangle(); // I dont know, something.

glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_XD);

glLightxx( GL_LIGHT0, GL_AMBIENT, normal );
glLightxx( GL_LIGHT0, GL_DIFFUSE, normal );
glLightxx( GL_LIGHT0, GL_SPECULAR, color );

glMaterialxx( GL_FRONT, GL_AMBIENT, normal );
glMaterialxx( GL_FRONT, GL_DIFFUSE, normal );
glMaterialxx( GL_FRONT, GL_SPECULAR, color );
glMaterialxx( GL_FRONT, GL_SHINENESS, 0 );

//You polygons again...
glRectangle();


I hope this helps... I am not saying this is optimal either. But it is an idea.

http://www.opengl.org/discussion_boards/ubb/smile.gif

Old GLman
05-14-2002, 10:22 AM
Hi, yeah you can do a two pass technique like above also, its entirely preference. You should always try to avoid the use of extensions if there is another way though.

Old GLman

Jambolo
05-14-2002, 06:38 PM
You may disappointed with specular highlights. Research how to do "environment mapping".

Pops
05-14-2002, 11:09 PM
Thanks Old GLman and yakuza.

I added the
#ifdef GL_EXT_separate_specular_color
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPA RATE_SPECULAR_COLOR);
#endif
bit as suggested but my code skips that bit (I assume the extension is not supported). What do I need to do to make it work?

yakuza
05-15-2002, 05:27 AM
Are you doing a check anywhere to define GL_EXT_seperate_specular_color as true if your card supports it? I have an InitExtensions() routine that checks all extensions returned from glGetString(GL_EXTENSIONS).

If you are doing that, what video card are you using?