Share this project

Done

Share this project

Done
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
105 likes

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!  

Density  

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!  

Owlcats  

 
 

Non-game image sources: https://collections.yandex.ru/card/570508316635180020da4ed9/  
http://zapal.ru/pivo-s-pogruzheniem/

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

Comments

Only backers can post comments. Log In
    1. Missing avatar

      DRvanR 4 days ago

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

    2. Missing avatar

      Pedro Duarte 5 days ago

      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

    3. Kahuna 6 days ago

      I love this kind of update, so interesting!

    4. Kevin Curow 6 days ago

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

    5. Limpan 6 days ago

      this looks amazing, very interesting post thanks.

    6. Missing avatar

      William Mawley-Mills 6 days ago

      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.)

    7. Denis Habulinec 6 days ago

      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!

    8. Andrew Tuckett 7 days ago

      I wonder if bodies of slain enemies will float downriver?

    9. alcaray 7 days ago

      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.

    10. euansmith
      Superbacker
      7 days ago

      Blimey, that is very impressive.

    11. Licktoren 7 days ago

      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!

    12. Magnus Bergqvist
      Superbacker
      7 days ago

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

    13. Missing avatar

      Tindomerel 7 days ago

      Blood looks awesome in the water. Great!

    14. Joe Pacelli 7 days ago

      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.

    15. Rob Leveille 7 days ago

      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.

    16. Bernie Monsanto 7 days ago

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