+static void water_compute_depth( boxf bounds )
+{
+ if( !wrender.enabled )
+ return;
+
+#ifdef VG_RELEASE
+ int const kres = 512;
+#else
+ int const kres = 64;
+#endif
+
+ vg_info( "Computing depth map\n" );
+ u8 *img = malloc( kres*kres );
+
+ v3f volume;
+ v3_sub( bounds[1], bounds[0], volume );
+ box_copy( bounds, wrender.depthbounds );
+
+ for( int y=0; y<kres; y++ )
+ {
+ for( int x=0; x<kres; x++ )
+ {
+ v3f pos = { x, 0, y };
+ v3_divs( pos, kres, pos );
+ v3_muladd( bounds[0], pos, volume, pos );
+ pos[1] = wrender.height;
+
+ ray_hit hit;
+ hit.dist = INFINITY;
+ u8 *dst = &img[ y*kres+x ];
+
+ if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &hit ))
+ {
+ float h = wrender.height - hit.pos[1];
+ h *= 1.0f/15.0f;
+ h = vg_clampf( h, 0.0f, 1.0f );
+ *dst = (u8)(h*255.0f);
+ }
+ else
+ *dst = 0;
+ }
+ }
+
+ if( wrender.depth_computed )
+ glDeleteTextures( 1, &wrender.depthmap );
+
+ glGenTextures( 1, &wrender.depthmap );
+ glBindTexture( GL_TEXTURE_2D, wrender.depthmap );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RED, kres, kres, 0,
+ GL_RED, GL_UNSIGNED_BYTE, img );
+
+ vg_tex2d_mipmap();
+ vg_tex2d_linear_mipmap();
+ vg_tex2d_clamp();
+
+ wrender.depth_computed = 1;
+ free( img );
+ vg_success( "Done.\n" );
+}
+
+static void water_set_surface( glmesh *surf, float height )