diff --git a/backend/sokol/blit_atlas.shdc.glsl b/backend/sokol/blit_atlas.shdc.glsl index de64c33..71992e2 100644 --- a/backend/sokol/blit_atlas.shdc.glsl +++ b/backend/sokol/blit_atlas.shdc.glsl @@ -1,48 +1,51 @@ -@module blit_atlas +@module ve_blit_atlas -@header package ve_sokol +@header package sectr @header import sg "thirdparty:sokol/gfx" -@vs blit_atlas_vs -@include ./source_shared.shdc.glsl +@vs ve_blit_atlas_vs +@include ./ve_source_shared.shdc.glsl @end -@fs blit_atlas_fs +@fs ve_blit_atlas_fs in vec2 uv; out vec4 frag_color; -layout(binding = 0) uniform texture2D blit_atlas_src_texture; -layout(binding = 0) uniform sampler blit_atlas_src_sampler; +layout(binding = 0) uniform texture2D ve_blit_atlas_src_texture; +layout(binding = 0) uniform sampler ve_blit_atlas_src_sampler; -layout(binding = 0) uniform blit_atlas_fs_params { - int region; +layout(binding = 0) uniform ve_blit_atlas_fs_params { + vec2 glyph_buffer_size; + float over_sample; + int region; }; -float down_sample( vec2 uv, vec2 texture_size ) +float down_sample_to_texture( vec2 uv, vec2 texture_size ) { - float down_sample_scale = 1.0f / 4.0f; + float down_sample = 1.0f / over_sample; float value = - texture(sampler2D( blit_atlas_src_texture, blit_atlas_src_sampler ), uv + vec2( 0.0f, 0.0f ) * texture_size ).x * down_sample_scale - + texture(sampler2D( blit_atlas_src_texture, blit_atlas_src_sampler ), uv + vec2( 0.0f, 1.0f ) * texture_size ).x * down_sample_scale - + texture(sampler2D( blit_atlas_src_texture, blit_atlas_src_sampler ), uv + vec2( 1.0f, 0.0f ) * texture_size ).x * down_sample_scale - + texture(sampler2D( blit_atlas_src_texture, blit_atlas_src_sampler ), uv + vec2( 1.0f, 1.0f ) * texture_size ).x * down_sample_scale; + texture(sampler2D( ve_blit_atlas_src_texture, ve_blit_atlas_src_sampler ), uv + vec2( 0.0f, 0.0f ) * texture_size ).x * down_sample + + texture(sampler2D( ve_blit_atlas_src_texture, ve_blit_atlas_src_sampler ), uv + vec2( 0.0f, 1.0f ) * texture_size ).x * down_sample + + texture(sampler2D( ve_blit_atlas_src_texture, ve_blit_atlas_src_sampler ), uv + vec2( 1.0f, 0.0f ) * texture_size ).x * down_sample + + texture(sampler2D( ve_blit_atlas_src_texture, ve_blit_atlas_src_sampler ), uv + vec2( 1.0f, 1.0f ) * texture_size ).x * down_sample; + return value; } void main() { - // TODO(Ed): The original author made these consts, I want to instead expose as uniforms... - const vec2 texture_size = 1.0f / vec2( 2048.0f, 512.0f ); // VEFontCache.Context.buffer_width/buffer_height - if ( region == 0 || region == 1 || region == 2 ) + // const vec2 texture_size = 1.0f / vec2( 2048.0f, 512.0f ); + const vec2 texture_size = 1.0f / glyph_buffer_size; + if ( region == 0 || region == 1 || region == 2 || region == 4 ) { - float down_sample_scale = 1.0f / 4.0f; + float down_sample = 1.0f / over_sample; float alpha = - down_sample( uv + vec2( -1.0f, -1.5f ) * texture_size, texture_size ) * down_sample_scale - + down_sample( uv + vec2( 0.5f, -1.5f ) * texture_size, texture_size ) * down_sample_scale - + down_sample( uv + vec2( -1.5f, 0.5f ) * texture_size, texture_size ) * down_sample_scale - + down_sample( uv + vec2( 0.5f, 0.5f ) * texture_size, texture_size ) * down_sample_scale; + down_sample_to_texture( uv + vec2( -1.0f, -1.5f ) * texture_size, texture_size ) * down_sample + + down_sample_to_texture( uv + vec2( 0.5f, -1.5f ) * texture_size, texture_size ) * down_sample + + down_sample_to_texture( uv + vec2( -1.5f, 0.5f ) * texture_size, texture_size ) * down_sample + + down_sample_to_texture( uv + vec2( 0.5f, 0.5f ) * texture_size, texture_size ) * down_sample; frag_color = vec4( 1.0f, 1.0f, 1.0f, alpha ); } else @@ -52,4 +55,4 @@ void main() } @end -@program blit_atlas blit_atlas_vs blit_atlas_fs +@program ve_blit_atlas ve_blit_atlas_vs ve_blit_atlas_fs diff --git a/backend/sokol/draw_text.shdc.glsl b/backend/sokol/draw_text.shdc.glsl index fa73f4f..1a6dfd6 100644 --- a/backend/sokol/draw_text.shdc.glsl +++ b/backend/sokol/draw_text.shdc.glsl @@ -1,51 +1,48 @@ -@module draw_text +@module ve_draw_text -@header package ve_sokol +@header package sectr @header import sg "thirdparty:sokol/gfx" -@vs draw_text_vs +@vs ve_draw_text_vs in vec2 v_position; in vec2 v_texture; out vec2 uv; void main() { -#if SOKOL_GLSL - uv = vec2( v_texture.x, v_texture.y ); -#else - uv = vec2( v_texture.x, 1.0 - v_texture.y ); -#endif + uv = vec2( v_texture.x, 1 - v_texture.y ); gl_Position = vec4( v_position * 2.0f - 1.0f, 0.0f, 1.0f ); } @end -@fs draw_text_fs +@fs ve_draw_text_fs in vec2 uv; out vec4 frag_color; -layout(binding = 0) uniform texture2D draw_text_src_texture; -layout(binding = 0) uniform sampler draw_text_src_sampler; +layout(binding = 0) uniform texture2D ve_draw_text_src_texture; +layout(binding = 0) uniform sampler ve_draw_text_src_sampler; -layout(binding = 0) uniform draw_text_fs_params { - int down_sample; - vec4 colour; +layout(binding = 0) uniform ve_draw_text_fs_params { + vec2 glyph_buffer_size; + float over_sample; + vec4 colour; }; void main() { - float alpha = texture(sampler2D( draw_text_src_texture, draw_text_src_sampler ), uv ).x; - if ( down_sample == 1 ) - { - // TODO(Ed): The original author made these consts, I want to instead expose as uniforms... - const vec2 texture_size = 1.0f / vec2( 2048.0f, 512.0f ); // VEFontCache.Context.buffer_width/buffer_height - alpha = - (texture(sampler2D( draw_text_src_texture, draw_text_src_sampler), uv + vec2( -0.5f, -0.5f) * texture_size ).x * 0.25f) - + (texture(sampler2D( draw_text_src_texture, draw_text_src_sampler), uv + vec2( -0.5f, 0.5f) * texture_size ).x * 0.25f) - + (texture(sampler2D( draw_text_src_texture, draw_text_src_sampler), uv + vec2( 0.5f, -0.5f) * texture_size ).x * 0.25f) - + (texture(sampler2D( draw_text_src_texture, draw_text_src_sampler), uv + vec2( 0.5f, 0.5f) * texture_size ).x * 0.25f); - } + float alpha = texture(sampler2D( ve_draw_text_src_texture, ve_draw_text_src_sampler ), uv ).x; + + // const vec2 texture_size = 1.0f / vec2( 2048.0f, 512.0f ); + const vec2 texture_size = glyph_buffer_size; + const float down_sample = 1.0f / over_sample; + + alpha = + (texture(sampler2D( ve_draw_text_src_texture, ve_draw_text_src_sampler), uv + vec2( -0.5f, -0.5f) * texture_size ).x * down_sample) + + (texture(sampler2D( ve_draw_text_src_texture, ve_draw_text_src_sampler), uv + vec2( -0.5f, 0.5f) * texture_size ).x * down_sample) + + (texture(sampler2D( ve_draw_text_src_texture, ve_draw_text_src_sampler), uv + vec2( 0.5f, -0.5f) * texture_size ).x * down_sample) + + (texture(sampler2D( ve_draw_text_src_texture, ve_draw_text_src_sampler), uv + vec2( 0.5f, 0.5f) * texture_size ).x * down_sample); frag_color = vec4( colour.xyz, colour.a * alpha ); } @end -@program draw_text draw_text_vs draw_text_fs +@program ve_draw_text ve_draw_text_vs ve_draw_text_fs