{"id":1789,"date":"2012-08-24T23:16:19","date_gmt":"2012-08-25T06:16:19","guid":{"rendered":"http:\/\/the-witness.net\/news\/?p=1789"},"modified":"2012-08-24T23:16:19","modified_gmt":"2012-08-25T06:16:19","slug":"regarding-water","status":"publish","type":"post","link":"http:\/\/the-witness.net\/news\/2012\/08\/regarding-water\/","title":{"rendered":"Regarding Water"},"content":{"rendered":"<p><em>(Here's an internal email that Ignacio sent today that may provide some flavor on what we're doing lately.)<\/em><\/p>\n<p>From: Ignacio Casta\u00f1o<br \/>\nDate: 24 August 2012<\/p>\n<p>I just checked in a few changes to the water shader. Note that this is still work in progress, there are some artifacts and unfinished features.<\/p>\n<p>From the art point of view, the main change is that there's now a water_color_map and a water_flow_map that you can use to change the behavior of the shader.<\/p>\n<p>The RGB channels of the color map control the water extinction color and the alpha controls the opacity factor. The previous underwater shading model was simply wrong, the new one works nicely and is easy to tweak. Note that I assume the water color changes very smoothly, avoid sharp color changes!<\/p>\n<p>The flow_map is intended to contain additional water attributes. Right now it's only used for the stillness, but I will certainly add more in the future.<\/p>\n<p>You will also notice that the shoreline now also has a foam layer:<\/p>\n<p><a href=\"http:\/\/the-witness.net\/news\/wp-content\/uploads\/2012\/08\/a.png\"><img src=\"http:\/\/the-witness.net\/news\/wp-content\/uploads\/2012\/08\/a-512x287.png\" alt=\"\" title=\"a\" width=\"512\" height=\"287\" class=\"aligncenter size-large wp-image-1791\" \/><\/a><\/p>\n<p>The way it's computed is by comparing the screenspace depth difference. This is not very correct, it looks OK from some angles, but it breaks badly when the underwater geometry has screen-space depth discontinuities:<\/p>\n<p><a href=\"http:\/\/the-witness.net\/news\/wp-content\/uploads\/2012\/08\/b.png\"><img src=\"http:\/\/the-witness.net\/news\/wp-content\/uploads\/2012\/08\/b-512x287.png\" alt=\"\" title=\"b\" width=\"512\" height=\"287\" class=\"aligncenter size-large wp-image-1792\" \/><\/a><\/p>\n<p>If the foam is a desirable feature, I'm considering modifying the print_map command to render a foam map, or maybe this is something that can be painted manually and added to the water_flow_map. One of my concerns is that this map may not have enough resolution. <\/p>\n<p>Just Cause 2 seems to use this method to render foam, but they apply a big screenspace distortion to hide the artifacts, I found it sickening when you stare at it closely...<\/p>\n<p>The way the water is shaded has also changed somewhat. First, I now approximate the specular exponent based on the position of the camera with respect to the water and the water roughness. Somewhat like the LEAN paper does, but assuming the roughness of the water is the same for the whole texture. Depending on the value of the exponent I either sample the mirrored reflection map, a filtered environment map, or blend between the two. My goal was to be able to use the mirrored reflection map only on a small subset of the lake entities. The physically based approach does not allow us to cull many, so I'll probably have to introduce some hacks. BTW, I'm doing all these work not just an optimization, but also so that we can use the light probe reflection model in the river and lakes inside the island, where the mirrored reflection map is not available.<\/p>\n<p>The main problem with the filtered environment map is that it does not take local reflections and occlusion from the environment into account. I have two ideas to work around this, one is to store an ambient occlusion map in the lightmaps, this may be a bit too smooth and will lack directional information. The other is to do screenspace raycasting of the depth buffer to decide whether the environment map is occluded or not.<\/p>\n<p>This is somewhat like what Crysis 2 does. Insomniac also uses a similar approach with just a single sample:<\/p>\n<p><a href=\"http:\/\/www.insomniacgames.com\/tech\/articles\/0409\/files\/water.pdf\" onclick=\"_gaq.push(['_trackEvent','download','http:\/\/www.insomniacgames.com\/tech\/articles\/0409\/files\/water.pdf']);\" >http:\/\/www.insomniacgames.com\/tech\/articles\/0409\/files\/water.pdf<\/a><\/p>\n<p>I'm hoping we can get away with a crude approximation too. I did a quick test, where the maths are not exactly right, with only 4 samples and no smoothing, and it was starting to look promising:<\/p>\n<p><a href=\"http:\/\/the-witness.net\/news\/wp-content\/uploads\/2012\/08\/c.png\"><img src=\"http:\/\/the-witness.net\/news\/wp-content\/uploads\/2012\/08\/c-512x287.png\" alt=\"\" title=\"c\" width=\"512\" height=\"287\" class=\"aligncenter size-large wp-image-1790\" \/><\/a><\/p>\n<p>This won't allow us to use the filtered environment maps closer to the camera, but if the screenspace raycasting works well, I'm thinking about using non-filtered environment maps in place of the mirrored reflection map, whenever those are not available.<\/p>\n<p>Finally, I've also been playing with Valve's water flow model, I have the basic implementation working, but I haven't yet been able to reproduce the workaround for the pulsing and repetition artifacts that Alex proposes.<\/p>\n<p><a href=\"http:\/\/www.valvesoftware.com\/publications\/2010\/siggraph2010_vlachos_waterflow.pdf\" onclick=\"_gaq.push(['_trackEvent','download','http:\/\/www.valvesoftware.com\/publications\/2010\/siggraph2010_vlachos_waterflow.pdf']);\" >http:\/\/www.valvesoftware.com\/publications\/2010\/siggraph2010_vlachos_waterflow.pdf<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Here&#8217;s an internal email that Ignacio sent today that may provide some flavor on what we&#8217;re doing lately.) From: Ignacio Casta\u00f1o Date: 24 August 2012 I just checked in a few changes to the water shader. Note that this is still work in progress, there are some artifacts and unfinished \u2026<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"http:\/\/the-witness.net\/news\/2012\/08\/regarding-water\/\">Continue reading<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"_links":{"self":[{"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/posts\/1789"}],"collection":[{"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/comments?post=1789"}],"version-history":[{"count":3,"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/posts\/1789\/revisions"}],"predecessor-version":[{"id":1795,"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/posts\/1789\/revisions\/1795"}],"wp:attachment":[{"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/media?parent=1789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/categories?post=1789"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/the-witness.net\/news\/wp-json\/wp\/v2\/tags?post=1789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}