Category: News ArchiveHits: 860
Water. You can drink it, you can walk in it, you can dump bodies into it. At least that's what the folks at Owlcat Games think, and they share these thoughts in the latest Kickstarter update for Pathfinder: Kingmaker. If you're curious to see how that game will deal with water effects and physics – you might want to check it out. An excerpt:
Today's update is all about water rendering in our game. Water is the most complicated rendering object from a technical point of view. To make the magic happen we use various subsystems of the game engine and thoroughly prepare both procedural and baked textures. Besides, we need a combination of programming skills, the abilities of our technical artists, lots of patience and a bit of luck. For our update, let's not dwell on trivial things, such as calculations of water lighting. Instead we are going to tell you about the difference between water rendering and rendering of regular geometry. Let's dive right in!
Perfectly clear water is usually almost colorless, and only if its layer becomes thicker, it gets a bluish shade. However, there are only a few places on Earth, where you can find such clear water in a natural environment, e.g. Blue Lake in New Zealand. In most cases, water contains tiny particles of other substances, which can color it into various shades. This effect is especially noticeable in rivers and streams, where running water carries more of such particles.
However, water color depends not only on particles of other substances, but also on some other parameters, and the most relevant for us is density. To make things easier, we'll make the assumption that the water color depends on depth (layer thickness) multiplied by density. In shallow water it becomes easier to see what's beneath, and in deeper places we can see more color of the water itself. The density is adjusted by our artists, and as for the depth, we calculate it via shader, using z-buffer.
Reflect or refract?
Actually, we need both reflection AND refraction. The hard part is this: while rendering water surfaces, we need to prepare two textures - one with the reflections, and another with all the objects that are located underwater. If we approach this problem bluntly, we can just render all the objects located underwater to the refraction texture, and all the objects located above the water to the reflection texture, adding a mirror camera matrix. If we choose this approach, we'll need to draw each object 3 times: 1. to the refraction texture, 2. to the reflection texture and 3. to the screen.
However, after giving this some thought, we came up with a better solution. We moved the water textures in the rendering queue, so they are rendered after all the other objects. When the other objects are drawn, the we draw the water, so we just copy everything we've drawn before on the screen to the new texture and use it as a refraction texture. This way, we have fewer objects to draw. We can't do this with the reflections, though, so we render all the objects to a separate texture. At this stage another question appears: should we calculate the light for these objects? We decided it consumes too many resources, especially when taking into account the minimal hardware requirements for our game. That's why we draw all the reflections in monochrome, and artists can adjust the colors later.
Distortion is adjusted by artists as well, but this parameter, just like density, depends on depth, so we again turn to the z-buffer to calculate proper distortion.
Twice in the same river
So, now we can set the water color, reflection, and refraction. The only thing left to do is to make water flow.
In the first iteration, we animated texture coordinates of bump-textures. If this animation is done right, we can also adjust water for lakes and ponds.
In Pathfinder, there are lots of locations with rivers and streams. We wanted the player to see that water curves around the stones and readily flows through all the turns of a watercourse. To do that, we used flow maps. They contain encoded vectors of flow direction. Artists can draw these flow maps by themselves, which gives them more opportunities to control the looks of the flow.