Portal 2

Portal 2

Not enough ratings
Reflective Water: Part 2
By Pilchardo
Reflective Water: Part 2 explores how to achieve fully reflective water at multiple levels in a single map.
   
Award
Favorite
Favorited
Unfavorite
Introduction
Part 1 of this guide covered a simple way to ensure your water is fully reflective without having to venture outside of the in-game puzzle maker. Part 2 offers a more complete solution but will require delving into the Portal 2 Authoring Tools (specifically, Hammer). If you haven't used Hammer before then don't worry; it's actually very intuitive and there's tonnes of information online to help you out.
Potentially Visible Sets
Update: Further experimentation has revealed that two bodies of water created at different heights in Hammer will work and reflect the environment without any problems. This is possibly due to an engine update (?). This section is therefore redundant but I'll leave it here for posterity. The section on Water Textures remains relevant as maps created using the in-game editor still automatically revert to using cheap water textures when two water brushes are created at different heights. See that section for the solution.

In part 1 of the guide I stated that in order for water to be fully reflective, it must be at a single height only within a given map. That isn't strictly true. It is true that the game engine can only render one height of reflective water at once, which means that if you have two separate bodies of water in different Potentially Visible Sets (PVS) then they can both be properly reflective, "expensive" water textures.

A PVS is an area of your map that the game engine thinks might be visible from where the player is standing. When you compile your map the compiler automatically splits your level up into these PVSs. When the game is running, the engine only actually renders the geometry and entities that fall into the player's current PVS. This means that as long as your bodies of water are in separate PVSs, they'll never be rendered at the same time and so there's no reason they can't be displayed properly. A rule of thumb is that if you have to traverse two corners to get from one area to the other, they'll be in different potentially visible sets. The screenshot on the right shows a map where the two pools of goo are definitely separate.

When running your map in-game, you can easily see the potentially visible sets by opening the console with the ` key (you may need to enable the console in the settings first) and entering the following command:

mat_leafvis 3

If this has no effect, make sure you've enabled cheats first using:

sv_cheats 1

The PVS that you're standing in will now be highlighted in blue, as shown below. Try moving around - you'll see the PVS change as you move from one area to another. You can use this to confirm that the potentially visible sets that your bodies of water are part of do not coincide.


However, there's a small catch. If you're using a chamber that you created in the puzzle maker, you'll have noticed that your water isn't rendering correctly, despite being in completely separate areas of the map. The reason for this is that the in-game compiler automatically replaces the nice, pretty water textures with cheap alternatives as soon as it discovers that you have water at multiple heights in your map. To fix this, we'll need to dive into Hammer.
Water Textures
First, open the console while your map is loaded in the in-game puzzle maker and enter:

puzzlemaker export filename

Replace "filename" with whatever you want to call the exported map file (don't worry about the file extension - it'll be added for you).

Now go into the tools view of your Steam library and open the Portal 2 Authoring Tools. When the small window opens, double-click Hammer, then select File -> Open and navigate to your exported map file. It'll probably be in a directory similar to this and have the .vmf extension:

C:\Program Files (x86)\Steam\steamapps\common\portal 2\sdk_content\maps

Depending on the size of your chamber, it may take a while to load and Hammer will flash and flicker a lot. Don't worry - this is normal! When the file has finished loading you'll need to navigate to your water. The easiest way to do this is to fly through the 3D view. First though, right-click on camera in the top-left of the 3D window and make sure 3D Shaded Textured Polygons is selected. This will make the view look closest to how it will appear when you actually run the game and so will make navigating around much easier. Pressing the Z key locks your mouse into controlling the camera and allows you to fly around using the WASD keys, just as if you were playing the game. Now, fly through the world (and through walls!) until you find the first block of water you want to edit.

Found it? Press Z again to unlock the mouse and then locate the Toggle Texture Application toolbar button. It's the one with an image of a green, blue and orange cube and is probably somewhere along the left-hand side of the screen. Alternatively you can press Shift+A. Both methods will open the Face Edit Sheet dialogue box. Click the surface of your water to select a section of it and populate the dialogue box with the selected texture. You'll see that it's something called:

nature/toxicslime_puzzlemaker_cheap

This is the cause of all our problems! Change it to the following and click Apply:

nature/toxicslime_a2_bridge_intro

You'll need to do this for the upper surface of every brush (cube) that makes up the water in your map. Fortunately, you can do this fairly quickly now that you've selected the correct texture by simply right-clicking on each surface in the 3D view that you want to apply the texture to (with the dialogue box still open). An even faster method is to click the 'Replace...' button to bring up the Replace Textures dialogue. This will allow you to replace all instances of the unwanted texture with the shiny new one. Use the 'Browse...' button to locate the textures and click 'OK'.

You can now run your map to see the effect of your changes. Selected File -> Run Map (or press F9) and be sure to tick the HDR checkbox before clicking OK in the dialogue box that pops up. Your map will be compiled and Portal 2 will automatically start and load your map. You should now find that your water is reflecting its surroundings correctly. Hooray!

And here's the proof:

Wrapping Up
Most of this information was gleaned from the Valve Developer Community with the following pages being particularly helpful:

Adding Water
PVS
Visibility Optimisation

If you get stuck, I'd recommend either looking at the above links or posting your questions in the comments below - I'll do my best to answer them.

Finally, this is a work in progress and will be updated over the next few days. There's plenty more to discuss, so keep checking back! The next update will cover area portals (not to be confused with Aperture portals) which should help in situations where the engine incorrectly believes that two bodies of water can be simultaneously visible.

Happy mapping!
6 Comments
aden8r 11 Feb, 2020 @ 1:06pm 
exporting puzzlemaker maps to hammer is generally a bad idea, as it doesn't contain certain stuff necessary; i got this info from the bee mod discord
Pajaro 30 May, 2013 @ 6:46pm 
yeah
Gman 26 Feb, 2013 @ 5:15am 
*yan
Pilchardo  [author] 23 Feb, 2013 @ 2:31pm 
Try putting the water texture back to the 'cheap' version to see if it behaves. If it does, and is acting strangely when you're using expensive water textures, my guess would be that your two bodies of water are in overlapping PVSs. You might be able to solve the problem using areaportals , but I must confess that I haven't played with those yet.
Professor Chaos 23 Feb, 2013 @ 2:19pm 
what do i do?
it ownt turn back
Professor Chaos 22 Feb, 2013 @ 9:50pm 
pt 2 beter then pt 1 but some of the watert is giltched