much cleaner audio handling & extra controls
[fishladder.git] / fishladder_resources.h
1 // TEXTURES
2 // ===========================================================================================================
3
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
9 vg_tex2d *texture_list[] = { &tex_tile_detail, &tex_tile_data, &tex_wood, &tex_ball };
10
11 // AUDIO
12 // ===========================================================================================================
13
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" };
16
17 sfx_system audio_system_sfx =
18 {
19 .vol = 1.f,
20 .ch = 1,
21 .vol_src = &audio_volume_sfx,
22 .name = "sfx"
23 };
24
25 sfx_set audio_tile_mod =
26 {
27 .sources = "\
28 sound/mod_01.ogg\0\
29 sound/mod_02.ogg\0\
30 sound/mod_03.ogg\0\
31 sound/mod_04.ogg\0\
32 sound/mod_05.ogg\0\
33 sound/mod_06.ogg\0",
34 .flags = 0
35 };
36
37 sfx_set audio_splitter =
38 {
39 .sources = "\
40 sound/splitter_01.ogg\0"
41 };
42
43 sfx_set audio_rolls =
44 {
45 .sources = "\
46 sound/rolling_01.ogg\0\
47 sound/rolling_02.ogg\0"
48 };
49
50 // One two or three layers of rolling noise
51 sfx_system audio_system_balls_rolling =
52 {
53 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
54 .name = "Balls Rolling", .flags = SFX_FLAG_REPEAT
55 };
56
57 // Various oneshots
58 sfx_system audio_system_balls_switching =
59 {
60 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
61 .name = "Balls Switching"
62 };
63
64 // Gameplay critical sounds eg. splitter sound rocking
65 sfx_system audio_system_balls_important =
66 {
67 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
68 .name = "Balls Gameplay"
69 };
70
71 // Suplemental sounds
72 sfx_system audio_system_balls_extra =
73 {
74 .vol = 1.f, .ch = 1, .vol_src = &audio_volume_sfx,
75 .name = "Balls Extra"
76 };
77
78 static void resource_load_main(void)
79 {
80 // Textures
81 vg_tex2d_init( texture_list, vg_list_size( texture_list ) );
82
83 // Audio
84 sfx_set_init( &audio_tile_mod, NULL );
85 sfx_set_init( &audio_splitter, NULL );
86 sfx_set_init( &audio_rolls, NULL );
87 }
88
89 static void resource_free_main(void)
90 {
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 );
95 }
96
97 // SHADERS
98 // ===========================================================================================================
99
100 SHADER_DEFINE( shader_tile_colour,
101
102 // VERTEX
103 "layout (location=0) in vec2 a_co;"
104 "uniform mat3 uPv;"
105 "uniform vec3 uOffset;"
106 ""
107 "void main()"
108 "{"
109 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
110 "}",
111
112 // FRAGMENT
113 "out vec4 FragColor;"
114 "uniform vec4 uColour;"
115 ""
116 "void main()"
117 "{"
118 "FragColor = uColour;"
119 "}"
120 ,
121 UNIFORMS({ "uPv", "uOffset", "uColour" })
122 )
123
124 SHADER_DEFINE( shader_ball,
125 // VERTEX
126 "layout (location=0) in vec2 a_co;"
127 "uniform vec2 uOffset;"
128 "uniform mat3 uPv;"
129 ""
130 "out vec2 aTexCoords;"
131 ""
132 "void main()"
133 "{"
134 // Create texture coords
135 "aTexCoords = a_co;"
136
137 // Vertex transform
138 "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
139 "gl_Position = vec4( uPv * worldpos, 1.0 );"
140 "}",
141
142 // FRAGMENT
143 "out vec4 FragColor;"
144 ""
145 "uniform sampler2D uTexMain;"
146 "uniform vec3 uColour;"
147 ""
148 "in vec2 aTexCoords;"
149 ""
150 "void main()"
151 "{"
152 "vec4 glyph = texture( uTexMain, aTexCoords );"
153 "FragColor = vec4( uColour + glyph.rgb * 0.2, glyph.a );"
154 "}"
155 ,
156 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" })
157 )
158
159 SHADER_DEFINE( shader_tile_main,
160 // VERTEX
161 "layout (location=0) in vec2 a_co;"
162 "uniform vec4 uOffset;" // Tile x/y, uv x/y
163 "uniform mat3 uPv;"
164 "uniform mat2 uSubTransform;"
165 ""
166 "out vec4 aTexCoords;"
167 "out vec2 aWorldCoords;"
168 ""
169 "vec2 hash22(vec2 p)"
170 "{"
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);"
174 "}"
175 ""
176 "void main()"
177 "{"
178 // Vertex transform
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 );"
182
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;"
188 "}",
189
190 // FRAGMENT
191 "out vec4 FragColor;"
192 ""
193 "uniform sampler2D uTexGlyphs;"
194 "uniform sampler2D uTexWood;"
195 "uniform float uGhost;"
196 "uniform vec2 uMousePos;"
197 "uniform vec4 uColour;"
198 ""
199 "in vec4 aTexCoords;"
200 "in vec2 aWorldCoords;"
201 ""
202 "void main()"
203 "{"
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 ) );"
209
210 "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
211
212 "vec4 output_regular = vec4( wood_comp * shadows, glyph.b );"
213
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 );"
216
217 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
218 "}"
219 ,
220 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour" })
221 )
222
223 void vg_register(void)
224 {
225 SHADER_INIT( shader_tile_colour );
226 SHADER_INIT( shader_tile_main );
227 SHADER_INIT( shader_ball );
228 }