<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Ocean scene</title>
<meta name="Microsoft Theme" content="zero 111">
</head>

<body background="_themes/zero/zertxtr.gif" bgcolor="#000000" text="#FFFFFF" link="#669966" vlink="#6699CC" alink="#999999"><!--mstheme--><font face="Arial, Arial, Helvetica">


<div align="center">
  
  <!--msthemeseparator--><p align="center"><img src="_themes/zero/zerrulea.gif" width="600" height="10"></p>
  
  <h1><!--mstheme--><font color="#6699CC"><i>Ocean 
  scene</i><!--mstheme--></font></h1>
  <!--msthemeseparator--><p align="center"><img src="_themes/zero/zerrulea.gif" width="600" height="10"></p>
  <p align="justify" style="line-height: 150%">&nbsp;</p>
  <p style="line-height: 150%"><img border="0" src="images/OceanSceneSmall.jpg" width="256" height="247"></p>
  <p align="justify" style="line-height: 150%">&nbsp;</p>
  <p align="justify" style="line-height: 150%">The <i>Ocean scene</i> is the 
  most complex effect in Meshuggah both visually/computationally and in terms of 
  using shaders. It's based on the papers <a href="#Ref1">[1]</a> and
  <a href="#Ref2">[2]</a> I came across lately. The provided sample shots there 
  looked promising enough to give it a shot. The implementation given here also 
  utilizes simplified equations from <a href="#Ref4">[4]</a> to determine the 
  view dependent color of water (pre-calculated and stored in a texture) and a 
  contrast-enhancement approach based on <a href="#Ref3">[3]</a> to further 
  improve the visual results when rendering ocean water.</p>
  <p align="justify" style="line-height: 150%">First and foremost a realistic 
  model for simulating and animating ocean water is necessary to generate an 
  appropriate mesh used for rendering. <a href="#Ref1">[1]</a> and
  <a href="#Ref2">[2]</a> - in greater detail - describe a statistical model 
  based on observations of the real sea. It has been successfully used 
  commercially in feature movies such as <i>Titanic</i> and <i>Waterworld</i>. 
  In this model a wave height field is decomposed into a set of sinus waves with 
  different amplitudes and phases. While the model itself provides 
  formulas to generate these amplitudes and phases an inverse Fast Fourier 
  Transformation (FFT)  converts them back into the spatial domain, thus 
  creating a wave height field required for building the ocean mesh. It also 
  allows calculating proper normals and displacement vectors for the height 
  field. These are used to shade the ocean mesh and to form choppy waves.</p>
  <p align="justify" style="line-height: 150%">A big advantage of this 
  particular model is that it produces an ocean height field which tiles 
  perfectly. In Meshuggah a 64 x 64 ocean height field is repeated four times 
  both horizontally and vertically to form a 256 x 256 ocean mesh.</p>
  <p align="justify" style="line-height: 150%">What contributes to the look of 
  the ocean surface? At first we need to determine the color of water. As 
  mentioned above we can take the equations provided in <a href="#Ref4">[4]</a> 
  and simplify them by treating the water surface as a flat plane. The result is an 
  equation only depending on the angle between the viewer and a point <i>p</i> 
  and its normal <i>n</i> on the ocean surface. It can be pre-calculated as a 1D 
  lookup texture containing greenish colors for angles of about 90 degrees 
  (viewer looks over wave) and dark blue colors for angles near or equal 
  to zero degree (viewer look straight on wave). In Meshuggah a simple linear 
  interpolation between the two colors using the angle between view vector and 
  wave normal as a blend factor has to be calculated instead since all available texture address operations 
  are already reserved for other purposes and an extra render pass was avoided 
  for performance reasons. Another factor which should be taken into account is 
  reflected skylight. To further enhance the detail of the water surface the 
  reflections will be per-pixel based meaning that the viewer will be able to 
  see little ripples on the water surface coming from a dynamically updated bump 
  map. In order not to overemphasize the reflections we also need to calculate 
  the fresnel term for the air to water case, multiply it to the reflected color 
  and add the result to the color of water. Otherwise reflections would make the water look more like 
  liquid metal instead. <a href="#Ref1">[1]</a> proposed the following 
  approximation:</p>
  <p align="justify" style="line-height: 150%">&nbsp;</p>
  <!--mstheme--></font><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" id="AutoNumber1">
    <tr>
      <td width="100%"><!--mstheme--><font face="Arial, Arial, Helvetica">
      <p style="line-height: 150%">
    <font face="Courier New" size="2">&#945; — cosine between eye and normal</font><!--mstheme--></font></td>
    </tr>
  </table><!--mstheme--><font face="Arial, Arial, Helvetica">
  <blockquote>
  <p style="line-height: 150%">
  <img border="0" src="images/OceanSceneFig1.gif" alt="Approximated fresnel term for air to water case" width="142" height="45"></p>
  </blockquote>
  <p align="justify" style="line-height: 150%">&nbsp;</p>
  <p align="justify" style="line-height: 150%">The fresnel term is a good 
  candidate for performing contrast enhancement. In <a href="#Ref3">[3]</a> an 
  exposure factor is multiplied to a high dynamic range texture map (16bit 
  information per color channel). In our case the fresnel term influences how 
  much reflected light should be added to the color of water for a given pixel. By 
  multiplying an exposure factor to the fresnel term we can increase the 
  intensity in areas of the ocean surface where sunlight is reflected while 
  leaving other areas relatively dark. Register combiners and final multipliers 
  are used in <a href="#Ref3">[3]</a> to overcome the limited range of [0..1] 
  for input colors and color math. We use pixel shader instruction and their 
  modifiers which are basically just an abstraction of both. In the vertex 
  shader we calculate the fresnel term and multiply it by a constant exposure 
  factor. In Meshuggah it is limited [0..4] to save pixel shader instructions as 
  we will see later. Since output color registers <i>oD0</i> and <i>oD1</i> will 
  clamp any value passed to them to [0..1] before they are interpolated during 
  rasterization and sent to the pixel shader we need to split up our <i>exposure 
  times fresnel</i> term. The fractional portion of it will be extracted and 
  copied to <i>oD1</i>. The integer portion is divided by the maximum exposure 
  value - 4 in our case- and copied to <i>oD0</i>. This way we avoid any 
  clamping of color values. In the pixel shader we combine the <i>exposure times 
  fresnel</i> term with the color from the environment map representing 
  reflected skylight. At first we multiply the color from the environment map by
  <i>v0</i> (corresponds to <i>oD0</i>) and use <i>_x4</i> instruction modifier 
  to even out the division which was performed when splitting up the <i>exposure times 
  fresnel</i> term in the vertex shader. Then we multiply the color from the 
  environment map by <i>v1</i> (corresponds to <i>oD1</i>) and add it to the 
  previous result. This yields in the desired <i><b>reflected skylight</b> times
  <b>fresnel term</b> times <b>exposure factor</b></i> color which is  added to the color of water.</p>
  <p align="justify" style="line-height: 150%">Doing per pixel reflections using 
  a bump map requires to setup a transformation matrix in the vertex shader 
  which is used to transform normals fetched from the bump map into world space 
  so that&nbsp; the view vector is reflected correctly. Normals in the bump map 
  are stored in a way that no transformation would be necessary if the ocean 
  surface would be a flat (x/z) plane. That is, they correspond with our&nbsp;(left-handed) world 
  coordinate system. Since our ocean mesh is based on a height 
  field which in turn is based on a rectangular grid generating the 
  transformation matrix is easy. It's formed by three normalized (!) vectors <i>x</i>, <i>y</i> and <i>
  z</i> which are copied into three consecutive output texture registers (namely
  <i>oT1 - oT3</i> as <i>oT0</i> is reserved for bump map texture coordinates). </p>
  <p align="justify" style="line-height: 150%">&nbsp;</p>
  <p style="line-height: 150%">
  <img border="0" src="images/OceanSceneFig2.gif" alt="Bump map normal transformation matrix" width="224" height="104"></p>
  <p align="justify" style="line-height: 150%">&nbsp;</p>
  <p align="justify" style="line-height: 150%">During rasterization the pixel 
  shader receives an interpolated version of these three vectors representing a 
  per pixel transformation matrix to transform the bump map normal from texture 
  into world space. To create and update the bump map 
  every frame normals from our current ocean height field can be used. Since 
  these normals already represent an ocean surface they can be used to model 
  surface detail  at a lower scale as well. Therefore the bump map is tiled 
  multiple times over the ocean mesh.</p>
  <p align="justify" style="line-height: 150%">As a last note a curvature is applied 
  to the ocean mesh in the vertex 
  shader. It's based on the x/z distance of each ocean mesh vertex to the 
  viewer's current position.</p>
  <p align="justify" style="line-height: 150%">&nbsp;</p>
  <h3 style="line-height: 150%"><!--mstheme--><font color="#6699CC">References<!--mstheme--></font></h3>
  <!--mstheme--></font><!--msthemelist--><table border="0" cellpadding="0" cellspacing="0" width="100%">
    <!--msthemelist--><tr><td valign="baseline" width="42"><img src="_themes/zero/zerbul1a.gif" width="15" height="15" hspace="13" alt="bullet"></td><td valign="top" width="100%"><!--mstheme--><font face="Arial, Arial, Helvetica">
    <p align="justify" style="line-height: 150%; margin-bottom:4">
    <a name="Ref1">[1]</a> Lasse S. Jensen and&nbsp;Robert Goli<font face="Arial">áš</font>. &quot;Deep 
    Water Animation and Rendering&quot; - <a href="http://www.swrendering.com/water">
    (pdf)</a>, <a href="http://www.gamasutra.com/gdce/jensen/jensen_01.htm">
    (html)</a> <!--mstheme--></font><!--msthemelist--></td></tr>
    <!--msthemelist--><tr><td valign="baseline" width="42"><img src="_themes/zero/zerbul1a.gif" width="15" height="15" hspace="13" alt="bullet"></td><td valign="top" width="100%"><!--mstheme--><font face="Arial, Arial, Helvetica">
    <p align="justify" style="line-height: 150%; margin-bottom:4">
    <a name="Ref2">[2]</a> Jerry Tessendorf.
    <a href="http://home1.gte.net/tssndrf/index.html">&quot;Simulating Ocean Water&quot;</a><!--mstheme--></font><!--msthemelist--></td></tr>
    <!--msthemelist--><tr><td valign="baseline" width="42"><img src="_themes/zero/zerbul1a.gif" width="15" height="15" hspace="13" alt="bullet"></td><td valign="top" width="100%"><!--mstheme--><font face="Arial, Arial, Helvetica">
    <p align="justify" style="line-height: 150%; margin-bottom:4">
    <a name="Ref3">[3]</a> Jonathan Cohen, Chris Tchou, 
    Tim Hawkins and Paul Debevec.
    <a href="http://www.ict.usc.edu/~jcohen/hdrtm.html">“Real-time High Dynamic 
    Range Texture Mapping&quot;</a><!--mstheme--></font><!--msthemelist--></td></tr>
    <!--msthemelist--><tr><td valign="baseline" width="42"><img src="_themes/zero/zerbul1a.gif" width="15" height="15" hspace="13" alt="bullet"></td><td valign="top" width="100%"><!--mstheme--><font face="Arial, Arial, Helvetica">
    <p align="justify" style="line-height: 150%; margin-bottom:4">
    <a name="Ref4">[4]</a> Tomoyuki Nishita, Eihac 
    hiro Nakamae. <a href="http://nis-lab.is.s.u-tokyo.ac.jp/~nis/pub_nis.html">
    “Method of Displaying Optical Effects within Water using Accumulation 
    Buffer”</a><!--mstheme--></font><!--msthemelist--></td></tr>
  <!--msthemelist--></table><!--mstheme--><font face="Arial, Arial, Helvetica">
  <p align="justify" style="line-height: 150%">&nbsp;</p>
  <!--webbot bot="Include" U-Include="footer.htm" TAG="BODY" startspan --><!--msthemeseparator--><p align="center"><img src="_themes/zero/zerrulea.gif" width="600" height="10"></p>
<p></p>
<p></p>
  <dl>
    <div align="center">
      <center>
      <dt>Last update on
      2002-03-17</dt>
      </center>
    </div>
    <div align="center">
      <center>
      <dd>
      <p align="center">&nbsp;</dd>
      </center>
    </div>
    <div align="center">
      <center>
      <dt>Meshuggah Demo and Effect browser.</dt>
      </center>
    </div>
    <div align="center">
      <center>
      <dt>Copyright © 2001, 2002
      <a href="mailto:carsten.wenzel@gmx.net?subject=Meshuggah Demo and Effect browser">Carsten Wenzel</a>.</dt>
      </center>
    </div>
    <div align="center">
      <center>
      <dt>All rights reserved.</dt>
      </center>
    </div>
  </dl>

<!--webbot bot="Include" i-checksum="22998" endspan --></div>


<!--mstheme--></font></body>

</html>
