1 vg_tex2d tex_tile_data
= { .path
= "textures/tileset.png" };
2 vg_tex2d tex_tile_detail
= { .path
= "textures/tile_overlays.png" };
3 vg_tex2d tex_wood
= { .path
= "textures/wood.png" };
4 vg_tex2d tex_ball
= { .path
= "textures/ball.png", .flags
= VG_TEXTURE_CLAMP
};
6 vg_tex2d
*texture_list
[] = { &tex_tile_detail
, &tex_tile_data
, &tex_wood
, &tex_ball
};
8 sfx_system_t audio_system_sfx
=
14 .vol_src
= &g_vol_sfx
,
16 .fadeout
= FADEOUT_LENGTH
,
20 sfx_set_t audio_tile_mod
=
32 static void resource_load_main(void)
35 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
38 sfx_set_init( &audio_tile_mod
, NULL
);
41 static void resource_free_main(void)
43 vg_tex2d_free( texture_list
, vg_list_size( texture_list
) );
44 sfx_set_free( &audio_tile_mod
);
48 // ===========================================================================================================
50 SHADER_DEFINE( shader_tile_colour
,
53 "layout (location=0) in vec2 a_co;"
55 "uniform vec3 uOffset;"
59 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
64 "uniform vec4 uColour;"
68 "FragColor = uColour;"
71 UNIFORMS({ "uPv", "uOffset", "uColour" })
74 SHADER_DEFINE( shader_ball
,
76 "layout (location=0) in vec2 a_co;"
77 "uniform vec2 uOffset;"
80 "out vec2 aTexCoords;"
84 // Create texture coords
88 "vec3 worldpos = vec3( a_co * 0.5 - 0.25 + uOffset, 1.0 );"
89 "gl_Position = vec4( uPv * worldpos, 1.0 );"
95 "uniform sampler2D uTexMain;"
96 "uniform vec3 uColour;"
102 "vec4 glyph = texture( uTexMain, aTexCoords );"
103 "FragColor = vec4( uColour + glyph.rgb * 0.2, glyph.a );"
106 UNIFORMS({ "uTexMain", "uColour", "uOffset", "uPv" })
109 SHADER_DEFINE( shader_tile_main
,
111 "layout (location=0) in vec2 a_co;"
112 "uniform vec4 uOffset;" // Tile x/y, uv x/y
114 "uniform mat2 uSubTransform;"
116 "out vec4 aTexCoords;"
117 "out vec2 aWorldCoords;"
119 "vec2 hash22(vec2 p)"
121 "vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));"
122 "p3 += dot(p3, p3.yzx+33.33);"
123 "return fract((p3.xx+p3.yz)*p3.zy);"
129 "vec2 subtransform = uSubTransform * (a_co-0.5) + 0.5;"
130 "vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );"
131 "gl_Position = vec4( uPv * worldpos, 1.0 );"
133 // Create texture coords
134 "vec2 random_offset = floor(hash22(uOffset.xy) * 4.0) * 0.25;"
135 "vec2 edge_safe_coords = a_co * 0.98 + 0.01;"
136 "aTexCoords = vec4((edge_safe_coords + uOffset.zw) * 0.25, edge_safe_coords * 0.25 + random_offset );"
137 "aWorldCoords = worldpos.xy;"
141 "out vec4 FragColor;"
143 "uniform sampler2D uTexGlyphs;"
144 "uniform sampler2D uTexWood;"
145 "uniform float uGhost;"
146 "uniform vec2 uMousePos;"
147 "uniform vec4 uColour;"
149 "in vec4 aTexCoords;"
150 "in vec2 aWorldCoords;"
154 "vec3 shadowing_colour = vec3( 0.93, 0.88536, 0.8184 );"
155 "vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );"
156 "vec4 wood = texture( uTexWood, aTexCoords.zw );"
157 "vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );"
158 "vec3 wood_comp = mix( wood_secondary.rgb * shadowing_colour, wood.rgb, clamp( glyph.b * 2.0 - 1.0, 0.0, 1.0 ) );"
160 "vec3 shadows = mix( vec3( 0.85, 0.7344, 0.561 ), vec3(1.0,1.0,1.0), glyph.r );"
162 "vec4 output_regular = vec4( wood_comp * shadows, glyph.b );"
164 "float ghost_dist = clamp( 1.5 - distance(uMousePos, aWorldCoords), 0.0, 1.0 );"
165 "vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g * ghost_dist );"
167 "FragColor = mix( output_regular, output_ghost, uGhost ) * uColour;"
170 UNIFORMS({ "uPv", "uOffset", "uTexGlyphs", "uTexWood", "uSubTransform", "uGhost", "uMousePos", "uColour" })
173 void vg_register(void)
175 SHADER_INIT( shader_tile_colour
);
176 SHADER_INIT( shader_tile_main
);
177 SHADER_INIT( shader_ball
);