From: hgn Date: Mon, 1 Nov 2021 16:45:23 +0000 (+0000) Subject: dont remember what i did X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=55bf7018846f925daf6c3800bf7d28079e1b4721;p=fishladder.git dont remember what i did --- diff --git a/fishladder.c b/fishladder.c index f4afab1..f75188e 100644 --- a/fishladder.c +++ b/fishladder.c @@ -571,15 +571,20 @@ void vg_update(void) vg_info( "Stopping simulation!\n" ); } - float ratio = (float)vg_window_y / (float)vg_window_x; - float const size = 9.5f; + // Fit within screen + + float r1 = (float)vg_window_y / (float)vg_window_x, + r2 = (float)world.h / (float)world.w, + size; + + size = ( r2 < r1? (float)world.w * 0.5f: ((float)world.h * 0.5f) / r1 ) + 2.5f; + m3x3_projection( m_projection, -size, size, -size*r1, size*r1 ); v3f origin; - origin[0] = -0.5f * world.w; - origin[1] = -0.5f * world.h; + origin[0] = floorf( -0.5f * world.w ); + origin[1] = floorf( -0.5f * world.h ); origin[2] = 0.0f; - m3x3_projection( m_projection, -size, size, -size*ratio, size*ratio ); m3x3_identity( m_view ); m3x3_translate( m_view, origin ); m3x3_mul( m_projection, m_view, vg_pv ); @@ -946,7 +951,7 @@ static void render_tiles( v2i start, v2i end, v4f const regular_colour, v4f cons { uv[0] = tile_offsets[ cell->config ][0]; uv[1] = tile_offsets[ cell->config ][1]; - } + } else continue; glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ), (float)x, (float)y, uv[0], uv[1] ); if( selected ) @@ -966,7 +971,7 @@ void vg_render(void) glViewport( 0,0, vg_window_x, vg_window_y ); glDisable( GL_DEPTH_TEST ); - glClearColor( 0.8f, 0.8f, 0.8f, 1.0f ); + glClearColor( 0.369768f, 0.3654f, 0.42f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); v4f const colour_default = {1.0f, 1.0f, 1.0f, 1.0f}; @@ -982,6 +987,23 @@ void vg_render(void) use_mesh( &world.tile ); + // Draw background + + if(0){ + + SHADER_USE( shader_background ); + glUniformMatrix3fv( SHADER_UNIFORM( shader_background, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); + + vg_tex2d_bind( &tex_background, 0 ); + glUniform1i( SHADER_UNIFORM( shader_background, "uTexMain" ), 0 ); + + glUniform3f( SHADER_UNIFORM( shader_background, "uOffset" ), -50, -50, 100 ); + + draw_mesh( 0, 2 ); + + } + + SHADER_USE( shader_tile_main ); m2x2f subtransform; @@ -989,6 +1011,11 @@ void vg_render(void) glUniformMatrix2fv( SHADER_UNIFORM( shader_tile_main, "uSubTransform" ), 1, GL_FALSE, (float *)subtransform ); glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_main, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); glUniform1f( SHADER_UNIFORM( shader_tile_main, "uGhost" ), 0.0f ); + glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 0.0f ); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); // Bind textures vg_tex2d_bind( &tex_tile_data, 0 ); @@ -999,9 +1026,7 @@ void vg_render(void) render_tiles( NULL, NULL, colour_default, colour_default ); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); + SHADER_USE( shader_ball ); glUniformMatrix3fv( SHADER_UNIFORM( shader_ball, "uPv" ), 1, GL_FALSE, (float *)vg_pv ); @@ -1040,6 +1065,7 @@ void vg_render(void) vg_tex2d_bind( &tex_wood, 1 ); glUniform1i( SHADER_UNIFORM( shader_tile_main, "uTexWood" ), 1 ); + glUniform1f( SHADER_UNIFORM( shader_tile_main, "uForeground" ), 1.0f ); render_tiles( NULL, NULL, colour_default, colour_selected ); // Draw splitters diff --git a/fishladder_resources.h b/fishladder_resources.h index 1f8c545..00cb199 100644 --- a/fishladder_resources.h +++ b/fishladder_resources.h @@ -5,8 +5,9 @@ vg_tex2d tex_tile_data = { .path = "textures/tileset.png" }; vg_tex2d tex_tile_detail = { .path = "textures/tile_overlays.png" }; vg_tex2d tex_wood = { .path = "textures/wood.png" }; vg_tex2d tex_ball = { .path = "textures/ball.png", .flags = VG_TEXTURE_CLAMP }; +vg_tex2d tex_background = { .path = "textures/background.png" }; -vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball }; +vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball, &tex_background }; // AUDIO // =========================================================================================================== @@ -209,6 +210,7 @@ SHADER_DEFINE( shader_tile_main, "uniform sampler2D uTexGlyphs;" "uniform sampler2D uTexWood;" "uniform float uGhost;" + "uniform float uForeground;" "uniform vec2 uMousePos;" "uniform vec4 uColour;" "" @@ -225,7 +227,7 @@ SHADER_DEFINE( shader_tile_main, "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );" - "vec4 output_regular = vec4( wood_comp * shadows, glyph.b );" + "vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );" "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );" "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );" @@ -233,7 +235,46 @@ SHADER_DEFINE( shader_tile_main, "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;" "}" , - UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour" }) + UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour", "uForeground" }) +) + +SHADER_DEFINE( shader_background, + // VERTEX + "layout (location=0) in vec2 a_co;" + "uniform mat3 uPv;" + "uniform vec3 uOffset;" + "" + "out vec2 aTexCoords;" + "" + "void main()" + "{" + "vec2 world_pos = a_co * uOffset.z + uOffset.xy;" + "gl_Position = vec4( uPv * vec3( world_pos, 1.0 ), 1.0 );" + "aTexCoords = world_pos * 0.25;" + "}", + + // FRAGMENT + "out vec4 FragColor;" + "" + "uniform sampler2D uTexMain;" + "" + "in vec2 aTexCoords;" + "" + "vec2 hash22(vec2 p)" + "{" + "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));" + "p3 += dot(p3, p3.yzx+33.33);" + "return fract((p3.xx+p3.yz)*p3.zy);" + "}" + "" + "void main()" + "{" + "vec2 random_offset = floor( hash22( floor( aTexCoords * 4.0 ) ) * 4.0 ) * 0.25;" + "vec4 background = texture( uTexMain, aTexCoords );" + "FragColor = vec4( background.rgb * (1.0+random_offset.r*0.015), 1.0 );" + "}" + , + UNIFORMS({ "uPv", "uOffset", "uTexMain" }) ) void vg_register(void) @@ -241,4 +282,5 @@ void vg_register(void) SHADER_INIT( shader_tile_colour ); SHADER_INIT( shader_tile_main ); SHADER_INIT( shader_ball ); + SHADER_INIT( shader_background ); } diff --git a/textures/background.png b/textures/background.png new file mode 100644 index 0000000..7312b7c Binary files /dev/null and b/textures/background.png differ diff --git a/textures/tileset.png b/textures/tileset.png index aa41e19..6d8928b 100644 Binary files a/textures/tileset.png and b/textures/tileset.png differ diff --git a/textures/wood.png b/textures/wood.png index 79521d4..81c0817 100644 Binary files a/textures/wood.png and b/textures/wood.png differ