diff --git a/src/Aesthetic.ts b/src/Aesthetic.ts index f1c383d5b..98c0e4e31 100644 --- a/src/Aesthetic.ts +++ b/src/Aesthetic.ts @@ -609,6 +609,24 @@ abstract class OneDAesthetic extends Aesthetic { abstract class BooleanAesthetic extends Aesthetic {} + +class Opacity extends OneDAesthetic { + static get default_constant() { + return 1; + } + static get_default_domain() { + return [0, 10]; + } + get default_domain() { + return [0, 10]; + } + default_constant = 1; + get default_range(): [number, number] { + return [0, 1]; + } + default_transform: Transform = 'linear'; +} + class Size extends OneDAesthetic { static get default_constant() { return 1.5; @@ -1035,6 +1053,11 @@ class StatefulY0 extends StatefulAesthetic { return Y0; } } +class Opacity extends StatefulAesthetic { + get Factory() { + return Opacity; + } +} class StatefulSize extends StatefulAesthetic { get Factory() { return Size; @@ -1075,6 +1098,7 @@ export const stateful_aesthetics: Record< y: StatefulY, y0: StatefulY0, size: StatefulSize, + opacity: StatefulOpacity, jitter_speed: StatefulJitter_speed, jitter_radius: StatefulJitter_radius, color: StatefulColor, diff --git a/src/glsl/general.vert b/src/glsl/general.vert index abd12cf1a..a8f292661 100644 --- a/src/glsl/general.vert +++ b/src/glsl/general.vert @@ -72,7 +72,7 @@ bool a_last_color_is_constant; /* python code to generate what follows. def autogenerate_code(): - ks = ["x", "y", "jitter_radius", "jitter_speed", "size", "filter1", "filter2", "x0", "y0"] + ks = ["x", "y", "jitter_radius", "jitter_speed", "size", "opacity", "filter1", "filter2", "x0", "y0"] times = ["", "last_"] print(""" // BEGIN AUTOGENERATED. DO NOT EDIT. @@ -196,14 +196,14 @@ autogenerate_code() bool a_last_jitter_speed_is_constant; - uniform float u_size_buffer_num; - uniform float u_size_constant; - uniform float u_size_transform; - uniform vec2 u_size_domain; - uniform vec2 u_size_range; - uniform float u_size_map_position; + uniform float u_size_buffer_num; // ie where to find the vlaue of size within the buffer + uniform float u_size_constant; // default + uniform float u_size_transform; // eg "log" + uniform vec2 u_size_domain; // eg [1, 100] + uniform vec2 u_size_range; + uniform float u_size_map_position; // maps the pixel buffer of categorical variables to their value/encoding(?) float a_size; - bool a_size_is_constant; + bool a_size_is_constant; // use constant? uniform float u_last_size_buffer_num; @@ -310,6 +310,7 @@ highp float ix_to_random(in float ix, in float seed) { // The fill color. +// NOTE: these varying's get passed to through fragment shader varying vec4 fill; varying float point_size; @@ -915,6 +916,7 @@ void main() { } if (u_size_buffer_num > -0.5) { + // look: a_size = get_buffer(u_size_buffer_num); a_size_is_constant = false; } else { @@ -995,6 +997,7 @@ void main() { } // END AUTOGENERATED. DO NOT EDIT ABOVE. // ------------------------------------------------ +// NOTE: things with gl_ prefix are magic variables that persist gl_PointSize = 1.; if (u_color_buffer_num > -0.5) { @@ -1146,6 +1149,7 @@ void main() { return; } +// note: float size_multiplier = texture_float_lookup( u_size_domain, u_size_range, @@ -1156,6 +1160,22 @@ void main() { u_last_size_domain, u_last_size_range, u_last_size_transform, a_last_size, u_last_size_map_position); + // we're transitioning between previos & new value via ease + size_multiplier = u_base_size * + mix(last_size_multiplier, size_multiplier, ease); + +// CONVERT TO OPACITY + float size_multiplier = texture_float_lookup( + u_size_domain, + u_size_range, + u_size_transform, a_size, + u_size_map_position); + + float last_size_multiplier = texture_float_lookup( + u_last_size_domain, u_last_size_range, u_last_size_transform, a_last_size, + u_last_size_map_position); + + // we're transitioning between previos & new value via ease size_multiplier = u_base_size * mix(last_size_multiplier, size_multiplier, ease); @@ -1232,6 +1252,8 @@ void main() { run_color_fill(ease); } // gl_PointSize = 2.1; +// toward the end we need to update this somethign like this: + fill.a = fill.a * opacityMultiplier point_size = gl_PointSize; /* if (u_use_glyphset > 0. && point_size > 5.0) { float random_letter = floor(64. * ix_to_random(ix, 1.3)); diff --git a/src/regl_rendering.ts b/src/regl_rendering.ts index 3644c1abf..e78b23009 100644 --- a/src/regl_rendering.ts +++ b/src/regl_rendering.ts @@ -835,6 +835,7 @@ export class ReglRenderer extends Renderer { viewportWidth / viewportHeight, //@ts-ignore u_zoom_balance: regl.prop('zoom_balance'), + // global vs computed size (I think Ben said) u_base_size: (_, { point_size }) => point_size, u_maxix: (_, { max_ix }) => max_ix, u_alpha: (_, { alpha }) => alpha, @@ -887,6 +888,7 @@ export class ReglRenderer extends Renderer { 'x0', 'y0', 'jitter_speed', + 'opacity', 'size', 'filter', 'filter2', @@ -956,6 +958,7 @@ export class ReglRenderer extends Renderer { 'x0', 'y0', 'size', + 'opacity', 'jitter_radius', 'jitter_speed', 'filter',