Author Topic: How to add water to your meshes (advanced)  (Read 1091 times)

0 Members and 1 Guest are viewing this topic.

Offline Bartender

  • Coding Magician
  • Modders
  • Trader
  • *****
  • Posts: 169
How to add water to your meshes (advanced)
« on: April 30, 2017, 03:48:40 AM »
http://i.imgur.com/qTaUnmT.png
How to add water to your meshes (advanced)


Introduction
As you may have read in my Natural Diversity topic, I have recently discovered that it is possible to have parts of meshes appear with the same properties as the water in the game. I did this by adapting the existing material that is used for the water in river and lakes, and applying it to my mesh. In this brief tutorial, I will explain how to use this water appearance for your own meshes. While I used it in combination with a terrain alteration to create a naturally looking pond, it may be used for a great many other things, like fountains, canals or pools.

Disclaimer:
As I expect mainly experienced modders to be interested in utilizing this, I’m not going to explain the basics of how to create a mesh and have it show up in the game. There are other excellent tutorials that explain this in great detail.


Copyright Information
I am freely distributing the files I created to make this work, so that everyone can benefit from them. You are free to use these in your mods, just put an acknowledgement somewhere in the mod description ;).

Necessary Files
Just like any mesh, the Rivers and Lakes in banished get their look from referencing a specific Material file. Though the toolkit provides us with the Material files that are used for this, namely 'Material\River\RiverMaterial.rsc’ and ‘Material\Lake\LakeMaterial.rsc’ (which both use the ‘Material\River\RiverMaterial.srsl’ as a basis), using these original materials for some reason does not work for normal meshes. I have created an adaptation of these original files, so that the water Materials can be used to fit our needs. These files can be found in the attachment.

Unpack the zip and include everything in your *mymod* folder, so that the structure looks like this:
Code: [Select]
*mymod*\Material\Bartender\WaterMaterial.srsl
*mymod*\Material\Bartender\RiverMaterial.rsc
*mymod*\Material\Bartender\LakeMaterial.rsc
*mymod*\Material\Constants.srsl
*mymod*\Material\Lighting.srsl

Make sure that this structure doesn’t change, the files need to reference each other so if anything changes it will produce an error.

The mesh
Creating the mesh is probably the easiest modeling you’re ever going to do for Banished. All it needs is a horizontal plane, placed where you want the water to show up in the mesh. If your mesh has other parts that you don’t want turned into water, then make sure that this plane has its own unique material assigned to it. In my case, it is the only part of the mesh, so I’m using one material. For this example, I simply named the material ‘pond’.

For the UV maps, only the first channel matters for the water. I used to simple unwrap to create a map that is exactly square, just like the mesh. The UV mapping influences the movement of the water, so the best effect is achieved if the x/y proportions are the same as those of your mesh. The scale of the UV map influences the size and speed of the movement in your water. A big scale will result in very little movement, a tiny scale will result in huge waves. Depending on the size of your plane, you will need to play around with this in order to achieve the same size and speed as the natural water. The rotation of the UV map determines the direction of the movement.

http://i.imgur.com/kcs9Eds.png
How to add water to your meshes (advanced)


That’s it for the modeling. There’s no need for textures associated with the water, as it uses the ones already supplied by the game. It also completely ignores any AO’s you might use for other parts of the mesh.

The Material file
To get the mesh to show up as water in the game, we need to direct it to the right material. This is done as with any material, with a properly named .rsc file in the MaterialInstance folder. In my example, this is the Pond.rsc file, placed in *mymod*\Buildings\Pond\MaterialInstance. It looks like this:

Code: [Select]
MaterialInstance resource
{
Material _material = "Material\Bartender\LakeMaterial.rsc"; //For river, change to “Material\Bartender\RiverMaterial.rsc”;
Texture _textures
[
{
String _name = "water";
ImageBuffer _texture = "Terrain\LakeWaterTexture.rsc"; //For river, change to “Terrain\RiverWaterTexture.rsc”;
}
{
String _name = "frame";
ImageBuffer _texture = "Terrain\RiverFrameCopyTexture.rsc";
}
{
String _name = "reflection";
ImageBuffer _texture = "Terrain\RiverReflect2Texture.rsc";
}
{
String _name = "highlight";
ImageBuffer _texture = "Terrain\RiverReflectTexture.rsc";
}

]
}

Since my pond is an isolated body of water, it uses the LakeMaterial.rsc, which creates calm and still water. If you wish to use the RiverMaterial.rsc, which creates water moving in a specific direction, change the file in the places described in the comments.

That’s all there is to it! Now if you place it in the game, this part of your mesh will show up as water.

There are a few final things I want to note:
-   The colour and sky reflection of the water in rivers and lakes are largely created by an interaction with the underlying lowered terrain. Without this the water will look transparent, though the movement is still visible, and it still reflects nearby objects. In these cases some realism can be created by changing the colouring of the textures underneath the water, for example by making them slightly darker than the rest of the mesh.
-   The first time you load the mod in the toolkit with the new material files, it may give an error upon closing the application. This does no harm whatsoever, and doesn’t happen anymore once the mod is packaged.
-   It is possible to change other properties of the water by altering the WaterMaterial.srsl file, such as the speed of the movement. If you decide to make changes to this, please change the name of the folder from ‘Bartender’ to something else, to prevent your changes from affecting any other mods that use these files.
-   For an explanation of how to use this technique to make water go around a corner, see http://worldofbanished.com/index.php?topic=1671.msg32379#msg32379

If you have any questions or comments regarding this tutorial, please post them below.
« Last Edit: May 02, 2017, 05:44:58 AM by Bartender »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: How to add water to your meshes (advanced)
« Reply #1 on: April 30, 2017, 04:24:58 AM »
This is a great find.

Well done @Bartender this is phenomenal.

Never thought possible.

Online embx61

  • Modders
  • Banished Expert
  • *****
  • Posts: 1091
  • You are always on my mind, Forever in my heart
Re: How to add water to your meshes (advanced)
« Reply #2 on: April 30, 2017, 04:26:50 AM »
Thank you so much for this @Bartender. :)

Unbelievable what all becomes possible with this HUGE discovery.
Later today if I get bored with working on my Glassworks I play a bit with your files and of course screw it all up :)
My beloved Kathy
As you were you will always be
Treasured forever in my memory

Offline RedKetchup

  • Champion
  • Banished Expert
  • *****
  • Posts: 6985
Re: How to add water to your meshes (advanced)
« Reply #3 on: April 30, 2017, 04:35:25 AM »
I personally want to THANKS YOU ALOT for your awesome discovery and your awesome tutorial !
It will benefit all the moddling community ! And it will benefit all the players around the world :)

i didnt played yet with your tuto and your files yet .... but gonna check that tonight  (after the bed if i succeed to sleep lolz)

Thanks YOU, @Bartender  :) You are a magician !
> > > Support Mods Creation developments with Paypal Donations < < <
Click here to PayPal Donate.

Offline kid1293

  • Modders
  • Banished Expert
  • *****
  • Posts: 1690
  • Never confuse movement with progress
Re: How to add water to your meshes (advanced)
« Reply #4 on: April 30, 2017, 04:59:02 AM »
Thank you!

This gives us hope that other unsolvable tasks may be done.
Very nice!

Offline RedKetchup

  • Champion
  • Banished Expert
  • *****
  • Posts: 6985
Re: How to add water to your meshes (advanced)
« Reply #5 on: April 30, 2017, 06:20:51 AM »
WOAH !!!!!!  ;D  ;D  ;D
> > > Support Mods Creation developments with Paypal Donations < < <
Click here to PayPal Donate.

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: How to add water to your meshes (advanced)
« Reply #6 on: April 30, 2017, 06:35:08 AM »
Brilliant @RedKetchup

Offline RedKetchup

  • Champion
  • Banished Expert
  • *****
  • Posts: 6985
Re: How to add water to your meshes (advanced)
« Reply #7 on: April 30, 2017, 06:39:56 AM »
thats so awesome ! and so exciting   :D
> > > Support Mods Creation developments with Paypal Donations < < <
Click here to PayPal Donate.

Offline RedKetchup

  • Champion
  • Banished Expert
  • *****
  • Posts: 6985
Re: How to add water to your meshes (advanced)
« Reply #8 on: April 30, 2017, 06:48:31 AM »
thats so awesome ! and so exciting   :D

this is so exciting ... tonight, i put the roman empire model on pause .... and i ll do all my canals :)
THANKS AGAIN @Bartender  :)
> > > Support Mods Creation developments with Paypal Donations < < <
Click here to PayPal Donate.

Offline Bartender

  • Coding Magician
  • Modders
  • Trader
  • *****
  • Posts: 169
Re: How to add water to your meshes (advanced)
« Reply #9 on: April 30, 2017, 07:51:40 AM »
Oh wow, they look amazing ;D! I can't wait to try those.

You're all very welcome! I'm rather excited to see what wonderful new things are going to be produced because of this.

Offline QueryEverything

  • Advisor
  • Banished Expert
  • *****
  • Posts: 1041
Re: How to add water to your meshes (advanced)
« Reply #10 on: April 30, 2017, 07:57:45 AM »
Oh wow @RedKetchup :)  :D
~ QE, I query because I like learning new things. 

Banished pinterest & Banished mod ideas
(Gently) Please: if you download mods please rate them, this helps & encourages the modders. :)

Offline RedKetchup

  • Champion
  • Banished Expert
  • *****
  • Posts: 6985
Re: How to add water to your meshes (advanced)
« Reply #11 on: April 30, 2017, 07:59:38 AM »
Oh wow, they look amazing ;D! I can't wait to try those.

You're all very welcome! I'm rather excited to see what wonderful new things are going to be produced because of this.


indeed !!!!!!!!!!!
 :D

if i want to make it flow faster.... and / or if i want to make bigger ripples : what do i need to change ? (if i dont want to change the size of the plane ?)


and....
btw... with your tests .... did you succeeded to make it fall 90 degres ? vertically ?
> > > Support Mods Creation developments with Paypal Donations < < <
Click here to PayPal Donate.

Offline Bartender

  • Coding Magician
  • Modders
  • Trader
  • *****
  • Posts: 169
Re: How to add water to your meshes (advanced)
« Reply #12 on: April 30, 2017, 08:54:11 AM »
You can scale down the square on the UV map to make it flow faster and have bigger ripples at the same time :). If you do that it basically draws a smaller part of the texture instead of the whole, resulting in a more 'zoomed in' image.

It does work if you move the plane into vertical position, though then you also get the issue that it is just transparent. I guess with the right flowing speed and the right background, it would be possible to make a realistically looking waterfall though :). The only thing I noticed is that the reflections are a bit weird in that case; it just reflects stuff as if it was horizontal no matter what the actual orientation is. Now if I get really bold I could try to improve it so that it would take the orientation into account, but I'm really not sure if that's possible.


Offline RedKetchup

  • Champion
  • Banished Expert
  • *****
  • Posts: 6985
Re: How to add water to your meshes (advanced)
« Reply #13 on: April 30, 2017, 02:59:08 PM »
imagine .... real fountains !

 :P ;D :D
> > > Support Mods Creation developments with Paypal Donations < < <
Click here to PayPal Donate.

Offline RedKetchup

  • Champion
  • Banished Expert
  • *****
  • Posts: 6985
Re: How to add water to your meshes (advanced)
« Reply #14 on: May 01, 2017, 05:29:21 AM »
well.... not easy to make the water turn in a corner  :P  ^^
> > > Support Mods Creation developments with Paypal Donations < < <
Click here to PayPal Donate.