World of Banished

MODS Garage => Tutorials => Topic started by: Bartender on April 30, 2017, 03:48:40 AM

Title: How to add water to your meshes (advanced)
Post by: Bartender on April 30, 2017, 03:48:40 AM
(http://i.imgur.com/qTaUnmT.png)

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:
*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)

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:

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 (http://worldofbanished.com/index.php?topic=1671.msg32379#msg32379)

If you have any questions or comments regarding this tutorial, please post them below.
Title: Re: How to add water to your meshes (advanced)
Post by: Discrepancy on April 30, 2017, 04:24:58 AM
This is a great find.

Well done @Bartender this is phenomenal.

Never thought possible.
Title: Re: How to add water to your meshes (advanced)
Post by: embx61 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 :)
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup 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 !
Title: Re: How to add water to your meshes (advanced)
Post by: kid1293 on April 30, 2017, 04:59:02 AM
Thank you!

This gives us hope that other unsolvable tasks may be done.
Very nice!
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on April 30, 2017, 06:20:51 AM
WOAH !!!!!!  ;D  ;D  ;D
Title: Re: How to add water to your meshes (advanced)
Post by: Discrepancy on April 30, 2017, 06:35:08 AM
Brilliant @RedKetchup
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on April 30, 2017, 06:39:56 AM
thats so awesome ! and so exciting   :D
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on April 30, 2017, 06:48:31 AM
Quote from: RedKetchup on April 30, 2017, 06:39:56 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  :)
Title: Re: How to add water to your meshes (advanced)
Post by: Bartender 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.
Title: Re: How to add water to your meshes (advanced)
Post by: QueryEverything on April 30, 2017, 07:57:45 AM
Oh wow @RedKetchup :)  :D
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on April 30, 2017, 07:59:38 AM
Quote from: Bartender 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.


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 ?
Title: Re: How to add water to your meshes (advanced)
Post by: Bartender 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.

Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on April 30, 2017, 02:59:08 PM
imagine .... real fountains !

:P ;D :D
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 01, 2017, 05:29:21 AM
well.... not easy to make the water turn in a corner  :P  ^^
Title: Re: How to add water to your meshes (advanced)
Post by: Bartender on May 01, 2017, 06:54:38 AM
@RedKetchup  I was just struggling with that as well :P. I've found a way that works though :).

The trick is to adapt the mesh to make a turn, but to leave the UV channel straight. I'll show what I did:

I first separated my plane into several strokes (Here I did a few, but in the end it turned out that I needed much more. I subdivided them later). Make sure that the UV channel looks exactly the same (we're going to leave it that way).
(http://i.imgur.com/5U39u1r.png)

Then I moved all the vertices on the left side of the plane to the same position, at the bottom of the square.
(http://i.imgur.com/055wHaK.png)

After that I rotated the vertices on the right side 45 degrees, and moved and scaled them so that they form the long side of the triangle and that there's a 90 degrees angle in the lower left corner.
(http://i.imgur.com/48lTnxZ.png)

Then I moved the vertices of the long side around to make it look like a nice quarter circle.
(http://i.imgur.com/JU7RbcQ.png)

Here I tested it, and realised that it was not detailed enough; I could see clear edges in the water. So I used the option subdivide (I guess 3dsMax has a similar function?) to cut the triangles into multiple smaller ones. I had to increase the amount of triangles by a factor 3 (subdivide 2 times), resulting in a total of 27. In Blender this option automatically updates the UV map while still leaving it straight.
(http://i.imgur.com/ElY8mJ6.png)

Then this is the result :)
(http://i.imgur.com/7ptjScj.jpg)

Let me know if it works!
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 01, 2017, 07:18:08 AM
that was  kinda what i did but yeah i was seeing big edges in the water....
but i didnt re-subdivided again. i ll test again tonight but with a subdiv of 3 on top of it.


thanks you for your tests :)
will give news back tonight
Title: Re: How to add water to your meshes (advanced)
Post by: Necora on May 01, 2017, 05:01:26 PM
That is pretty darn cool. Although I guess the riffle stuff is pretty redundant now. Hmm.
Title: Re: How to add water to your meshes (advanced)
Post by: QueryEverything on May 01, 2017, 05:06:35 PM
Quote from: Necora on May 01, 2017, 05:01:26 PM
That is pretty darn cool. Although I guess the riffle stuff is pretty redundant now. Hmm.

You bite your tongue!  pffffttttt Had to pounce this because many people will still use the Riffles, I see that there is definitely still a place for the mod - a very controlled placement is the first example, what I see as how I would use the above and yours is:
Create the larger area (like I was trying to achieve with the terraform by Kral) then fill it in with the Riffle mod, the nuances to it, and all the little riffles on the edges etc.

Definitely not redundant at all.    After all, I am still determined to get a backyard pond fishing spot made and we're 95% there now :D :D :D
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 01, 2017, 09:35:13 PM
have riffles just below the water level and having see it moving cause the river game particles can be very cool, much more cooler than before :)
Title: Re: How to add water to your meshes (advanced)
Post by: despo_20 on May 02, 2017, 03:06:19 AM
Your riffles are amazing Necora! Close to the wheels of mills or near the rocks add a more realistic look!

About the little streams instead, can this new discovery be used to implement reflective water?
Is there a minimum size limit?
Title: Re: How to add water to your meshes (advanced)
Post by: Paeng on May 02, 2017, 04:46:59 AM
Quote from: Necora on May 01, 2017, 05:01:26 PMI guess the riffle stuff is pretty redundant now.

Nah, there's always use for surface water... and the turbulences are still way cool (sorry, can't get used to the term "riffles")...  :)
Title: Re: How to add water to your meshes (advanced)
Post by: Bartender on May 02, 2017, 05:20:16 AM
I have to second this, your riffles are amazing @Necora ! It would be a shame to stop development on them.

I personally feel that combining your idea of putting meshes and particles in the water with being able to add water to our meshes actually creates a huge potential! Imagine actual flowing water rapids going downhill, with riffles in them and the foaming particles at the bottom.. that would look amazing.

I definitely think that you could try to apply this material to your small streams, I'd be curious to see how it would turn out :).

Meanwhile, I'm doing some research into the interaction between the OpaqueInWaterMaterial and this new material.. perhaps that one can be used to make parts of meshes that are under the water appear more realistic without needing to do complicated stuff with the textures :).
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 02, 2017, 05:25:36 AM
Quote from: Bartender on May 02, 2017, 05:20:16 AM
I have to second this, your riffles are amazing @Necora ! It would be a shame to stop development on them.

I personally feel that combining your idea of putting meshes and particles in the water with being able to add water to our meshes actually creates a huge potential! Imagine actual flowing water rapids going downhill, with riffles in them and the foaming particles at the bottom.. that would look amazing.

I definitely think that you could try to apply this material to your small streams, I'd be curious to see how it would turn out :).

Meanwhile, I'm doing some research into the interaction between the OpaqueInWaterMaterial and this new material.. perhaps that one can be used to make parts of meshes that are under the water appear more realistic without needing to do complicated stuff with the textures :).


i second that ! @Necora
riffles just below the water will make your riffles look amazing and really moving !

Title: Re: How to add water to your meshes (advanced)
Post by: despo_20 on May 02, 2017, 05:33:13 AM
It seems that the quote feature of this site doesn't work on my browser... but I totally agree with Bartender and Ketchup.
"Apply this material to your small streams" and "place the riffles just below the water" could give great results ;)
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 02, 2017, 05:35:13 AM
Quote from: despo_20 on May 02, 2017, 05:33:13 AM
It seems that the quote feature of this site doesn't work on my browser... but I totally agree with Bartender and Ketchup.
"Apply this material to your small streams" and "place the riffles just below the water" could give great results ;)

oh it will work when you ll get more posts ^^ at 3 posts or 5 ... i dont remember exactly the number ^^
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 02, 2017, 05:37:42 AM
Quote from: despo_20 on May 02, 2017, 03:06:19 AM
About the little streams instead, can this new discovery be used to implement reflective water?
Is there a minimum size limit?

i dont fully understand the question .... but i dont think there is a limit size... it has the size of your plane you put in your mesh .... if you make a plane of 800x800 tiles.... it will be that big

if you make a "ghosted" plane as big as a small, medium, large map and since it is ghosted, you can build and live with it like if it never existed....
and hidden under ground at minus level -0,75 underground...


every time you will "dig" somewhere in the map, there will always be some water appear wherever you dig ^^
Title: Re: How to add water to your meshes (advanced)
Post by: embx61 on May 02, 2017, 06:00:16 AM
Quoteoh it will work when you ll get more posts ^^ at 3 posts or 5 ... i dont remember exactly the number ^^

quote link/button ain't working for me either.
Not a big deal as I just copy the text I want to quote and type the quote BB code myself around it.
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 02, 2017, 06:04:09 AM
Quote from: embx61 on May 02, 2017, 06:00:16 AM
Quoteoh it will work when you ll get more posts ^^ at 3 posts or 5 ... i dont remember exactly the number ^^

quote link/button ain't working for me either.
Not a big deal as I just copy the text I want to quote and type the quote BB code myself around it.

really ?

and if you "reply" an open your box you type in....
scroll down after and click "insert quote" of someone ? doesnt work neither ?

are you using the default forum "appearance" "theme" or 1 of the dozens of theme provided ? (forum profile => look and layout thing)
Title: Re: How to add water to your meshes (advanced)
Post by: embx61 on May 02, 2017, 06:25:07 AM
Quote from: RedKetchup on May 02, 2017, 06:04:09 AM
Quote from: embx61 on May 02, 2017, 06:00:16 AM
Quoteoh it will work when you ll get more posts ^^ at 3 posts or 5 ... i dont remember exactly the number ^^

quote link/button ain't working for me either.
Not a big deal as I just copy the text I want to quote and type the quote BB code myself around it.

really ?

and if you "reply" an open your box you type in....
scroll down after and click "insert quote" of someone ? doesnt work neither ?

are you using the default forum "appearance" "theme" or 1 of the dozens of theme provided ? (forum profile => look and layout thing)

Yeah, that works. ^^ :) Never thought about that one.

I just use standard Theme. I never changed it at least.
Title: Re: How to add water to your meshes (advanced)
Post by: QueryEverything on May 02, 2017, 07:05:09 AM
Quote from: embx61 on May 02, 2017, 06:25:07 AM
Quote from: RedKetchup on May 02, 2017, 06:04:09 AM
Quote from: embx61 on May 02, 2017, 06:00:16 AM
Quoteoh it will work when you ll get more posts ^^ at 3 posts or 5 ... i dont remember exactly the number ^^

quote link/button ain't working for me either.
Not a big deal as I just copy the text I want to quote and type the quote BB code myself around it.

really ?

and if you "reply" an open your box you type in....
scroll down after and click "insert quote" of someone ? doesnt work neither ?

are you using the default forum "appearance" "theme" or 1 of the dozens of theme provided ? (forum profile => look and layout thing)

Yeah, that works. ^^ :) Never thought about that one.

I just use standard Theme. I never changed it at least.

I have found that if you use the quick reply you don't get the options, you need to be in the 'preview' screen that will have the link options as well as others :) 

It may not be the case for you, but that's where I found it for me. 
I am using a custom theme, but it worked as well in the forum basic theme too.
There is a setting in your Profile Settings about whether or not you want to see the Quick Reply box.  That may affect you.  But, it could also be a 'theme' thing, not sure. :(
Title: Re: How to add water to your meshes (advanced)
Post by: despo_20 on May 02, 2017, 08:41:53 AM
Quote from: QueryEverything on May 02, 2017, 07:05:09 AM
There is a setting in your Profile Settings about whether or not you want to see the Quick Reply box.  That may affect you.
Thank you Query!
It works for me  ;)
Title: Re: How to add water to your meshes (advanced)
Post by: despo_20 on May 02, 2017, 08:45:54 AM
Quote from: RedKetchup on May 02, 2017, 05:37:42 AM
i dont fully understand the question .... but i dont think there is a limit size... it has the size of your plane you put in your mesh ....
I wondered what the result could be by applying that water material to a 1x1 square. If it looks good or not.
I haven't done any testing with it.
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 02, 2017, 09:14:19 AM
Quote from: despo_20 on May 02, 2017, 08:45:54 AM
Quote from: RedKetchup on May 02, 2017, 05:37:42 AM
i dont fully understand the question .... but i dont think there is a limit size... it has the size of your plane you put in your mesh ....
I wondered what the result could be by applying that water material to a 1x1 square. If it looks good or not.
I haven't done any testing with it.

oh yes you can apply to a 1x1 :) look as good as 10x10. but if you put 1x1 side od another 1x1 .... youll see the thin line depending the angle you watch it.
aka my nmt canals
Title: Re: How to add water to your meshes (advanced)
Post by: brads3 on May 02, 2017, 10:36:26 AM
has anyone experimented  to build a new terrain raising or lowering shovel mod that can make rounded banked round holes instead of the square diggouts we have now? if so how bout hills and how tall they can be? if we had a tool to dig our own lakes then it would be possable to make a large water mesh that covers the entire maps. we could then create our own maps.
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 02, 2017, 10:56:59 AM
about rounded holes instead of suare... i am not sure, i really wish to know how and if it is possible.

about dig your own lakes :
1. i am not sure but i created a 200x200 water plane. but in game it is really not as 200x200. like if there is a limitation to 50x50 or 60x60 .. not sure.
2. you need to know the water has not any coloration , totally transparent. to get the blue effect, it comes from digging enough down to get the "blue" ground which kinda reflect on the water.

on the screenshots below you can see ontop of the river, the difference, it is not 200x200. you see it starting and see it ending.
on screenshot 2, you see the claypit and there is water there, hard to see on a picture cause the water is pure clear. the only thing in game you see is ripples and the wood planks are moving cause the water.

of course cause the plane is big, the water is very quiet and more hard to see. i would rather need to put more planes side by side instead of 1 giant plane in order to get thin ripples
Title: Re: How to add water to your meshes (advanced)
Post by: Bartender on May 09, 2017, 11:04:38 AM
Just a little update; I ran some tests with the OpaqueInWaterMaterial, to see its behaviour. Using it for the parts of meshes that are supposed to be underwater fixes the problem with the 'clear' water, but the default material only works properly if the water is at the natural height (-0.75). I have found a way to reliably adapt it to give the right results at any desirable Z-level, so I will update the tutorial soon to include this.
Title: Re: How to add water to your meshes (advanced)
Post by: RedKetchup on May 09, 2017, 01:29:46 PM
ok :)

i didnt used it yet though :)
Title: Re: How to add water to your meshes (advanced)
Post by: angainor88 on January 20, 2019, 06:15:09 PM
Hey so I know Bartender isn't around much these days, but I am having trouble getting the water to work. Would anyone be willing to look at my files? Thanks!
Title: Re: How to add water to your meshes (advanced)
Post by: Discrepancy on January 20, 2019, 06:53:27 PM
Sure I will :) send me a PM.
Title: Re: How to add water to your meshes (advanced)
Post by: purringcat on January 23, 2019, 02:06:02 PM
RK    I love the natural looking canal