{"id":51,"date":"2014-01-13T09:04:00","date_gmt":"2014-01-13T09:04:00","guid":{"rendered":"http:\/\/oneiricworlds.com\/en\/index.php\/2014\/01\/13\/waterfalls-and-sleeping-water\/"},"modified":"2014-01-13T09:04:00","modified_gmt":"2014-01-13T09:04:00","slug":"waterfalls-and-sleeping-water","status":"publish","type":"post","link":"https:\/\/oneiricworlds.com\/en\/2014\/01\/waterfalls-and-sleeping-water\/","title":{"rendered":"Waterfalls and sleeping water"},"content":{"rendered":"<p>Hi there!<\/p>\n<p>I will just write a quick article on this week&#8217;s work: creating the appearance of waterfalls and water\/lakes which are not the main sea.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/1.bp.blogspot.com\/-lteLjUJ-4UQ\/UtOj95u0RWI\/AAAAAAAAHkI\/nE30l3MzaB0\/s1600\/20140109_155413.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/1.bp.blogspot.com\/-lteLjUJ-4UQ\/UtOj95u0RWI\/AAAAAAAAHkI\/nE30l3MzaB0\/s1600\/20140109_155413.png\" height=\"220\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>The final look of waterfalls.<\/i><\/div>\n<p>Indeed, I want a world with various (floating) islands and some waterfalls. Maybe you noticed it, but there is already water in the video game. I previously <a href=\"http:\/\/home.oneiricworlds.com\/2013\/06\/steven-seagull.html\">worked on the main sea <\/a>of the world, and it wasn&#8217;t that easy to set up a look that I found OK. I finally chose to have a purely reflective water. The big problem is that displaying the main sea is quite computationally expensive.<\/p>\n<p>If I want to add other water planes (for example a lake on an island) or waterfalls, I can&#8217;t use the exact same approach because it will seriously slow down the game. Plus, for a simple plane, computing the reflection is &#8220;quite&#8221; straight-forward, but for complex shapes (a waterfall), the computations are more difficult and the graphical pipeline of the GPU is not well suited for such a task. So I have to use a work around if I don&#8217;t want to spend days developing an incredibly complex material that nobody will notice anyway.<\/p>\n<p>I finally choose a combination of various classical techniques used in video game\/real-time applications&#8230;<\/p>\n<p><\/p>\n<h3>I &#8211; Environment(cube) map<\/h3>\n<p>An environment map is some kind of &#8220;spherical&#8221; texture (actually it&#8217;s computed from the faces of a cube) that is applied on a mesh according to its normals. The idea is to &#8220;fake&#8221; the reflection of the environment on the object. <\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/2.bp.blogspot.com\/-Iyblp9g5R-E\/UtOdHYzshaI\/AAAAAAAAHjU\/j-gTihPvsfk\/s1600\/20140112_material1.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/2.bp.blogspot.com\/-Iyblp9g5R-E\/UtOdHYzshaI\/AAAAAAAAHjU\/j-gTihPvsfk\/s1600\/20140112_material1.jpg\" height=\"251\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>The environment map fakes a perfect reflection of the environment. This works well with a sphere, but it&#8217;s less convincing with other mesh primitives. <\/i><\/div>\n<p>Technically, it is possible to compute such a normal map in real-time to obtain a &#8220;true&#8221; reflection of the environment. However, as usual, this is quite GPU-heavy (you have to make 6 renders of the scene to create the real-time reflection texture). Furthermore, even with real-time computed reflections, the mapping itselft is still a fake one, which won&#8217;t fool the careful viewer&#8217;s eye.<\/p>\n<p>Thus, I choose to use a pre-computed environment map: I simply use the cube map of the sky (see <a href=\"http:\/\/home.oneiricworlds.com\/2013\/06\/skybox-and-art-improvement.html\">this post<\/a> for more details).<\/p>\n<p><\/p>\n<h3>II &#8211; Moving normal maps to create waves<\/h3>\n<p>Then, to break the perfect flatness of the water, I add 2 normal maps that moves at 2 different speeds. It creates a nice effect of moving waves. By the way, it&#8217;s the same trick that is used to create the waves on the main sea material.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/4.bp.blogspot.com\/-Hy4N9cwM5EY\/UtOdHZEipzI\/AAAAAAAAHjQ\/NCwkRDt2TO0\/s1600\/20140112_material2.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/4.bp.blogspot.com\/-Hy4N9cwM5EY\/UtOdHZEipzI\/AAAAAAAAHjQ\/NCwkRDt2TO0\/s1600\/20140112_material2.jpg\" height=\"251\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>&nbsp;The environment map with normal maps to simulate waves<\/i><\/div>\n<div style=\"text-align: center;\"><\/div>\n<div style=\"text-align: center;\"><\/div>\n<h3>III &#8211; Moving foam texture<\/h3>\n<p>This one is a simple classical moving texture added on top of the moving waves. To keep consistency with the rendering of the main sea, I use pure white for the foam, and I play with the alpha channel to modulate the visual impact.<\/p>\n<div style=\"clear: both; text-align: center;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/1.bp.blogspot.com\/-Cr3Cbfc9tfc\/UtOdHuc4DdI\/AAAAAAAAHjM\/1i6jj_TYvjI\/s1600\/20140112_material3.jpg\" height=\"251\" width=\"400\" \/> <\/div>\n<div style=\"text-align: center;\"><i>The white foam above the water.<\/i> <\/div>\n<div style=\"text-align: center;\"><\/div>\n<div style=\"text-align: center;\"><\/div>\n<h3>IV &#8211; Distortion of the foam texture<\/h3>\n<p>Because I want the foam not to be straight on this moving water, I add distortion to it by altering the texture coordinates with a noise texture (actually, this is the wave normal map with a different scale and speed).<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/2.bp.blogspot.com\/-awHPh8o2BFU\/UtOdH1545KI\/AAAAAAAAHjo\/Wl8NeDUYsNs\/s1600\/20140112_material4.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/2.bp.blogspot.com\/-awHPh8o2BFU\/UtOdH1545KI\/AAAAAAAAHjo\/Wl8NeDUYsNs\/s1600\/20140112_material4.jpg\" height=\"251\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>Foam with distortion!<\/i><\/div>\n<h3 style=\"clear: both; text-align: left;\">V &#8211; Day time aware material<\/h3>\n<div style=\"clear: both; text-align: left;\"><\/div>\n<div style=\"clear: both; text-align: left;\">The final step is to make the material reacting to the day time. Indeed, the sky\/environment is evolving (there is a day\/night cycle in the game) and I can&#8217;t have a night reflection in full day, this totally breaks the visual integrity of the scene. So I need to carefully blend the day and night environment map of the sky according to the virtual time of the game.<\/div>\n<p><\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/2.bp.blogspot.com\/-sQFl7Oc-T9c\/UtOdId9AT0I\/AAAAAAAAHjk\/59Xrhc28CJA\/s1600\/20140112_material6.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/2.bp.blogspot.com\/-sQFl7Oc-T9c\/UtOdId9AT0I\/AAAAAAAAHjk\/59Xrhc28CJA\/s1600\/20140112_material6.jpg\" height=\"251\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>Day reflection<\/i><\/div>\n<p><\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/3.bp.blogspot.com\/-TbP4GZ3piVc\/UtOdI1FzI6I\/AAAAAAAAHjw\/tz56uBzPtGg\/s1600\/20140112_material7.jpg\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/-TbP4GZ3piVc\/UtOdI1FzI6I\/AAAAAAAAHjw\/tz56uBzPtGg\/s1600\/20140112_material7.jpg\" height=\"251\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>&nbsp;Noon reflection<\/i><\/div>\n<div style=\"text-align: center;\"><\/div>\n<div style=\"text-align: center;\"><\/div>\n<h3>VI &#8211; Tweaking and particles<\/h3>\n<p>The final difficulty is adjusting all the material parameters of this &#8220;fake&#8221; water, to match most closely the main sea water. Because the algorithms behind the rendering of these 2 water styles are different, it&#8217;s strictly impossible, but I have to minimize the visual gap.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/2.bp.blogspot.com\/-BEkyWF3Y_vk\/UtOmA8cD03I\/AAAAAAAAHkU\/XnPqCoFy5CE\/s1600\/20140113_092514.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/2.bp.blogspot.com\/-BEkyWF3Y_vk\/UtOmA8cD03I\/AAAAAAAAHkU\/XnPqCoFy5CE\/s1600\/20140113_092514.png\" height=\"262\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>The main sea water material with real reflections. <\/i><\/div>\n<p><\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/3.bp.blogspot.com\/-B13CiEWPuRk\/UtOmBlE9j1I\/AAAAAAAAHkc\/MCDQ0rytIog\/s1600\/20140113_092534.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/-B13CiEWPuRk\/UtOmBlE9j1I\/AAAAAAAAHkc\/MCDQ0rytIog\/s1600\/20140113_092534.png\" height=\"262\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>The lake water material with fake reflections.<\/i><\/div>\n<p>As you can see on the above screenshots, for lake and other &#8220;sleeping&#8221; water planes, the differences with the main sea water can be obvious according to the camera viewing direction. But for the moment, I can&#8217;t do better.<\/p>\n<p>Maybe, later, I&#8217;ll modify the main water rendering shader to make it structurally closer to the fake water one, so that it can be easier to have a similar look (without losing real reflection on the main water of course). Or maybe I&#8217;ll find anoter way to have real-time reflections on lakes too without hurting too much the GPU (I already tried&#8230; but failed&#8230; for now).<\/p>\n<p>For waterfalls however, this fake water is quite OK, I guess because all waterfalls have the same material. By the way, I must add particles to create the splashing waters.<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/3.bp.blogspot.com\/-HmDP8zm1r4w\/UtOmcc_3OyI\/AAAAAAAAHkk\/LieUKP1WU_Y\/s1600\/20140113_092556.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img loading=\"lazy\" decoding=\"async\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/-HmDP8zm1r4w\/UtOmcc_3OyI\/AAAAAAAAHkk\/LieUKP1WU_Y\/s1600\/20140113_092556.png\" height=\"262\" width=\"400\" \/><\/a><\/div>\n<div style=\"text-align: center;\"><i>A waterfall with splashing water particles.<\/i><\/div>\n<p>So, that&#8217;s all for today! I hope this detailed water material post was interesting for you&#8230;<\/p>\n<p>And, I didn&#8217;t talk about it in this post, but I made a loooot of bug fixes thanks to all of you guys who tested the last demo. Thanks for your amazing feedback! I plan to release a new demo with lots of major fixes at the end of the week, so that new testers can find new bugs \ud83d\ude09<\/p>\n<p>See you! Peace!<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi there! I will just write a quick article on this week&#8217;s work: creating the appearance of waterfalls and water\/lakes which are not the main sea. The final look of waterfalls. Indeed, I want a world with various (floating) islands and some waterfalls. Maybe you noticed it, but there is already water in the video [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":222,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-51","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/posts\/51","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/comments?post=51"}],"version-history":[{"count":0,"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/posts\/51\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/media\/222"}],"wp:attachment":[{"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/media?parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/categories?post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oneiricworlds.com\/en\/wp-json\/wp\/v2\/tags?post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}