Masked Mirror Surfaces
by Brett Fattori · 08/27/2003 (11:21 am) · 8 comments
If you're like me, you've envisioned a big city with lots of reflecting buildings. The surroundings all laid out to see, reflected in the glass of the windows. Well, sorry to say, with current hardware and the TGE's implementation of mirrors, this isn't possible without a LOT of tweaking. However, for that quick and dirty mirror (dirt is optional!) you can make these changes to get mirrors that are masked. It isn't a perfect mask, but it's close and you may find this little example useful in your implementation.
BACK UP YOUR CODE!! - Can't say this enough...
We only need to change mirrorSubObject.cc to get this to work. In the method MirrorSubObject::closePortal change the line that reads:
Here is a sample of what is possible:

Stencil buffer reflections are framerate-eaters!! And the actual image will be a little darker when it is displayed in the engine, due to the blending. But I think that you'll find this useful. Note that this change will modify ALL mirrors in your game, so if you already have some, any alpha textures will show up more vividly.
Enjoy,
Brett
BACK UP YOUR CODE!! - Can't say this enough...
We only need to change mirrorSubObject.cc to get this to work. In the method MirrorSubObject::closePortal change the line that reads:
glEnable(GL_BLEND); [b]glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);[/b]To read:
glEnable(GL_BLEND); [b]glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);[/b]Then scroll down a little and change the line (around 243):
glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); [b]glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);[/b]To read:
glEnable(GL_TEXTURE_GEN_S); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); [b]glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);[/b]Finally, around line 249, change this line:
glActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_VERTEX_ARRAY); [b]glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);[/b]To read:
glActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_VERTEX_ARRAY); [b]glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);[/b]And that should do it.. Now any alpha in your textures will be applied to the mirror.
Here is a sample of what is possible:

Stencil buffer reflections are framerate-eaters!! And the actual image will be a little darker when it is displayed in the engine, due to the blending. But I think that you'll find this useful. Note that this change will modify ALL mirrors in your game, so if you already have some, any alpha textures will show up more vividly.
Enjoy,
Brett
About the author
Recent Blogs
• A small hello• Recent Stuph
• So long and so out of touch...
• Plan for Brett Fattori
• Plan for Brett Fattori
#3
08/27/2003 (11:23 am)
Looks pretty cool :) But I can imagine what those mirrors are doing to your frame rate, ouch!
#4
I haven't really played around with mirrors much yet, so what exactly does this resource "fix" by changing those few little things?
How much of a framerate loss did you get from your fix in that map with the helicopter you took shots of?
04/06/2004 (4:02 pm)
I have a couple questions nearly a year after this resource's release =pI haven't really played around with mirrors much yet, so what exactly does this resource "fix" by changing those few little things?
How much of a framerate loss did you get from your fix in that map with the helicopter you took shots of?
#5
Framerate losses were actually quite minimal, until I tried making buildings with more than one reflective surface. It was really just a test of whether it could be done. But imagine being able to create a truely semi-reflective surface within a game. You could use it as your floor, and have dirt that doesn't reflect...
- Brett
06/01/2004 (12:39 pm)
It gives you the ability to supply an alpha map that will be applied to a mirror surface. Thus, instead of always having mirrors that are a perfectly reflective surface, you could instead have a surface that varies in reflectivity based on the alpha of the texture.Framerate losses were actually quite minimal, until I tried making buildings with more than one reflective surface. It was really just a test of whether it could be done. But imagine being able to create a truely semi-reflective surface within a game. You could use it as your floor, and have dirt that doesn't reflect...
- Brett
#6
-B
06/08/2004 (9:26 pm)
works great only one question... when using a single texture on a mirror surface, how do I get it to only reflect in the windows, like you have in the second shot?-B
#7
- Brett
10/19/2004 (3:30 pm)
You need to set the alpha so that where you don't want it to reflect, it's zero. Anything above that and it reflects.- Brett
#8
04/24/2005 (12:33 pm)
How do you actually apply a mirror effect to a surface in QuArK? 
Torque Owner Brett Fattori
- Brett