Share this project


Share this project

Pathfinder: Kingmaker is an isometric single-player RPG based on the Pathfinder Roleplaying Game Kingmaker Adventure Path.
Pathfinder: Kingmaker is an isometric single-player RPG based on the Pathfinder Roleplaying Game Kingmaker Adventure Path.
Pathfinder: Kingmaker is an isometric single-player RPG based on the Pathfinder Roleplaying Game Kingmaker Adventure Path.
18,351 backers pledged $909,057 to help bring this project to life.

Going with the flow - The water in Pathfinder: Kingmaker

Posted by Berserkerkitten

Dear Pathfinders,

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.


What else should we add…  

What we have now, looks rather good already, but still not good enough - something's missing.  


Right! Foam!  

To draw foam, we use 4-channel texture, where each channel contains a foam texture with different density. While rendering, we once again use z-buffer to estimate water depth, and in the locations with minimal depth (usually near the shore) we add foam. Less depth means increased foam density.  


But if we use depth as our only reference, sometimes we can't show the foam everywhere our artists want to see it. That's why we added a special mask to one of the channels of the flow map. This mask determines, where the foam will be shown, regardless the depth. This helps to highlight the spots with stronger flow.


Combined together, it looks like this  

What if I want to walk in there?  

This part of the content is still under construction, so we'll describe this process, using examples and imagination. ☺

In previous updates you may have noticed our characters can already interact with grass. To establish this kind of interaction, we draw special textures, which are projected on the location from above. When a character moves, he leaves a trail in this texture. Then, when we render grass, we take information from this texture and animate the grass, if it happens to grow under the character's trail.  

Interaction with water works the same way.  


Let's kill all the things and dump the bodies in the water!  

Yeah, about that... killing people underwater is less subtle than you may think, because the blood shows up in the water. We run actual fluid simulation and make the blood flow downstream.  


And that concludes today's update. We hope you've enjoyed it! If you have any questions or comments - feel free to leave them on our forum, and we'll be happy to answer!  

Hail to the kings!  



Non-game image sources:

Brandon Urey, Yannick Verrydt, and 106 more people like this update.


Only backers can post comments. Log In
    1. Carl on August 17, 2017

      Really interesting updates.

    2. Missing avatar

      DRvanR on August 13, 2017

      A very nice detailed post, and it shows wonderful progress! Loving this!

    3. Missing avatar

      Pedro Duarte on August 12, 2017

      One of the most important factors to me when it comes to a game is the water effects. If your going to put in water efects than by golly u do it right. love this update

    4. Kahuna on August 11, 2017

      I love this kind of update, so interesting!

    5. Kevin C on August 11, 2017

      Now I just want to sit and watch the rivers in this game...

    6. Mevy on August 11, 2017

      this looks amazing, very interesting post thanks.

    7. Missing avatar

      William Mawley-Mills on August 11, 2017

      That "dumping the bodies in the water" example only made me wonder what kind of options of choice one has for alignment. Partly because that sounded like something the an organized criminal syndicate would do... Which does suggest a party of CN characters.

      ... Which just leaves the question of what CG characters can/should do; given LG, LN, and NG are probably accounted for. (Well, that and the Evil alignments... But that's... Not going to be a typical play through.)

    8. Denis Habulinec on August 10, 2017

      This was a very interesting update! I know next to nothing about programming water into a game realistically, and this has shed some light onto it! Sounds like a great deal of work and patience!

    9. Andrew Tuckett on August 10, 2017

      I wonder if bodies of slain enemies will float downriver?

    10. alcaray on August 10, 2017

      Water, grass, hair, weather effects seem to cause a big chunk of the problems that people have with games out-of-the-box. But, if the game is otherwise great, I'd be just as happy to turn off the troubling features (if the developers provided such switches). And I deplore the loss of programming resources to areas of the game that I find essential.

      I guess that everyone has their own idea of what the prize is, in the phrase, "Keep your eyes on the prize." In my case, water effects are no where near the prize.

    11. euansmith
      on August 10, 2017

      Blimey, that is very impressive.

    12. Licktoren on August 10, 2017

      Wow, this gives some great insight into the level of detail your team is going to for the game! Looks great, With all the water details it makes me hope we can do some sort of water battles or something!

    13. Magnus Bergqvist
      on August 10, 2017

      Looks awesome. Would it be nice if the effects were toggleable if you have a lower-end machine.

    14. Missing avatar

      Tindomerel on August 10, 2017

      Blood looks awesome in the water. Great!

    15. Joe Pacelli on August 10, 2017

      I'm envious of you. I'm also a software engineer but I do more of the database side and backend development. SQL Server and C# windows services. But I've always was interested in the game aspect of development and love what you all are doing.

      Keep up the great work.

    16. Rob Leveille on August 10, 2017

      Personally, I don't care how realistic the water works. I care how fun the game is.

      please don't make it so that this only plays in high-end computers.

    17. Bernie Monsanto on August 10, 2017

      I have often said the difference between good art and great art is the details.