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

feat: density-based point size #143

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
Fix relative point offset
  • Loading branch information
flekschas committed May 30, 2023
commit ff67faa22f7186673bec945e1180c43358422639
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,8 @@ const createScatterplot = (

const getResolution = () => [canvas.width, canvas.height];
const getMinHalfResolution = () => Math.min(canvas.width, canvas.height) / 2;
const getPointRelMagnitude = () =>
0.25 / Math.min(canvas.width, canvas.height) / 2;
const getRelativePointOffset = () =>
0.5 / camera.scaling[0] / Math.min(canvas.width, canvas.height);
const getBackgroundImage = () => backgroundImage;
const getColorTex = () => colorTex;
const getColorTexRes = () => colorTexRes;
Expand Down Expand Up @@ -1615,7 +1615,7 @@ const createScatterplot = (
uniforms: {
resolution: getResolution,
minHalfResolution: getMinHalfResolution,
pointRelMagnitude: getPointRelMagnitude,
relativePointOffset: getRelativePointOffset,
modelViewProjection: getModelViewProjection,
devicePixelRatio: getDevicePixelRatio,
pointScale: getPointScale,
Expand Down
10 changes: 5 additions & 5 deletions src/point.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const FRAGMENT_SHADER = `
precision highp float;

uniform float pointRelMagnitude;
uniform float relativePointOffset;
uniform float minHalfResolution;

varying vec4 vColor;
Expand All @@ -16,10 +16,10 @@ vec4 sample(float d2, float r2) {
}

void main() {
vec2 p1 = vPosition + vec2(-pointRelMagnitude, +pointRelMagnitude);
vec2 p2 = vPosition + vec2(+pointRelMagnitude, +pointRelMagnitude);
vec2 p3 = vPosition + vec2(+pointRelMagnitude, -pointRelMagnitude);
vec2 p4 = vPosition + vec2(-pointRelMagnitude, -pointRelMagnitude);
vec2 p1 = vPosition + vec2(-relativePointOffset, +relativePointOffset);
vec2 p2 = vPosition + vec2(+relativePointOffset, +relativePointOffset);
vec2 p3 = vPosition + vec2(+relativePointOffset, -relativePointOffset);
vec2 p4 = vPosition + vec2(-relativePointOffset, -relativePointOffset);
float d1 = dot(p1, p1);
float d2 = dot(p2, p2);
float d3 = dot(p3, p3);
Expand Down