bring audio code inline with current standards
[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 .fadeout_length = FADEOUT_LENGTH,
23 .name = "sfx"
24 };
25
26 sfx_set audio_tile_mod =
27 {
28 .sources = "\
29 sound/mod_01.ogg\0\
30 sound/mod_02.ogg\0\
31 sound/mod_03.ogg\0\
32 sound/mod_04.ogg\0\
33 sound/mod_05.ogg\0\
34 sound/mod_06.ogg\0",
35 .flags = 0
36 };
37
38 static void resource_load_main(void)
39 {
40 // Textures
41 vg_tex2d_init( texture_list, vg_list_size( texture_list ) );
42
43 // Audio
44 sfx_set_init( &audio_tile_mod, NULL );
45 }
46
47 static void resource_free_main(void)
48 {
49 vg_tex2d_free( texture_list, vg_list_size( texture_list ) );
50 sfx_set_free( &audio_tile_mod );
51 }
52
53 // SHADERS
54 // ===========================================================================================================
55
56 SHADER_DEFINE( shader_tile_colour,
57
58 // VERTEX
59 "layout (location=0) in vec2 a_co;"
60 "uniform mat3 uPv;"
61 "uniform vec3 uOffset;"
62 ""
63 "void main()"
64 "{"
65 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
66 "}",
67
68 // FRAGMENT
69 "out vec4 FragColor;"
70 "uniform vec4 uColour;"
71 ""
72 "void main()"
73 "{"
74 "FragColor = uColour;"
75 "}"
76 ,
77 UNIFORMS({ "uPv", "uOffset", "uColour" })
78 )
79
80 SHADER_DEFINE( shader_ball,
81 // VERTEX
82 "layout (location=0) in vec2 a_co;"
83 "uniform vec2 uOffset;"
84 "uniform mat3 uPv;"
85 ""
86 "out vec2 aTexCoords;"
87 ""
88 "void main()"
89 "{"
90 // Create texture coords
91 "aTexCoords = a_co;"
92
93 // Vertex transform
94 "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
95 "gl_Position = vec4( uPv * worldpos, 1.0 );"
96 "}",
97
98 // FRAGMENT
99 "out vec4 FragColor;"
100 ""
101 "uniform sampler2D uTexMain;"
102 "uniform vec3 uColour;"
103 ""
104 "in vec2 aTexCoords;"
105 ""
106 "void main()"
107 "{"
108 "vec4 glyph = texture( uTexMain, aTexCoords );"
109 "FragColor = vec4( uColour + glyph.rgb * 0.2, glyph.a );"
110 "}"
111 ,
112 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" })
113 )
114
115 SHADER_DEFINE( shader_tile_main,
116 // VERTEX
117 "layout (location=0) in vec2 a_co;"
118 "uniform vec4 uOffset;" // Tile x/y, uv x/y
119 "uniform mat3 uPv;"
120 "uniform mat2 uSubTransform;"
121 ""
122 "out vec4 aTexCoords;"
123 "out vec2 aWorldCoords;"
124 ""
125 "vec2 hash22(vec2 p)"
126 "{"
127 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
128 "p3 += dot(p3, p3.yzx+33.33);"
129 "return fract((p3.xx+p3.yz)*p3.zy);"
130 "}"
131 ""
132 "void main()"
133 "{"
134 // Vertex transform
135 "vec2 subtransform = uSubTransform * (a_co-0.5) + 0.5;"
136 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
137 "gl_Position = vec4( uPv * worldpos, 1.0 );"
138
139 // Create texture coords
140 "vec2 random_offset = floor(hash22(uOffset.xy) * 4.0) * 0.25;"
141 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
142 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
143 "aWorldCoords = worldpos.xy;"
144 "}",
145
146 // FRAGMENT
147 "out vec4 FragColor;"
148 ""
149 "uniform sampler2D uTexGlyphs;"
150 "uniform sampler2D uTexWood;"
151 "uniform float uGhost;"
152 "uniform vec2 uMousePos;"
153 "uniform vec4 uColour;"
154 ""
155 "in vec4 aTexCoords;"
156 "in vec2 aWorldCoords;"
157 ""
158 "void main()"
159 "{"
160 "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 );"
161 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
162 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
163 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
164 "vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );"
165
166 "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
167
168 "vec4 output_regular = vec4( wood_comp * shadows, glyph.b );"
169
170 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
171 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
172
173 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
174 "}"
175 ,
176 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour" })
177 )
178
179 void vg_register(void)
180 {
181 SHADER_INIT( shader_tile_colour );
182 SHADER_INIT( shader_tile_main );
183 SHADER_INIT( shader_ball );
184 }