actually good ball shader
authorhgn <hgodden00@gmail.com>
Fri, 3 Dec 2021 02:56:05 +0000 (02:56 +0000)
committerhgn <hgodden00@gmail.com>
Fri, 3 Dec 2021 02:56:05 +0000 (02:56 +0000)
fishladder.c
fishladder_resources.h
textures/bnoise.png [new file with mode: 0644]

index eb56b5a3fd2cab8bb7505e3aea5232a3ec4217d3..4ff74588763a3990458addab078b3b00a87c1d42 100644 (file)
@@ -182,7 +182,7 @@ v2f const curve_7_1[] = {{0.5f,0.8438f},{1.0f-0.875f,0.8438f},{1.0-0.625f,0.5f},
 float const curve_7_linear_section = 0.1562f;
 
 v3f colour_sets[] =
-{ { 0.9f, 0.6f, 0.20f },
+{ { 1.0f, 0.9f, 0.3f },
   { 0.2f, 0.9f, 0.14f },
   { 0.4f, 0.8f, 1.00f } };
 
@@ -1911,7 +1911,7 @@ void vg_render(void)
        SHADER_USE( shader_ball );
        glUniformMatrix3fv( SHADER_UNIFORM( shader_ball, "uPv" ), 1, GL_FALSE, (float *)vg_pv );
        
-       vg_tex2d_bind( &tex_ball, 0 );
+       vg_tex2d_bind( &tex_ball_noise, 0 );
        glUniform1i( SHADER_UNIFORM( shader_ball, "uTexMain" ), 0 );
        
        // Draw 'fish'
@@ -1932,7 +1932,8 @@ void vg_render(void)
                        
                        glUniform3fv( SHADER_UNIFORM( shader_ball, "uColour" ), 1, dot_colour );
                        glUniform2fv( SHADER_UNIFORM( shader_ball, "uOffset" ), 1, fish->physics_co );
-                       draw_mesh( 0, 32 );
+                       glUniform2f( SHADER_UNIFORM( shader_ball, "uTexOffset" ), (float)i * 1.2334, (float)i * -0.3579f );
+                       draw_mesh( 0, 2 );
                }
        }
        
index 2bd1442d125e379b53eb589b77fc3f0b81ba8390..e3abf07bd3da513c1a24328f5244fc3829468b97 100644 (file)
@@ -6,8 +6,9 @@ vg_tex2d tex_tile_detail = { .path = "textures/tile_overlays.qoi" };
 vg_tex2d tex_wood =                    { .path = "textures/wood.qoi" };
 vg_tex2d tex_ball =                    { .path = "textures/ball.qoi", .flags = VG_TEXTURE_CLAMP };
 vg_tex2d tex_background =      { .path = "textures/background.qoi" };
+vg_tex2d tex_ball_noise =  { .path = "textures/bnoise.qoi" };
 
-vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball, &tex_background };
+vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball, &tex_background, &tex_ball_noise };
 
 // AUDIO
 // ===========================================================================================================
@@ -138,6 +139,7 @@ SHADER_DEFINE( shader_tile_colour,
        UNIFORMS({ "uPv", "uOffset", "uColour" })
 )
 
+/*
 SHADER_DEFINE( shader_ball,
        // VERTEX
        "layout (location=0) in vec2 a_co;"
@@ -172,6 +174,60 @@ SHADER_DEFINE( shader_ball,
        ,
        UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" })
 )
+*/
+
+SHADER_DEFINE( shader_ball,
+       // VERTEX
+       "layout (location=0) in vec2 a_co;"
+       "uniform vec2 uOffset;"
+       "uniform mat3 uPv;"
+       ""
+       "out vec4 aTexCoords;"
+       ""
+       "void main()"
+       "{"
+               // Vertex transform
+               "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
+               "gl_Position = vec4( uPv * worldpos, 1.0 );"
+
+               // Create texture coords
+               "aTexCoords = vec4( a_co, worldpos.xy );"
+       "}",
+       
+       // FRAGMENT
+       "out vec4 FragColor;"
+       ""
+       "uniform sampler2D uTexMain;"
+       "uniform vec3 uColour;"
+       "uniform vec2 uTexOffset;"
+       ""
+       "in vec4 aTexCoords;"
+       ""
+       "void main()"
+       "{"
+               "vec2 center_coords = aTexCoords.xy - 0.5;"
+               "vec2 center_coords_sqr = center_coords*center_coords;"
+               "float circle_factor = smoothstep( 0.07, 0.0625, center_coords_sqr.x+center_coords_sqr.y );"
+               
+               "float bulge_amt = center_coords_sqr.x+center_coords_sqr.y;"
+               "vec2 warped_coords = aTexCoords.zw+uTexOffset - center_coords;"
+               "vec4 noise_sample = texture( uTexMain, warped_coords );"
+               
+               "float rim_light = (center_coords_sqr.x+center_coords_sqr.y)*15.0;"
+               
+               "vec2 shadow_coords = center_coords + vec2(0.02,0.07);"
+               "vec2 shadow_coords_sqr = shadow_coords*shadow_coords;"
+               //"float shadow = exp(-abs(shadow_coords_sqr.x+shadow_coords_sqr.y)*20.0);"
+               "float shadow = exp(-((shadow_coords_sqr.x+shadow_coords_sqr.y)-0.0125)*15.0);"
+               
+               "vec3 marble_comp = uColour*0.9 + (noise_sample.x*0.7+pow(rim_light,3.0)*2.0) * 0.1;"
+               "vec4 colour_comp = mix( vec4(0.74,0.53,0.34,shadow), vec4(marble_comp,1.0), circle_factor );"
+               
+               "FragColor = colour_comp;"
+       "}"
+       ,
+       UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv", "uTexOffset" })
+)
 
 SHADER_DEFINE( shader_tile_main,
        // VERTEX
diff --git a/textures/bnoise.png b/textures/bnoise.png
new file mode 100644 (file)
index 0000000..23b4a8f
Binary files /dev/null and b/textures/bnoise.png differ