Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: Pixel_Outlaw on January 05, 2009

Title: [OpenGL] Best way to give a chrome impression.
Post by: Pixel_Outlaw on January 05, 2009

I'm working on a very simply game and everything is going well. My main problem artistically is getting my little cell objects to look like chrome. I guess the answer would be to use a simple reflection. I wonder if using cube maps or some other trick would be fast enough for 100 small cell objects. It would be really cool so see maybe some cloud texture move while they rotate. I may need to ask for help coding such an effect too. Here is a video for the current engine. It would be really cool so see some small hints of reflection in these things.

[youtube]http://www.youtube.com/watch?v=5-kc2T_6-yA&feature=channel_page[/youtube]


Title: Re: [OpenGL] Best way to give a chrome impression.
Post by: hellfire on January 05, 2009
You can simply use a sphere-map.
The problem with spherical environment mapping is that they have ugly distortions on the back-side, but I guess this won't be a problem in your case as the view-point seems to be fixed.
All you need are proper vertex-normals and OpenGL will handle the rest:
Code: [Select]
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, envmap);
   glEnable(GL_TEXTURE_GEN_S);
   glEnable(GL_TEXTURE_GEN_T);
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

// render

   glDisable(GL_TEXTURE_GEN_S);
   glDisable(GL_TEXTURE_GEN_T);
GL_SPHERE_MAP reflects the view-vector (camera to vertex) at the surface-normal and projects it into spherical coordinates, so the environment-map represents the reflective (specular) part of the light.
If you want diffuse lighting, you can use GL_NORMAL_MAP instead (and use a very blurry texture) - or even both.

Setting up a proper sphere-map works like this:
(http://www.abload.de/img/sphere8pxd.jpg)
You can find many of those on Paul's site (http://www.debevec.org/Probes).

If you want inter-object-reflection it's going to be a bit trickier, though.
Title: Re: [OpenGL] Best way to give a chrome impression.
Post by: Pixel_Outlaw on January 05, 2009
Ok, I'll give this a shot now.

Is there a good way to turn an already seamless texture into the sphere map?
Title: Re: [OpenGL] Best way to give a chrome impression.
Post by: benny! on January 05, 2009
Guess Hellfire tip will help you.

The video looks very cool - looking forward
to interact with it ;-)
Title: Re: [OpenGL] Best way to give a chrome impression.
Post by: hellfire on January 05, 2009
Quote
Is there a good way to turn an already seamless texture into the sphere map?
Strictly speaking no, because there is no way to wrap a rectangular texture around a sphere without producing distortions somewhere.

Probably the best (and most laborious) way is to arrange your texture to form a cubemap:
(http://www.abload.de/img/cuben66o.jpg)
(keep in mind which edge connects to another edge to avoid seams; also check skypaint (http://www.skypaint.com))
Cubemaps are defined in spherical domain, too, so they can be easily converted (have a look at hdr-shop (http://projects.ict.usc.edu/graphics/HDRShop)).

You can also treat your rectangular texture as a lattitude/longitude map:
(http://www.abload.de/img/lattitude6cir.jpg)
Just ignore the missing distortions at the poles and transform it into a ball (hdr-shop again).
You can often find half of these in texture-archives for mapping hemispheres (eg. here (http://www.cgtextures.com/textures.php?t=browse&q=26546)).

A much simpler but often used approach is to apply some sort of spherize distortion (photoshop) to your texture to imitate the shape of an actual envmap.
Title: Re: [OpenGL] Best way to give a chrome impression.
Post by: Pixel_Outlaw on January 05, 2009
Is this image prepared properly for the last way you mentioned? I assume the excess corner material is ignored?
Title: Re: [OpenGL] Best way to give a chrome impression.
Post by: hellfire on January 05, 2009
Looks pretty doable to me. Just try it!
Keep in mind that the texture represents a reflection and thus should gives clues about (and should integrate well with) the environment.
For reference I attached an envmap done by acryl (http://gfxzone.planet-d.net/personal/acryl/acryl-personal_01.html) which is based on a photo but was created the same way (spherize filter).