2 // ===========================================================================================================
4 vg_tex2d tex_tile_data
= { .path
= "textures/tileset.png" };
5 vg_tex2d tex_tile_detail
= { .path
= "textures/tile_overlays.png" };
6 vg_tex2d tex_wood
= { .path
= "textures/wood.png" };
7 vg_tex2d tex_ball
= { .path
= "textures/ball.png", .flags
= VG_TEXTURE_CLAMP
};
8 vg_tex2d tex_background
= { .path
= "textures/background.png" };
10 vg_tex2d
*texture_list
[] = { &tex_tile_detail
, &tex_tile_data
, &tex_wood
, &tex_ball
, &tex_background
};
13 // ===========================================================================================================
15 sfx_vol_control audio_volume_sfx
= { .val
= 1.0f
, .name
= "Sound effects" };
16 sfx_vol_control audio_volume_music
= { .val
= 1.0f
, .name
= "Music" };
18 sfx_system audio_system_sfx
=
22 .vol_src
= &audio_volume_sfx
,
26 sfx_set audio_tile_mod
=
38 sfx_set audio_splitter
=
41 sound/splitter_01.ogg\0"
47 sound/rolling_01.ogg\0\
48 sound/rolling_02.ogg\0"
51 sfx_set audio_random
=
54 sound/random_01.ogg\0\
55 sound/random_02.ogg\0\
56 sound/random_03.ogg\0\
57 sound/random_04.ogg\0\
58 sound/random_05.ogg\0\
59 sound/random_06.ogg\0\
60 sound/random_07.ogg\0\
61 sound/random_08.ogg\0"
64 // One two or three layers of rolling noise
65 sfx_system audio_system_balls_rolling
=
67 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
68 .name
= "Balls Rolling", .flags
= SFX_FLAG_REPEAT
72 sfx_system audio_system_balls_switching
=
74 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
75 .name
= "Balls Switching"
78 // Gameplay critical sounds eg. splitter sound rocking
79 sfx_system audio_system_balls_important
=
81 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
82 .name
= "Balls Gameplay"
86 sfx_system audio_system_balls_extra
=
88 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
92 static void resource_load_main(void)
95 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
98 sfx_set_init( &audio_tile_mod
, NULL
);
99 sfx_set_init( &audio_splitter
, NULL
);
100 sfx_set_init( &audio_rolls
, NULL
);
101 sfx_set_init( &audio_random
, NULL
);
104 static void resource_free_main(void)
106 vg_tex2d_free( texture_list
, vg_list_size( texture_list
) );
108 sfx_set_free( &audio_tile_mod
);
109 sfx_set_free( &audio_splitter
);
110 sfx_set_free( &audio_rolls
);
111 sfx_set_free( &audio_random
);
115 // ===========================================================================================================
117 SHADER_DEFINE( shader_tile_colour
,
120 "layout (location=0) in vec2 a_co;"
122 "uniform vec3 uOffset;"
126 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
130 "out vec4 FragColor;"
131 "uniform vec4 uColour;"
135 "FragColor = uColour;"
138 UNIFORMS({ "uPv", "uOffset", "uColour" })
141 SHADER_DEFINE( shader_ball
,
143 "layout (location=0) in vec2 a_co;"
144 "uniform vec2 uOffset;"
147 "out vec2 aTexCoords;"
151 // Create texture coords
155 "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
156 "gl_Position = vec4( uPv * worldpos, 1.0 );"
160 "out vec4 FragColor;"
162 "uniform sampler2D uTexMain;"
163 "uniform vec3 uColour;"
165 "in vec2 aTexCoords;"
169 "vec4 glyph = texture( uTexMain, aTexCoords );"
170 "FragColor = vec4( uColour + glyph.rgb * 0.2, glyph.a );"
173 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" })
176 SHADER_DEFINE( shader_tile_main
,
178 "layout (location=0) in vec2 a_co;"
179 "uniform vec4 uOffset;" // Tile x/y, uv x/y
181 "uniform mat2 uSubTransform;"
183 "out vec4 aTexCoords;"
184 "out vec2 aWorldCoords;"
186 "vec2 hash22(vec2 p)"
188 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
189 "p3 += dot(p3, p3.yzx+33.33);"
190 "return fract((p3.xx+p3.yz)*p3.zy);"
196 "vec2 subtransform = uSubTransform * (a_co-0.5) + 0.5;"
197 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
198 "gl_Position = vec4( uPv * worldpos, 1.0 );"
200 // Create texture coords
201 "vec2 random_offset = floor(hash22(uOffset.xy) * 4.0) * 0.25;"
202 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
203 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
204 "aWorldCoords = worldpos.xy;"
208 "out vec4 FragColor;"
210 "uniform sampler2D uTexGlyphs;"
211 "uniform sampler2D uTexWood;"
212 "uniform float uGhost;"
213 "uniform float uForeground;"
214 "uniform vec2 uMousePos;"
215 "uniform vec4 uColour;"
217 "in vec4 aTexCoords;"
218 "in vec2 aWorldCoords;"
222 "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 );"
223 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
224 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
225 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
226 "vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );"
228 "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
230 "vec4 output_regular = vec4( wood_comp * shadows, mix( glyph.a, glyph.b, uForeground ) );"
232 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
233 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
235 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
238 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour", "uForeground" })
241 SHADER_DEFINE( shader_background
,
243 "layout (location=0) in vec2 a_co;"
245 "uniform vec3 uOffset;"
247 "out vec2 aTexCoords;"
251 "vec2 world_pos = a_co * uOffset.z + uOffset.xy;"
252 "gl_Position = vec4( uPv * vec3( world_pos, 1.0 ), 1.0 );"
257 "out vec4 FragColor;"
259 "uniform sampler2D uTexMain;"
260 "uniform sampler2D uSamplerNoise;"
261 "uniform float uVariance;"
263 "in vec2 aTexCoords;"
267 "float ao_accum = 0.0;"
268 "for( int i=0; i<10; ++i )"
270 "vec2 random_noise = (texture( uSamplerNoise, aTexCoords * 20.0 + float(i) * 0.2 ).xy - vec2( 0.5, 0.5 )) * uVariance;"
271 "vec4 background = texture( uTexMain, aTexCoords + random_noise );"
272 "ao_accum += background.r * clamp((1.0 - length( random_noise )), 0.0, 1.0);"
276 "vec4 data_this_tile = texture( uTexMain, aTexCoords );"
278 "ao_accum -= data_this_tile.r;"
280 "vec3 colour_main = vec3( 0.369768, 0.3654, 0.42 );"
282 "vec2 square_coords = fract( aTexCoords * 64.0 );"
283 "vec2 grid_coords = abs( square_coords - 0.5 );"
284 "float edge_contrast = (1.0-ao_accum*0.2);"
286 "float gridline = step( 0.49, max(grid_coords.x,grid_coords.y) );"
287 "float gridline_fadeout = min(max(edge_contrast-1.0, 0.0)*40.0 + data_this_tile.g,10.0);"
289 "FragColor = vec4( colour_main * edge_contrast + gridline * 0.02 * gridline_fadeout, 1.0 );"
292 UNIFORMS({ "uPv", "uOffset", "uTexMain", "uVariance", "uSamplerNoise" })
295 void vg_register(void)
297 SHADER_INIT( shader_tile_colour
);
298 SHADER_INIT( shader_tile_main
);
299 SHADER_INIT( shader_ball
);
300 SHADER_INIT( shader_background
);