Moderator elections are being held. See Valve Developer Community:Moderator elections for more details.
Users who would like to run for moderator must be autoconfirmed and have at least 100 edits. Users can check their own edit count at Special:Preferences.
This article relates to the game "Counter-Strike: Source". Click here for more information.
This article's documentation is for anything that uses the Source engine. Click here for more information.

Real-time Reflections in CS:S

From Valve Developer Community
Jump to: navigation, search

English (en)Français (fr)
Real-time Reflections in CS:S

Using the Source engine, the only way to get real-time reflections is to use the "water" shader (typically used for water textures). Typically, reflections are made possible by Cubemaps, which are low-quality and pre-calculated but sufficient for most materials. Cubemaps are not useful for a mirror which requires a real-time reflection. There is a trick, however, that makes it possible to use real-time reflections in a custom material. this technique consists in superimposing (overlaying) 2 shaders: A normal transparent shader and a water shader (for reflections only). This technique is ideal for a floor, but unfortunately cannot be applied to a wall due to an engine limitation with the water shader. The water shader reflects everything in the world except for the player.

This technique is mostly useless since Source 2007 Source 2007, because has an entity for real-time reflections which can be applied to a wall: func_reflective_glass, which uses the Shader-ball.png LightmappedReflective shader.

How it Works

The three materials:

You need to use 3 layers of materials:

  • Normal material (in alpha) on the surface where players will walk. Optional.
  • A material with the Water shader which will show reflections in real time.
  • Something to overlay the water material (without this, it will not work properly).

Material for the Surface

Create a brush that is 1 hammer unit thick and apply the material to it with alpha. It is important to leave a gap of any width between this material and the water, or the alpha will not work and you will have a kind of blurry effect.

Example :

         $alpha 0.6
         $basetexture ...


          %compilewater 1
          $reflecttexture _rt_WaterReflection
          $reflectamount 0.1  // The lower the value, the more reflections you will have.
          $reflecttint "[1 1 1]"
          $normalmap ....  // Indicate a texture of solid colors, such as a solid white texture.
          $fogenable 0
          $fogcolor "[1 1 1]"
          %compilepassbullets 1  

The parameter "%compilepassbullets" 1 will make the material unresponsive to external effects, balls and players who step on it will have no effect on it. This setting is essential for CSS, because the balls go through the Blocks, every time you shoot on the ground you will have a SPLASH, which is not realistic. You can also, thanks to this compilation parameter, run on this surface, as on a mirror.

Covering the Material

It's pretty important to cover this material, but it doesn't matter how you do it.


Translation Notes

I'm going to follow this tutorial to learn how it works, and then rewrite the page in a way that English readers can understand.