Real time reflections w/ HL2 engine

necro

L3: Member
Mar 24, 2008
106
13
Ever wanted realtime reflections in your map, like a polished floor, or a mirrored wall? I know the HL2 engine is archaic, and doesnt really support reflections (other than the cheesy env_cubemaps). So here is an old trick I used from a map I made for Shadow Warrior (read your history kiddies)

The illusion is simple really. Lets say I had a scene like this (which it just so happens I do in the map I'm currently working on)

tut01.jpg


And lets say you want the river to be reflective. Just select any of the brushes and models you want to reflect, click into the front or side view and press Ctrl+I. This will flip them upside down. Make sure your texture lock button (the TL one at the top) is clicked on when you flip the objects. Otherwise the textures wont flip with the brushes. Then just move them down to align at the reflective surface. You'll end up with something like this:

tut02.jpg


Then just put a brush with a transluscent texture at the reflection plane, and the illusion is complete. You could use a glass texture for a mirror surface for instance, or make your own, like I had to for the icy river.

Now, here's the most important part:

This can be an absolute framerate killer if its not done right!!!

You'll need to go through and delete any surface that wouldn't reflect. In my example, for instance, all the contents of the cabin's interior would get deleted, as well as the back walls. The top of the roof would get a nodraw texture, since only the underside of the eaves would reflect. All floor surfaces get deleted, since they dont reflect. You get the idea.

Also, this can be an absolute Vis killer. Make sure everything in your bizarro world is either a func_detail, displacement, model, or anything else that doesnt get processed in vis.

Some other caveats. If you're reflecting models that are very asymmetrical, then the illusion doesnt work, since you can't flip models (unless you actually make a custom model). In my example, I lucked out since the 2fort bridge model is symmetrical.

Another caveat is that player models obviously wont reflect. So everyones a vampire in your mirror.

If its an outdoor scene, there are some other considerations. Obviously the sun is going to keep shining down into your bizarro world. That means the underside of things will get lit instead of the top. If you have a very transparent surface, this may become an issue. It wasnt really noticeable with my ice texture. Here's the end result:

pl080000.jpg


And if you plan to reflect the sky, you'll probably want to make a custom sky texture thats mirrored at the horizon, like this:

necroskyft.jpg


Well, its sucks that in todays day and age that we need to use these old tricks to get around engine limitations, but there ya go.
 

R3dRuM

L6: Sharp Member
Feb 13, 2008
303
19
That isnt good for tf2, just eyecandy... lots of eyecandy. will result in tremendous more fps loss.

But good thinking, could be useful in single player
 

necro

L3: Member
Mar 24, 2008
106
13
Um, wrong. If its done right, theres no appreciable hit on framerate. My map was getting 120fps before I mirrored it. Its now getting 110fps. I dont call that a tremendous loss.

You know, I tried many things to get the ice to look right, but sometimes, without reflections, it just doesnt work. Besides, I think a lot of maps could use a little more eyecandy. :)
 

YM

LVL100 YM
aa
Dec 5, 2007
7,158
6,079
Well, its sucks that in todays day and age that we need to use these old tricks to get around engine limitations, but there ya go.
Not really, all the engines that do have real time reflections are hugely lacking in some other way.
 

necro

L3: Member
Mar 24, 2008
106
13
Sounds like that technique has some major limitations, especially in multiplayer. Interesting though.


Ha! I stand corrected. Thanks Pseudo. Has anyone actually used this in a map? It surely has to be a major fps killer, since its rendering the world twice, no? Its ashame theres not a flag to reflect players only.
 
Last edited:

necro

L3: Member
Mar 24, 2008
106
13
Alright, I just did a test. Standing in the same spot in my map, here are the results:

Solid ground (reflected brushwork deleted): 110 FPS
Reflected brushes as described above: 100 FPS
Func_reflective_glass in lieu of brushes: 50 FPS

Clearly the Func_reflective_glass is only useful for reflecting smallish rooms. For large areas, my method is probably still preferred, since you can refine what gets reflected.
 

Snipergen

L13: Stunning Member
Nov 16, 2007
1,051
150
Wouldn't you rather use that 10 fps for detailing your normal world? I know I would :p

Thx for the tut though necro :)
 

YM

LVL100 YM
aa
Dec 5, 2007
7,158
6,079
other way of doing this is to use a 1 unit thick sheet of water under a transparant texture (so you can't shoot it and see splashes)
because the water does reflections it works great
 

Trypto

L1: Registered
Apr 1, 2008
35
22
other way of doing this is to use a 1 unit thick sheet of water under a transparant texture (so you can't shoot it and see splashes)
because the water does reflections it works great

Wouldn't that also give the distortion effect on the water?
 

YM

LVL100 YM
aa
Dec 5, 2007
7,158
6,079
not if you make your own water texture that has no distortion and isnt animated. (there are tutorials out there....)
 

necro

L3: Member
Mar 24, 2008
106
13
I'll give your idea a try Youme. During the playtest on my map, a couple people were bitching bout the framerate. So even though the reflections work fine on my machine (and most peoples), perhaps older vid cards are having difficulty with having a bunch of models and displacements under the that much transluscent material. Course, even the water under all that transluscent may be an issue for those same people.

At any rate, I'm curious what kinda effect it'll create. So I'll post some pics once I try it.
 

YM

LVL100 YM
aa
Dec 5, 2007
7,158
6,079
The second link lord ned posted is the one I was thinking of when I said use water
 

EVIL

L1: Registered
Jun 9, 2008
1
0
The downside of the water trick is that it uses cubemaps and cubemaps are impossible to align perfectly. They are great for prop reflections but horrible for surface reflections.

The mirror one looks good, I wonder if it would be possible to edit it so the further away the object is from the reflected surface the more blurred it would be, to simulate lynolium type floors
 

YM

LVL100 YM
aa
Dec 5, 2007
7,158
6,079
The downside of the water trick is that it uses cubemaps and cubemaps are impossible to align perfectly. They are great for prop reflections but horrible for surface reflections.

nope, certain expencive waters do real time reflections(go play lost coast if you don't believe me)
 

Spike

L10: Glamorous Member
Feb 13, 2008
716
82
Actually that's the way how HL1 mappers did reflections. Cool but FPS killer.
 

Dox

L8: Fancy Shmancy Member
Oct 26, 2007
588
62
Wouldn't you rather use that 10 fps for detailing your normal world? I know I would :p

Thx for the tut though necro :)

I don't know, that does look pretty neat, I think it is worth the hit as outdoor maps don't need as many small details.
 

R3dRuM

L6: Sharp Member
Feb 13, 2008
303
19
Your reflections are in no way real time, they eat up map fps and don't look good in the end.
Your best bet would be to use func_reflective_glass. It is actually true real time and it reflects all players and objects but yourself.

163b.jpg
 
Last edited: