Jump to content
  • Advertisement
Sign in to follow this  
deavik

Color Material

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

If I use color materials, my models have a plasticky look. While that is my problem, my questions are 2-fold: 1. I know there is a GL_SHININESS parameter if I use glMaterialf, but that doesn't work for color material, does it? What options do I have with color material to change the appearance of a model? (I would be grateful if you gave me ALL parameters - transparency, shininess, et al) 2. I am using a basic Gouraud shading algorithm. I suspect that Phong shading would help with the specular highlights. I know it uses surface normals as well as vertex normals, but I have no idea how to implement it. Thanks for any suggestions and / or help!

Share this post


Link to post
Share on other sites
Advertisement
Check out this page:
http://sjbaker.org/steve/omniv/opengl_lighting.html

Before drawing an object, I do something like this:

GLfloat gold_ambient[]={0.24725,0.1995,0.0745, 0.0};
GLfloat gold_diffuse[]={0.75164,0.60648,0.22648, 1.0};
GLfloat gold_specular[]={0.628281,0.555802,0.366065, 0.0};
GLfloat gold_shiny[]={51.2};

glMaterialfv (GL_FRONT, GL_AMBIENT, gold_ambient);
glMaterialfv (GL_FRONT, GL_DIFFUSE, gold_diffuse);
glMaterialfv (GL_FRONT, GL_SPECULAR, gold_specular);
glMaterialfv (GL_FRONT, GL_SHININESS, gold_shiny);



Those values were taken from:
http://acc6.its.brooklyn.cuny.edu/~lscarlat/graphics/SurfMats.html

This should take away ur plasticy look. Enjoy!

Share this post


Link to post
Share on other sites
Thanks ignisdeus, thos links were VERY helpful! I did as you suggested, but - it sometimes looks like the object's appearance is changing suddenly (not a smooth transition) as the orientaion to light changes. Is maybe glMaterial slow or something? As the page in the first link said? There doesn't happen to be a cure to that, does there?

Also, do you have any tips on how to model glass with material settings? You can imagine what I want - transparent but reflections to light (like real glass).

And, about the Phong shading thing - does anyone have a clue?

Share this post


Link to post
Share on other sites
Hello,
It's hard to say why your object looks strange without seeing the source, but I know when I started, 99% of the time the lighting looked weird it was because I forgot to use normalized normals ;). Anyhoo, great info on lighting and what seems like a very good GLSL tutorial can be found on http://www.lighthouse3d.com/opengl/glsl/. Be prepared to spend some time if you really want to understand this stuff though.

Share this post


Link to post
Share on other sites
Hmmm, I can't enter the lighthouse3d website ... maybe down or something? And I am using unit normals - I do that in the model loading routine so that there are no mistakes. [smile]

... And still no one wants to tell me about Phong shading. Well, I decided to force it in: firstly I know zip about GLSL or any other shading languages. And as it looks like in ANY articles on Phong shading I can get my hands on, it seems like I will have to write my own shaders. Someone please correct me if I am wrong.

And I would be grateful for any help with the "making stuff look like glass" thing ...

Share this post


Link to post
Share on other sites
As far as glass goes, from:
http://www.opengl.org/resources/faq/technical/transparency.htm
Quote:

How can I render glass with OpenGL?

This question is difficult to answer, because what looks like glass to one person might not to another. What follows is a general algorithm to get you started.

First render all opaque objects in your scene. Disable lighting, enable blending, and render your glass geometry with a small alpha value. This should result in a faint rendering of your object in the framebuffer. (Note: You may need to sort your glass geometry, so it's rendered in back to front Z order.)

Now, you need to add the specular highlight. Set your ambient and diffuse material colors to black, and your specular material and light colors to white. Enable lighting. Set glDepthFunc(GL_EQUAL), then render your glass object a second time.


No clue on the phong shader, sorry I can't help you there. If it still looks plastic like, I'd either say your normals aren't being scaled OR your program is using the vertices as the normals.
This is what my model looked like when using the vertices as normals:
http://www.angelfire.com/space2/artib/Guy.jpg

Glad I could help btw :).

Share this post


Link to post
Share on other sites
Well I AM using vertex normals for the smooth shading. It must still be possible to have a specular hilight, right? Anyway, your earlier post helped with that, ignisdeus. And that was a great link on transparency ... you have a great googling talent, I must say!

EDIT: fixed typo [wink]

Share this post


Link to post
Share on other sites
hi. i can help you with vertex normals. Vertex normals are vectors computed by averaging the face normals from all the faces that are incident in that vertex.
you specify vertex normals like specifying colors ie between glBegin and glEnd you say glNormal3f(btw, you can use vertex arrays too). that's all about goround in fixed pipeline. this gives a surface a 'rounded' look. if you want a surface to have both rounded and hard edges, then you have to break the surface into smaller surfaces along the hard edges. this break means doubling the vertices and remaping the edges, and recalculate the vertex normals for each of the 2 vertices (which have the same position in space, but different vertex normals).

the phong alghortm is perpixel lighting. the difference from goround is that the vertex normals are interpolated for every pixel. first they are interpolated along edges (with a scanline) and the 2 normals on the edges are interpolated along the segment that imaginary links them.

surface normals (normal mapping) is obtained by using a texture that contains normals, so when doing per pixel lighting, you take normals not by interpolating vertex normals, but by taking the values from the normals texture. this is very generic info, you should dig deeper for a specific algorithm, but there are plenty on them on web.

[Edited by - meeshoo on September 6, 2005 6:05:12 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by deavik
Well I AM using vertex normals for the smooth shading. It must still be possible to have a specular hilight, right? Anyway, your earlier post helped with that, ignisdeus. And that was a great link on transparency ... you have a great googling talent, I must say!

EDIT: fixed typo [wink]


Vertex normals? Meaning you're using the vertices, as the normals? If you are, this could be the problem. If not, ignore this.

Anyways, I'm sorry I claimed I know nothing about phong shaders. I was thinking of anisoptric, which is the kind of shading a CD has, the one that bends and looks like an "S". If I think of phong the same way you do, maybe these picture will show you something you like. I made this random revolved shape in maya, and then this is what it looks like in OpenGL (keep in mind it has 70k triangles, thats why it looks so nice):




If the images aren't showing up (lame angelfire) here are the links:
http://www.angelfire.com/space2/artib/RandomShape1.jpg
http://www.angelfire.com/space2/artib/RS2.jpg
http://www.angelfire.com/space2/artib/R3.jpg

I use the following code before I render the object (the code for when the F3 key is pressed is suppose to be 'plus'=0.1f, but this board doesn't do plus signs):

//out of the draw function:
GLfloat specR=0.0f, specG=0.0f, specB=0.0f;

//inside the draw function:
GLfloat ambient[]={0.19225,0.19225,0.19225};
GLfloat diffuse[]={0.50754,0.50754,0.50754};
GLfloat specular[]={specR, specG, specB};
GLfloat shiny[]={51.2};


glMaterialfv (GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv (GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv (GL_FRONT, GL_SPECULAR, specular);
glMaterialfv (GL_FRONT, GL_SHININESS, shiny);

if(GetAsyncKeyState(VK_F3)&1==1){specR+=0.1f; specG+=0.1f; specB+=0.1f;}
if(GetAsyncKeyState(VK_F4)&1==1){specR-=0.1f; specG-=0.1f; specB-=0.1f;}



The ambient, diffuse and shiny values are the one from the page above for silver. I simply changed the specular values, using custom values. Throw this into a program, and hit F3 to increase the specularity. If you go into negatives, the surface will actually absorb light and turn black. I hope this is what you meant by phong shader. Ooo, and this is the light I was using at the time too:

GLfloat diffuse_light0[] = { 1.0f, 1.0f, 1.0f, 0.0f };
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse_light0 );


I hope this helps! Glad my googling skills are helping you, they never work for me! lol.

Share this post


Link to post
Share on other sites
Ignisdeus, I still couldn't see your images - just the angelfire logo. They must not allow direct external links, like, you must visit the page or something. I wonder how they do that?

Anyway, I tried out what you said, and a strange thing is happenning to me. Negative values for specularity make the object brighter, values nearer 1.0f just make the object almost black. I wonder if you have a clue about this, cause I don't ...

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!