Author Topic: [OpenGL] Best way to give a chrome impression.  (Read 4771 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile

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]


Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [OpenGL] Best way to give a chrome impression.
« Reply #1 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:

You can find many of those on Paul's site.

If you want inter-object-reflection it's going to be a bit trickier, though.
« Last Edit: January 05, 2009 by hellfire »
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [OpenGL] Best way to give a chrome impression.
« Reply #2 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?
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [OpenGL] Best way to give a chrome impression.
« Reply #3 on: January 05, 2009 »
Guess Hellfire tip will help you.

The video looks very cool - looking forward
to interact with it ;-)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [OpenGL] Best way to give a chrome impression.
« Reply #4 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:

(keep in mind which edge connects to another edge to avoid seams; also check skypaint)
Cubemaps are defined in spherical domain, too, so they can be easily converted (have a look at hdr-shop).

You can also treat your rectangular texture as a lattitude/longitude map:

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).

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.
« Last Edit: January 05, 2009 by hellfire »
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [OpenGL] Best way to give a chrome impression.
« Reply #5 on: January 05, 2009 »
Is this image prepared properly for the last way you mentioned? I assume the excess corner material is ignored?
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [OpenGL] Best way to give a chrome impression.
« Reply #6 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 which is based on a photo but was created the same way (spherize filter).
Challenge Trophies Won: