X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=water.h;h=1de2554abf8e459175a30438cb6146e0f24b09a3;hb=4a883ac1b2506032f9dddab342712de46f2ca734;hp=ac1db00dbafaf53001728bc6253f70b855a95a49;hpb=3bb0287d544a4cb75de9afe2927ac8e946f3a18e;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/water.h b/water.h index ac1db00..1de2554 100644 --- a/water.h +++ b/water.h @@ -4,7 +4,6 @@ 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); @@ -23,12 +22,12 @@ static struct struct framebuffer fbreflect, fbdepth; glmesh mdl; - GLuint depthmap; boxf depthbounds; int depth_computed; float height; int enabled; + v4f plane; } wrender = { @@ -64,6 +63,7 @@ static void water_fb_resize(void) fb_resize( &wrender.fbdepth ); } +#if 0 static void water_compute_depth( boxf bounds ) { if( !wrender.enabled ) @@ -72,11 +72,11 @@ static void water_compute_depth( boxf bounds ) #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]); @@ -92,25 +92,22 @@ static void water_compute_depth( boxf bounds ) { 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; } } } @@ -120,8 +117,8 @@ static void water_compute_depth( boxf bounds ) 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(); @@ -131,11 +128,14 @@ static void water_compute_depth( boxf bounds ) 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 ) @@ -204,7 +204,7 @@ 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 ); } @@ -226,18 +226,10 @@ static void render_water_surface( m4x4f pv, m4x3f camera ) 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 );