Game Development Community

Environment maps and interiors

by Fenrir Wolf · in Torque Game Engine · 09/20/2003 (5:33 pm) · 2 replies

Well, I wanted to implement environment maps in my game, as a cheap and easy way to emulate reflective windows on buildings. I wasn't sure if Torque had code to handle this, but I found this thread which discussed how to enable environment mapping for various surfaces: www.garagegames.com/mg/forums/result.thread.php?qt=8555

It worked! Except I was having some weird problems with it. In particular, my environment maps seemed to be showing up at certain times and not others. For example, if I load up my level, here is how my building looked (note, I was using a bright pink env map with 1.0 opacity to test how it looks): screenshot 1 Hmm. But if I zoomed out a bit, suddenly the objects would become environ mapped correctly, as so: screenshot 2

When I zoomed back in, everything looked fine: screenshot 3 Ok, time to have fun in Visual Studio... After a lot of code tracing, I finally figured out that the fog coordinates for each vertex of the interior solids were only being calculated when an object was actually actively 'in' a fog. (Inside of Interior.cc, at Interior::setupActivePolyList around the part that decides whether or not the interior polys need to be fogged.) The problem boiled down to Interior::renderARB_FC in InteriorRender.cc, around lines 1234, which read:

glColor4f(1, 1, 1, baseLevel * (1.0 - mPoints[mWindings[j]].fogCoord));

The problem with this is that it assumes fogCoord is set correctly, when as far as I can tell, it isn't, unless the object is actually fogged. So, I changed that line to read:

if (sgFogActive)  // DAVID
  glColor4f(1, 1, 1, baseLevel * (1.0 - mPoints[mWindings[j]].fogCoord));
else
  glColor4f(1, 1, 1, baseLevel) ;

Boom. It works. I'm now getting proper environment mapping. Here's what it looks like, with normal textures applied: Environment Maps on interiors

Anyway, I'm posting this in the hopes it will help those who might have been wrestling with this same problem. I've tested this little change, and it seems to work. Of course, if your card doesn't support the multitexture extension, then this won't work as the rendering code will use the Interior::render_vc_fc function instead.

The environment map UV coordinate calculation seems to be a little screwy however, as it tends to stretch the map across the entire surface in a manner I'm not entirely happy with. So I'm going to take a look at that next.

#1
12/07/2003 (2:42 am)
Man, I wasted so much time trying to figure this out before. Thanks for sharing your solution. You should submit this as a bugfix for HEAD.

I still see a bug with environement maps though. If you set the environment map factor below 0.4 it doesn't show up. To get less environment mapping you have to use a translucent png image. The real hassle is when you want a dif with a translucent env. mapped surface.
#2
12/08/2003 (12:55 am)
I'll try to figure out how to do that, Mark. Good suggestion, I never thought about it.

As for the environment maps not showing up if the factor is less than 0.4, I can test that out. Also, if I recall correctly, the new animated skyboxes weren't showing up properly either.

Once I get some time alone with Torque, I'll check it out.