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
};
9 vg_tex2d
*texture_list
[] = { &tex_tile_detail
, &tex_tile_data
, &tex_wood
, &tex_ball
};
12 // ===========================================================================================================
14 sfx_vol_control audio_volume_sfx
= { .val
= 1.0f
, .name
= "Sound effects" };
15 sfx_vol_control audio_volume_music
= { .val
= 1.0f
, .name
= "Music" };
17 sfx_system audio_system_sfx
=
21 .vol_src
= &audio_volume_sfx
,
25 sfx_set audio_tile_mod
=
37 sfx_set audio_splitter
=
40 sound/splitter_01.ogg\0"
46 sound/rolling_01.ogg\0\
47 sound/rolling_02.ogg\0"
50 sfx_set audio_random
=
53 sound/random_01.ogg\0\
54 sound/random_02.ogg\0\
55 sound/random_03.ogg\0\
56 sound/random_04.ogg\0\
57 sound/random_05.ogg\0\
58 sound/random_06.ogg\0\
59 sound/random_07.ogg\0\
60 sound/random_08.ogg\0"
63 // One two or three layers of rolling noise
64 sfx_system audio_system_balls_rolling
=
66 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
67 .name
= "Balls Rolling", .flags
= SFX_FLAG_REPEAT
71 sfx_system audio_system_balls_switching
=
73 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
74 .name
= "Balls Switching"
77 // Gameplay critical sounds eg. splitter sound rocking
78 sfx_system audio_system_balls_important
=
80 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
81 .name
= "Balls Gameplay"
85 sfx_system audio_system_balls_extra
=
87 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
91 static void resource_load_main(void)
94 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
97 sfx_set_init( &audio_tile_mod
, NULL
);
98 sfx_set_init( &audio_splitter
, NULL
);
99 sfx_set_init( &audio_rolls
, NULL
);
100 sfx_set_init( &audio_random
, NULL
);
103 static void resource_free_main(void)
105 vg_tex2d_free( texture_list
, vg_list_size( texture_list
) );
107 sfx_set_free( &audio_tile_mod
);
108 sfx_set_free( &audio_splitter
);
109 sfx_set_free( &audio_rolls
);
110 sfx_set_free( &audio_random
);
114 // ===========================================================================================================
116 SHADER_DEFINE( shader_tile_colour
,
119 "layout (location=0) in vec2 a_co;"
121 "uniform vec3 uOffset;"
125 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
129 "out vec4 FragColor;"
130 "uniform vec4 uColour;"
134 "FragColor = uColour;"
137 UNIFORMS({ "uPv", "uOffset", "uColour" })
140 SHADER_DEFINE( shader_ball
,
142 "layout (location=0) in vec2 a_co;"
143 "uniform vec2 uOffset;"
146 "out vec2 aTexCoords;"
150 // Create texture coords
154 "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
155 "gl_Position = vec4( uPv * worldpos, 1.0 );"
159 "out vec4 FragColor;"
161 "uniform sampler2D uTexMain;"
162 "uniform vec3 uColour;"
164 "in vec2 aTexCoords;"
168 "vec4 glyph = texture( uTexMain, aTexCoords );"
169 "FragColor = vec4( uColour + glyph.rgb * 0.2, glyph.a );"
172 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" })
175 SHADER_DEFINE( shader_tile_main
,
177 "layout (location=0) in vec2 a_co;"
178 "uniform vec4 uOffset;" // Tile x/y, uv x/y
180 "uniform mat2 uSubTransform;"
182 "out vec4 aTexCoords;"
183 "out vec2 aWorldCoords;"
185 "vec2 hash22(vec2 p)"
187 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
188 "p3 += dot(p3, p3.yzx+33.33);"
189 "return fract((p3.xx+p3.yz)*p3.zy);"
195 "vec2 subtransform = uSubTransform * (a_co-0.5) + 0.5;"
196 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
197 "gl_Position = vec4( uPv * worldpos, 1.0 );"
199 // Create texture coords
200 "vec2 random_offset = floor(hash22(uOffset.xy) * 4.0) * 0.25;"
201 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
202 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
203 "aWorldCoords = worldpos.xy;"
207 "out vec4 FragColor;"
209 "uniform sampler2D uTexGlyphs;"
210 "uniform sampler2D uTexWood;"
211 "uniform float uGhost;"
212 "uniform vec2 uMousePos;"
213 "uniform vec4 uColour;"
215 "in vec4 aTexCoords;"
216 "in vec2 aWorldCoords;"
220 "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 );"
221 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
222 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
223 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
224 "vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );"
226 "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
228 "vec4 output_regular = vec4( wood_comp * shadows, glyph.b );"
230 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
231 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
233 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
236 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour" })
239 void vg_register(void)
241 SHADER_INIT( shader_tile_colour
);
242 SHADER_INIT( shader_tile_main
);
243 SHADER_INIT( shader_ball
);