mirror of
https://github.com/Ed94/VEFontCache-Odin.git
synced 2025-08-06 06:52:44 -07:00
Updating shaders
This commit is contained in:
@@ -1,48 +1,51 @@
|
|||||||
@module blit_atlas
|
@module ve_blit_atlas
|
||||||
|
|
||||||
@header package ve_sokol
|
@header package sectr
|
||||||
@header import sg "thirdparty:sokol/gfx"
|
@header import sg "thirdparty:sokol/gfx"
|
||||||
|
|
||||||
@vs blit_atlas_vs
|
@vs ve_blit_atlas_vs
|
||||||
@include ./source_shared.shdc.glsl
|
@include ./ve_source_shared.shdc.glsl
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@fs blit_atlas_fs
|
@fs ve_blit_atlas_fs
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
out vec4 frag_color;
|
out vec4 frag_color;
|
||||||
|
|
||||||
layout(binding = 0) uniform texture2D blit_atlas_src_texture;
|
layout(binding = 0) uniform texture2D ve_blit_atlas_src_texture;
|
||||||
layout(binding = 0) uniform sampler blit_atlas_src_sampler;
|
layout(binding = 0) uniform sampler ve_blit_atlas_src_sampler;
|
||||||
|
|
||||||
layout(binding = 0) uniform blit_atlas_fs_params {
|
layout(binding = 0) uniform ve_blit_atlas_fs_params {
|
||||||
int region;
|
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 =
|
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( ve_blit_atlas_src_texture, ve_blit_atlas_src_sampler ), uv + vec2( 0.0f, 0.0f ) * texture_size ).x * down_sample
|
||||||
+ texture(sampler2D( blit_atlas_src_texture, blit_atlas_src_sampler ), uv + vec2( 0.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, 1.0f ) * texture_size ).x * down_sample
|
||||||
+ texture(sampler2D( blit_atlas_src_texture, blit_atlas_src_sampler ), uv + vec2( 1.0f, 0.0f ) * texture_size ).x * down_sample_scale
|
+ 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( 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( 1.0f, 1.0f ) * texture_size ).x * down_sample;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
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 );
|
||||||
const vec2 texture_size = 1.0f / vec2( 2048.0f, 512.0f ); // VEFontCache.Context.buffer_width/buffer_height
|
const vec2 texture_size = 1.0f / glyph_buffer_size;
|
||||||
if ( region == 0 || region == 1 || region == 2 )
|
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 =
|
float alpha =
|
||||||
down_sample( uv + vec2( -1.0f, -1.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( uv + vec2( 0.5f, -1.5f ) * texture_size, texture_size ) * down_sample_scale
|
+ down_sample_to_texture( uv + vec2( 0.5f, -1.5f ) * texture_size, texture_size ) * down_sample
|
||||||
+ down_sample( uv + vec2( -1.5f, 0.5f ) * texture_size, texture_size ) * down_sample_scale
|
+ down_sample_to_texture( uv + vec2( -1.5f, 0.5f ) * texture_size, texture_size ) * down_sample
|
||||||
+ down_sample( uv + vec2( 0.5f, 0.5f ) * texture_size, texture_size ) * down_sample_scale;
|
+ 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 );
|
frag_color = vec4( 1.0f, 1.0f, 1.0f, alpha );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -52,4 +55,4 @@ void main()
|
|||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@program blit_atlas blit_atlas_vs blit_atlas_fs
|
@program ve_blit_atlas ve_blit_atlas_vs ve_blit_atlas_fs
|
||||||
|
@@ -1,51 +1,48 @@
|
|||||||
@module draw_text
|
@module ve_draw_text
|
||||||
|
|
||||||
@header package ve_sokol
|
@header package sectr
|
||||||
@header import sg "thirdparty:sokol/gfx"
|
@header import sg "thirdparty:sokol/gfx"
|
||||||
|
|
||||||
@vs draw_text_vs
|
@vs ve_draw_text_vs
|
||||||
in vec2 v_position;
|
in vec2 v_position;
|
||||||
in vec2 v_texture;
|
in vec2 v_texture;
|
||||||
out vec2 uv;
|
out vec2 uv;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
#if SOKOL_GLSL
|
uv = vec2( v_texture.x, 1 - v_texture.y );
|
||||||
uv = vec2( v_texture.x, v_texture.y );
|
|
||||||
#else
|
|
||||||
uv = vec2( v_texture.x, 1.0 - v_texture.y );
|
|
||||||
#endif
|
|
||||||
gl_Position = vec4( v_position * 2.0f - 1.0f, 0.0f, 1.0f );
|
gl_Position = vec4( v_position * 2.0f - 1.0f, 0.0f, 1.0f );
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@fs draw_text_fs
|
@fs ve_draw_text_fs
|
||||||
in vec2 uv;
|
in vec2 uv;
|
||||||
out vec4 frag_color;
|
out vec4 frag_color;
|
||||||
|
|
||||||
layout(binding = 0) uniform texture2D draw_text_src_texture;
|
layout(binding = 0) uniform texture2D ve_draw_text_src_texture;
|
||||||
layout(binding = 0) uniform sampler draw_text_src_sampler;
|
layout(binding = 0) uniform sampler ve_draw_text_src_sampler;
|
||||||
|
|
||||||
layout(binding = 0) uniform draw_text_fs_params {
|
layout(binding = 0) uniform ve_draw_text_fs_params {
|
||||||
int down_sample;
|
vec2 glyph_buffer_size;
|
||||||
vec4 colour;
|
float over_sample;
|
||||||
|
vec4 colour;
|
||||||
};
|
};
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float alpha = texture(sampler2D( draw_text_src_texture, draw_text_src_sampler ), uv ).x;
|
float alpha = texture(sampler2D( ve_draw_text_src_texture, ve_draw_text_src_sampler ), uv ).x;
|
||||||
if ( down_sample == 1 )
|
|
||||||
{
|
// const vec2 texture_size = 1.0f / vec2( 2048.0f, 512.0f );
|
||||||
// TODO(Ed): The original author made these consts, I want to instead expose as uniforms...
|
const vec2 texture_size = glyph_buffer_size;
|
||||||
const vec2 texture_size = 1.0f / vec2( 2048.0f, 512.0f ); // VEFontCache.Context.buffer_width/buffer_height
|
const float down_sample = 1.0f / over_sample;
|
||||||
alpha =
|
|
||||||
(texture(sampler2D( draw_text_src_texture, draw_text_src_sampler), uv + vec2( -0.5f, -0.5f) * texture_size ).x * 0.25f)
|
alpha =
|
||||||
+ (texture(sampler2D( draw_text_src_texture, draw_text_src_sampler), uv + vec2( -0.5f, 0.5f) * texture_size ).x * 0.25f)
|
(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( draw_text_src_texture, draw_text_src_sampler), uv + vec2( 0.5f, -0.5f) * texture_size ).x * 0.25f)
|
+ (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( draw_text_src_texture, draw_text_src_sampler), uv + vec2( 0.5f, 0.5f) * texture_size ).x * 0.25f);
|
+ (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 );
|
frag_color = vec4( colour.xyz, colour.a * alpha );
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@program draw_text draw_text_vs draw_text_fs
|
@program ve_draw_text ve_draw_text_vs ve_draw_text_fs
|
||||||
|
Reference in New Issue
Block a user