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 // One two or three layers of rolling noise
51 sfx_system audio_system_balls_rolling
=
53 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
54 .name
= "Balls Rolling", .flags
= SFX_FLAG_REPEAT
58 sfx_system audio_system_balls_switching
=
60 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
61 .name
= "Balls Switching"
64 // Gameplay critical sounds eg. splitter sound rocking
65 sfx_system audio_system_balls_important
=
67 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
68 .name
= "Balls Gameplay"
72 sfx_system audio_system_balls_extra
=
74 .vol
= 1.f
, .ch
= 1, .vol_src
= &audio_volume_sfx
,
78 static void resource_load_main(void)
81 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
84 sfx_set_init( &audio_tile_mod
, NULL
);
85 sfx_set_init( &audio_splitter
, NULL
);
86 sfx_set_init( &audio_rolls
, NULL
);
89 static void resource_free_main(void)
91 vg_tex2d_free( texture_list
, vg_list_size( texture_list
) );
92 sfx_set_free( &audio_tile_mod
);
93 sfx_set_free( &audio_splitter
);
94 sfx_set_free( &audio_rolls
);
98 // ===========================================================================================================
100 SHADER_DEFINE( shader_tile_colour
,
103 "layout (location=0) in vec2 a_co;"
105 "uniform vec3 uOffset;"
109 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
113 "out vec4 FragColor;"
114 "uniform vec4 uColour;"
118 "FragColor = uColour;"
121 UNIFORMS({ "uPv", "uOffset", "uColour" })
124 SHADER_DEFINE( shader_ball
,
126 "layout (location=0) in vec2 a_co;"
127 "uniform vec2 uOffset;"
130 "out vec2 aTexCoords;"
134 // Create texture coords
138 "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
139 "gl_Position = vec4( uPv * worldpos, 1.0 );"
143 "out vec4 FragColor;"
145 "uniform sampler2D uTexMain;"
146 "uniform vec3 uColour;"
148 "in vec2 aTexCoords;"
152 "vec4 glyph = texture( uTexMain, aTexCoords );"
153 "FragColor = vec4( uColour + glyph.rgb * 0.2, glyph.a );"
156 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" })
159 SHADER_DEFINE( shader_tile_main
,
161 "layout (location=0) in vec2 a_co;"
162 "uniform vec4 uOffset;" // Tile x/y, uv x/y
164 "uniform mat2 uSubTransform;"
166 "out vec4 aTexCoords;"
167 "out vec2 aWorldCoords;"
169 "vec2 hash22(vec2 p)"
171 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
172 "p3 += dot(p3, p3.yzx+33.33);"
173 "return fract((p3.xx+p3.yz)*p3.zy);"
179 "vec2 subtransform = uSubTransform * (a_co-0.5) + 0.5;"
180 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
181 "gl_Position = vec4( uPv * worldpos, 1.0 );"
183 // Create texture coords
184 "vec2 random_offset = floor(hash22(uOffset.xy) * 4.0) * 0.25;"
185 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
186 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
187 "aWorldCoords = worldpos.xy;"
191 "out vec4 FragColor;"
193 "uniform sampler2D uTexGlyphs;"
194 "uniform sampler2D uTexWood;"
195 "uniform float uGhost;"
196 "uniform vec2 uMousePos;"
197 "uniform vec4 uColour;"
199 "in vec4 aTexCoords;"
200 "in vec2 aWorldCoords;"
204 "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 );"
205 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
206 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
207 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
208 "vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );"
210 "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
212 "vec4 output_regular = vec4( wood_comp * shadows, glyph.b );"
214 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
215 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
217 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
220 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour" })
223 void vg_register(void)
225 SHADER_INIT( shader_tile_colour
);
226 SHADER_INIT( shader_tile_main
);
227 SHADER_INIT( shader_ball
);