Real time reflections w/ HL2 engine

Discussion in 'Mapping Questions & Discussion' started by necro, May 10, 2008.

  1. necro

    necro L3: Member

    Messages:
    106
    Positive Ratings:
    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)

    [​IMG]

    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:

    [​IMG]

    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:

    [​IMG]

    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:

    [​IMG]

    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.
     
    • Thanks Thanks x 1
  2. R3dRuM

    R3dRuM L6: Sharp Member

    Messages:
    303
    Positive Ratings:
    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
     
  3. necro

    necro L3: Member

    Messages:
    106
    Positive Ratings:
    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. :)
     
  4. YM

    aa YM LVL100 YM

    Messages:
    7,099
    Positive Ratings:
    5,745
    Not really, all the engines that do have real time reflections are hugely lacking in some other way.
     
  5. tedrock

    tedrock L2: Junior Member

    Messages:
    79
    Positive Ratings:
    8
  6. Pseudo

    Pseudo L6: Sharp Member

    Messages:
    319
    Positive Ratings:
    149
    • Thanks Thanks x 1
  7. necro

    necro L3: Member

    Messages:
    106
    Positive Ratings:
    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: May 11, 2008
  8. necro

    necro L3: Member

    Messages:
    106
    Positive Ratings:
    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.
     
  9. Snipergen

    Snipergen L13: Stunning Member

    Messages:
    1,053
    Positive Ratings:
    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 :)
     
  10. YM

    aa YM LVL100 YM

    Messages:
    7,099
    Positive Ratings:
    5,745
    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
     
  11. Trypto

    Trypto L1: Registered

    Messages:
    35
    Positive Ratings:
    12
    Wouldn't that also give the distortion effect on the water?
     
  12. YM

    aa YM LVL100 YM

    Messages:
    7,099
    Positive Ratings:
    5,745
    not if you make your own water texture that has no distortion and isnt animated. (there are tutorials out there....)
     
  13. necro

    necro L3: Member

    Messages:
    106
    Positive Ratings:
    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.
     
  14. Lord Ned

    Lord Ned L7: Fancy Member

    Messages:
    421
    Positive Ratings:
    174
    Last edited: May 18, 2008
  15. YM

    aa YM LVL100 YM

    Messages:
    7,099
    Positive Ratings:
    5,745
    The second link lord ned posted is the one I was thinking of when I said use water
     
  16. EVIL

    EVIL L1: Registered

    Messages:
    1
    Positive Ratings:
    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
     
  17. YM

    aa YM LVL100 YM

    Messages:
    7,099
    Positive Ratings:
    5,745
    nope, certain expencive waters do real time reflections(go play lost coast if you don't believe me)
     
  18. Spike

    Spike L10: Glamorous Member

    Messages:
    716
    Positive Ratings:
    82
    Actually that's the way how HL1 mappers did reflections. Cool but FPS killer.
     
  19. Dox

    Dox L8: Fancy Shmancy Member

    Messages:
    588
    Positive Ratings:
    62
    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.
     
  20. R3dRuM

    R3dRuM L6: Sharp Member

    Messages:
    303
    Positive Ratings:
    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.

    [​IMG]
     
    • Thanks Thanks x 1
    Last edited: Jun 17, 2008