Rendering first pass
authorhgn <hgodden00@gmail.com>
Sun, 25 Jul 2021 13:10:32 +0000 (14:10 +0100)
committerhgn <hgodden00@gmail.com>
Sun, 25 Jul 2021 13:10:32 +0000 (14:10 +0100)
fishladder.c
textures/rivertiles_flowm.tga
vg/vg_platform.h

index bb261856b3661e59da76644867c4ec1c69e6f409..1f4634bcce9f2fa66b39e11ba0c7b361a5d8ca99 100644 (file)
@@ -3,8 +3,8 @@
 //#define VG_STEAM
 #include "vg/vg.h"
 
-#define CELL_SHEET_X 256
-#define CELL_SHEET_Y 256
+#define CELL_SHEET_X 512
+#define CELL_SHEET_Y 512
 
 SHADER_DEFINE( colour_shader, 
 
@@ -46,11 +46,13 @@ SHADER_DEFINE( tilemap_shader,
        "{"
                "vec2 world_coord = a_co+a_offset+uOrigin;"
           "gl_Position = uPv * vec4( world_coord.x, 0.0, world_coord.y, 1.0 );"
-          "aCoords = (a_co*0.98+0.01 + a_data.xy) * 0.125;"
+          "aCoords = (a_co*0.98+0.01 + a_data.xy) * 0.0625;"
        "}",
        
        // FRAGMENT
        "uniform sampler2D uTexTiles;"
+       "uniform sampler2D uTexRipples;"
+       "uniform float uTime;"
        
        "in vec2 aCoords;"
        "out vec4 FragColor;"
@@ -58,10 +60,14 @@ SHADER_DEFINE( tilemap_shader,
        "void main()"
        "{"
                "vec4 glyph = texture( uTexTiles, aCoords );"
-          "FragColor = vec4( glyph.xyz, 1.0 );"
+               "vec4 ripple = texture( uTexRipples, vec2( glyph.x - uTime, glyph.y ));"
+               "float wstatus = -(fract(uTime)*2.0-1.0);"      // -1 := None in, 0.0 := Hold middle, 1.0 := All out
+               "float dev = step( 0.0, glyph.x+wstatus ) * step( glyph.x+wstatus, 1.0 );" //+ abs(glyph.y-0.5) );"
+               "vec3 composite = mix( vec3(0.5,0.5,0.5), vec3(0.3,0.6,1.0) + ripple.xyz * 0.1, step( 0.75, glyph.a )*dev ) * glyph.z;"
+          "FragColor = vec4( composite, 1.0 );"
        "}"
        ,
-       UNIFORMS({ "uPv", "uTexTiles", "uOrigin" })
+       UNIFORMS({ "uPv", "uTexTiles", "uTexRipples", "uTime", "uOrigin" })
 )
 
 mat4 m_projection;
@@ -157,6 +163,11 @@ static void map_free(void)
        map.io = NULL;
 }
 
+static struct cell *map_tile( int pos[2] )
+{
+       return map.cells + pos[1]*map.x + pos[0];
+}
+
 static struct cell *map_tile_at( int pos[2] )
 {
        if( pos[0] >= 0 && pos[0] < map.x && pos[1] >= 0 && pos[1] < map.y )
@@ -242,6 +253,41 @@ static void map_update_visual(void)
                celldata[i*4+1] = (i & ~0x7) >> 3;
        }
        
+       // Configurations
+       // DCBA | X Y
+       // 0001   3 0
+       // 0010   
+       
+       for( int y = 0; y < map.y; y ++ )
+       {
+               for( int x = 0; x < map.x; x ++ )
+               {
+                       struct cell *cur = map.cells + y*map.x + x;
+                       u8 *cellbytes = celldata + (y*map.x+x)*4; 
+                       
+                       if( cur->flags & CELL_FLAG_WALKABLE )
+                       {
+                               struct cell *a, *b, *c, *d;
+                               
+                               a = map_tile_at_cond( (int[2]){ x,y+1 }, CELL_FLAG_WALKABLE );
+                               b = map_tile_at_cond( (int[2]){ x+1,y }, CELL_FLAG_WALKABLE );
+                               c = map_tile_at_cond( (int[2]){ x,y-1 }, CELL_FLAG_WALKABLE );
+                               d = map_tile_at_cond( (int[2]){ x-1,y }, CELL_FLAG_WALKABLE );
+                               
+                               u32 config = (a?0x1:0x0) | (b?0x2:0x0) | (c?0x4:0x0) | (d?0x8:0x0);
+                               
+                               cellbytes[ 0 ] = config;
+                               cellbytes[ 1 ] = 0;
+                       }
+                       else
+                       {
+                               // TODO: Random background tiles
+                               cellbytes[ 0 ] = 1;
+                               cellbytes[ 1 ] = 0;
+                       }
+               }
+       }
+       
        glBindBuffer( GL_ARRAY_BUFFER, map.tiles_vbo );
        glBufferSubData( GL_ARRAY_BUFFER, 16*sizeof(float) + 1024*2*sizeof(float), map.x*map.y*4, celldata );
 }
@@ -392,7 +438,7 @@ static int map_tile_availible( int co[2] )
        for( int y = vg_max( co[1]-2, 0 ); y < vg_min( map.y, co[1]+3 ); y ++ )
                for( int x = vg_max( co[0]-2, 0 ); x < vg_min( map.x, co[0]+3 ); x ++ )
                {                               
-                       struct cell *cell = map_tile_at( (int[2]){ x, y } );
+                       struct cell *cell = map_tile( (int[2]){ x, y } );
                        
                        if( cell && (cell->flags & CELL_FLAG_WALKABLE) )
                                blob |= 0x1 << ((y-(co[1]-2))*5 + x-(co[0]-2));
@@ -767,7 +813,12 @@ void vg_render(void)
        glActiveTexture( GL_TEXTURE0 );
        glBindTexture( GL_TEXTURE_2D, map.tile_texture );
        
+       glUniform1i( SHADER_UNIFORM( tilemap_shader, "uTexRipples" ), 1 );
+       glActiveTexture( GL_TEXTURE1 );
+       glBindTexture( GL_TEXTURE_2D, map.flow_texture );
+       
        glUniform2f( SHADER_UNIFORM( tilemap_shader, "uOrigin" ), map.origin[0], map.origin[2] );
+       glUniform1f( SHADER_UNIFORM( tilemap_shader, "uTime" ), vg_time * 0.5f );
        
        glDrawArraysInstanced( GL_TRIANGLES, 0, 6, map.x*map.y );
 }
@@ -841,7 +892,8 @@ void vg_start(void)
        vg_tex2d_repeat();
        
        map.flow_texture = vg_tex2d_rgba( "textures/rivertiles_ripple.tga" );
-       
+       vg_tex2d_nearest();
+       vg_tex2d_repeat();
        
        map_load
        ( 
index 624502d7f85ebb40989d70a1979fe5286124a7b1..57b986f56bcc8ed0664d5c9fa243352cc29f4207 100644 (file)
Binary files a/textures/rivertiles_flowm.tga and b/textures/rivertiles_flowm.tga differ
index bc610f6b9192f8818426e58c334a23d581430848..da9a6adf3def39d5519c202a2f21733f5c752c86 100644 (file)
@@ -24,7 +24,7 @@ typedef unsigned int uint;
        #define MUTEX_TYPE             HANDLE
        #define MUTEX_INITIALIZER      NULL
        #define MUTEX_SETUP(x)         (x) = CreateMutex(NULL, FALSE, NULL)
-       #define MUTEX_CLEANUP(x)       (CloseHandle(x))
+       #define MUTEX_CLEANUP(x)       (CloseHandle(x)) //TODO: Why is this defined but never used?
        #define MUTEX_LOCK(x)          emulate_pthread_mutex_lock(&(x))
        #define MUTEX_UNLOCK(x)        (ReleaseMutex(x))