//#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,
"{"
"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;"
"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;
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 )
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 );
}
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));
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 );
}
vg_tex2d_repeat();
map.flow_texture = vg_tex2d_rgba( "textures/rivertiles_ripple.tga" );
-
+ vg_tex2d_nearest();
+ vg_tex2d_repeat();
map_load
(