Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP, ON HOLD] Add opacity aesthetic #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Aesthetic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1035,6 +1053,11 @@ class StatefulY0 extends StatefulAesthetic<Y0> {
return Y0;
}
}
class Opacity extends StatefulAesthetic<Opacity> {
get Factory() {
return Opacity;
}
}
Comment on lines +1056 to +1060
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a naming conflict between the two Opacity class definitions. To maintain consistency with the codebase's naming pattern (as seen with StatefulSize, StatefulY, etc.), this class should be renamed to StatefulOpacity.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

class StatefulSize extends StatefulAesthetic<Size> {
get Factory() {
return Size;
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 30 additions & 8 deletions src/glsl/general.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1146,6 +1149,7 @@ void main() {
return;
}

// note:
float size_multiplier = texture_float_lookup(
u_size_domain,
u_size_range,
Expand All @@ -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);

Expand Down Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions src/regl_rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ export class ReglRenderer<T extends Tile> 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,
Expand Down Expand Up @@ -887,6 +888,7 @@ export class ReglRenderer<T extends Tile> extends Renderer {
'x0',
'y0',
'jitter_speed',
'opacity',
'size',
'filter',
'filter2',
Expand Down Expand Up @@ -956,6 +958,7 @@ export class ReglRenderer<T extends Tile> extends Renderer {
'x0',
'y0',
'size',
'opacity',
'jitter_radius',
'jitter_speed',
'filter',
Expand Down