@ -16,7 +16,7 @@ const sdf_vs_src = `#version 300 es
@@ -16,7 +16,7 @@ const sdf_vs_src = `#version 300 es
out vec3 v _color ;
flat out vec2 v _thickness ;
out float v _scalefade ;
void main ( ) {
vec2 screen02 ;
@ -31,7 +31,12 @@ const sdf_vs_src = `#version 300 es
@@ -31,7 +31,12 @@ const sdf_vs_src = `#version 300 es
int stroke _data _y = stroke _index / u _stroke _texture _size ;
int stroke _data _x = stroke _index % u _stroke _texture _size ;
uvec4 stroke _data = texelFetch ( u _stroke _data , ivec2 ( stroke _data _x , stroke _data _y ) , 0 ) ;
float radius = float ( stroke _data . w ) ;
float canvas _pixel = 1.0 / u _scale . x ; // assuming square pixels here..
float radius = max ( 0.5 * canvas _pixel , float ( stroke _data . w ) ) ;
// Fade from 1.0 to 0.0 based on sqrt distance beyond being 1 pixel wide? (compeltely ad-hoc, picked whatever looked good to me)
float scalefade = float ( stroke _data . w ) / canvas _pixel ;
v _scalefade = min ( 1.0 , sqrt ( scalefade ) ) ;
vec2 pos ;
@ -80,12 +85,13 @@ const sdf_fs_src = `#version 300 es
@@ -80,12 +85,13 @@ const sdf_fs_src = `#version 300 es
uniform float u _opacity _multipliter ;
in vec3 v _color ;
in float v _scalefade ;
layout ( location = 0 ) out vec4 FragColor ;
void main ( ) {
if ( u _debug _mode == 0 ) {
float alpha = 0.75 * u _opacity _multipliter ;
float alpha = u _opacity _multipliter * v _scalefade ;
FragColor = vec4 ( v _color * alpha , alpha ) ;
} else {
FragColor = vec4 ( u _debug _color , 0.8 ) ;
@ -382,12 +388,12 @@ function init_webgl(state, context) {
@@ -382,12 +388,12 @@ function init_webgl(state, context) {
gl . bindTexture ( gl . TEXTURE _2D , context . textures [ 'dynamic_stroke_data' ] ) ;
gl . texParameteri ( gl . TEXTURE _2D , gl . TEXTURE _MIN _FILTER , gl . NEAREST ) ;
gl . texParameteri ( gl . TEXTURE _2D , gl . TEXTURE _MAG _FILTER , gl . NEAREST ) ;
gl . texImage2D ( gl . TEXTURE _2D , 0 , gl . RGBA16UI , config . stroke _texture _size , config . stroke _texture _size , 0 , gl . RGBA _INTEGER , gl . UNSIGNED _SHORT , new Uint16Array ( config . stroke _texture _size * config . stroke _texture _size * 4 ) ) ; // fill the whole texture once with zeroes to kill a warning about a partial upload
gl . texImage2D ( gl . TEXTURE _2D , 0 , gl . RGBA16UI , config . stroke _texture _size , config . stroke _texture _size , 0 , gl . RGBA _INTEGER , gl . UNSIGNED _SHORT , new Uint16Array ( config . stroke _texture _size * config . stroke _texture _size * 4 ) ) ;
gl . bindTexture ( gl . TEXTURE _2D , context . textures [ 'ui' ] ) ;
gl . texParameteri ( gl . TEXTURE _2D , gl . TEXTURE _MIN _FILTER , gl . NEAREST ) ;
gl . texParameteri ( gl . TEXTURE _2D , gl . TEXTURE _MAG _FILTER , gl . NEAREST ) ;
gl . texImage2D ( gl . TEXTURE _2D , 0 , gl . RGBA16UI , config . ui _texture _size , config . ui _texture _size , 0 , gl . RGBA _INTEGER , gl . UNSIGNED _SHORT , new Uint16Array ( config . ui _texture _size * config . ui _texture _size * 4 ) ) ; // fill the whole texture once with zeroes to kill a warning about a partial upload
gl . texImage2D ( gl . TEXTURE _2D , 0 , gl . RGBA16UI , config . ui _texture _size , config . ui _texture _size , 0 , gl . RGBA _INTEGER , gl . UNSIGNED _SHORT , new Uint16Array ( config . ui _texture _size * config . ui _texture _size * 4 ) ) ;
const resize _canvas = ( entries ) => {
// https://www.khronos.org/webgl/wiki/HandlingHighDPI