static void water_register(void);
static void water_init(void);
static void water_fb_resize(void);
-static void water_compute_depth( boxf bounds );
static void water_set_surface( glmesh *surf, float height );
static float water_height(void);
struct framebuffer fbreflect, fbdepth;
glmesh mdl;
- GLuint depthmap;
boxf depthbounds;
int depth_computed;
float height;
int enabled;
+ v4f plane;
}
wrender =
{
fb_resize( &wrender.fbdepth );
}
+#if 0
static void water_compute_depth( boxf bounds )
{
if( !wrender.enabled )
#ifdef VG_RELEASE
int const kres = 512;
#else
- int const kres = 64;
+ int const kres = 1024;
#endif
vg_info( "Computing depth map\n" );
- u8 *img = malloc( kres*kres );
+ float *img = malloc( kres*kres*sizeof(float) );
boxf interior;
v3_add(bounds[0],(v3f){1.0f,1.0f,1.0f},interior[0]);
{
v3f pos = { x, 0.0f, y };
pos[0] += 0.5f;
- pos[1] += 0.5f;
+ pos[2] += 0.5f;
v3_divs( pos, kres+1, pos );
v3_muladd( interior[0], pos, volume, pos );
pos[1] = 2000.0f;
ray_hit hit;
hit.dist = INFINITY;
- u8 *dst = &img[ y*kres+x ];
+ float *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/25.0f;
- h = vg_clampf( h, 0.0f, 1.0f );
- *dst = (u8)(h*255.0f);
+ *dst = hit.pos[1];
}
else
{
- *dst = 0;
+ *dst = 0.0f;
}
}
}
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 );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_R32F, kres, kres, 0,
+ GL_RED, GL_FLOAT, img );
vg_tex2d_mipmap();
vg_tex2d_linear_mipmap();
free( img );
vg_success( "Done.\n" );
}
+#endif
static void water_set_surface( glmesh *surf, float height )
{
wrender.mdl = *surf;
wrender.height = height;
+
+ v4_copy( (v4f){ 0.0f, 1.0f, 0.0f, height }, wrender.plane );
}
static void render_water_texture( m4x3f camera )
plane_clip_projection( projection, clippb );
m4x4_mul( projection, view, projection );
- render_world( projection, camera );
+ render_world_depth( projection, camera );
glViewport( 0, 0, vg_window_x, vg_window_y );
}
1.0f / (float)vg_window_x,
1.0f / (float)vg_window_y });
- glActiveTexture( GL_TEXTURE2 );
- glBindTexture( GL_TEXTURE_2D, wrender.depthmap );
- shader_water_uTexDepth( 2 );
- shader_water_uDepthBounds( (v4f){
- wrender.depthbounds[0][0],
- wrender.depthbounds[0][2],
- 1.0f/ (wrender.depthbounds[1][0]-wrender.depthbounds[0][0]),
- 1.0f/ (wrender.depthbounds[1][2]-wrender.depthbounds[0][2])} );
+ shader_link_standard_ub( _shader_water.id, 2 );
fb_bindtex( &wrender.fbdepth, 3 );
shader_water_uTexBack( 3 );
-
shader_water_uTime( vg_time );
shader_water_uCamera( camera[3] );
shader_water_uSurfaceY( wrender.height );