Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rreusser committed Nov 19, 2021
1 parent 9c5e115 commit 0f47d4f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 1.0.1
## 1.1.0

## Features

Expand Down
2 changes: 1 addition & 1 deletion dist/regl-gpu-lines.compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
};
return regl({
// Insert user GLSL at the top
vert: "".concat(meta.glsl, "\nconst float CAP_START = ").concat(ORIENTATION$2.CAP_START, ".0;\nconst float CAP_END = ").concat(ORIENTATION$2.CAP_END, ".0;\n\n// Attribute specification\n").concat(spec.glsl, "\n\nattribute float index;\n").concat(debug ? 'attribute float debugInstanceID;' : '', "\n\nuniform vec2 vertCnt2, capJoinRes2;\nuniform vec2 resolution, capScale;\nuniform float miterLimit;\n").concat(meta.orientation || !isEndpoints ? '' : 'uniform float orientation;', "\n\nvarying vec3 lineCoord;\n").concat(debug ? 'varying vec2 triStripCoord;' : '', "\n").concat(debug ? 'varying float instanceID;' : '', "\n").concat(debug ? 'varying float vertexIndex;' : '', "\n\n// This turns out not to work very well\n// bool isnan(float val) {\n// return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;\n// }\n\nbool invalid(vec4 p) {\n return p.w == 0.0;\n}\n\nvoid main() {\n const float pi = 3.141592653589793;\n\n bool isRound = ").concat(isRound ? 'true' : 'false', ";\n ").concat(debug ? 'vertexIndex = index;' : '', "\n lineCoord = vec3(0);\n\n ").concat(debug ? "instanceID = ".concat(isEndpoints ? '-1.0' : 'debugInstanceID', ";") : '', "\n ").concat(debug ? 'triStripCoord = vec2(floor(index / 2.0), mod(index, 2.0));' : '', "\n\n ").concat(verts.map(function (vert) {
vert: "".concat(meta.glsl, "\nconst float CAP_START = ").concat(ORIENTATION$2.CAP_START, ".0;\nconst float CAP_END = ").concat(ORIENTATION$2.CAP_END, ".0;\n\n// Attribute specification\n").concat(spec.glsl, "\n\nattribute float index;\n").concat(debug ? 'attribute float debugInstanceID;' : '', "\n\nuniform vec2 vertCnt2, capJoinRes2;\nuniform vec2 resolution, capScale;\nuniform float miterLimit;\n").concat(meta.orientation || !isEndpoints ? '' : 'uniform float orientation;', "\n\nvarying vec3 lineCoord;\n").concat(debug ? 'varying vec2 triStripCoord;' : '', "\n").concat(debug ? 'varying float instanceID;' : '', "\n").concat(debug ? 'varying float vertexIndex;' : '', "\n\n// This turns out not to work very well\nbool isnan(float val) {\n return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;\n}\n\nbool invalid(vec4 p) {\n return p.w == 0.0 || isnan(p.x);\n}\n\nvoid main() {\n const float pi = 3.141592653589793;\n\n bool isRound = ").concat(isRound ? 'true' : 'false', ";\n ").concat(debug ? 'vertexIndex = index;' : '', "\n lineCoord = vec3(0);\n\n ").concat(debug ? "instanceID = ".concat(isEndpoints ? '-1.0' : 'debugInstanceID', ";") : '', "\n ").concat(debug ? 'triStripCoord = vec2(floor(index / 2.0), mod(index, 2.0));' : '', "\n\n ").concat(verts.map(function (vert) {
return "vec4 p".concat(vert, " = ").concat(meta.position.generate(vert), ";");
}).join('\n'), "\n\n // A sensible default for early returns\n gl_Position = pB;\n\n bool aInvalid = ").concat(isEndpoints ? 'false' : 'invalid(pA)', ";\n bool bInvalid = invalid(pB);\n bool cInvalid = invalid(pC);\n bool dInvalid = invalid(pD);\n\n // Vertex count for each part (first half of join, second (mirrored) half). Note that not all of\n // these vertices may be used, for example if we have enough for a round cap but only draw a miter\n // join.\n vec2 v = vertCnt2 + 3.0;\n\n // Total vertex count\n float N = dot(v, vec2(1));\n\n // If we're past the first half-join and half of the segment, then we swap all vertices and start\n // over from the opposite end.\n bool mirror = index >= v.x;\n\n // When rendering dedicated endoints, this allows us to insert an end cap *alone* (without the attached\n // segment and join)\n ").concat(isEndpoints ? "if (dInvalid && mirror) return;" : '', "\n\n // Convert to screen-pixel coordinates\n // Save w so we can perspective re-multiply at the end to get varyings depth-correct\n float pw = mirror ? pC.w : pB.w;\n ").concat(verts.map(function (v) {
return "p".concat(v, " = vec4(vec3(p").concat(v, ".xy * resolution, p").concat(v, ".z) / p").concat(v, ".w, 1);");
Expand Down
2 changes: 1 addition & 1 deletion dist/regl-gpu-lines.compat.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/regl-gpu-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ ${debug ? 'varying float instanceID;' : ''}
${debug ? 'varying float vertexIndex;' : ''}
// This turns out not to work very well
// bool isnan(float val) {
// return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;
// }
bool isnan(float val) {
return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;
}
bool invalid(vec4 p) {
return p.w == 0.0;
return p.w == 0.0 || isnan(p.x);
}
void main() {
Expand Down
2 changes: 1 addition & 1 deletion dist/regl-gpu-lines.min.js

Large diffs are not rendered by default.

48 changes: 16 additions & 32 deletions docs/multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@
precision highp float;
#pragma lines: attribute vec2 xy;
#pragma lines: attribute float break;
#pragma lines: position = getPosition(xy, break);
#pragma lines: position = getPosition(xy);
#pragma lines: width = getWidth();
#pragma lines: varying vec2 pos = getXY(xy);
// Return w = 0 wherever there's a break
vec4 getPosition(vec2 xy, float isBreak) {
if (isBreak > 0.0) return vec4(0);
vec4 getPosition(vec2 xy) {
return vec4(xy, 0, 1);
}
float getWidth() { return 40.0; }
Expand All @@ -48,6 +45,7 @@
// Turn off depth and turn on blending to make it very clear if we accidentally
// draw end caps twice
depth: { enable: false },
cull: {enable: true, face: 'back'},
blend: {
enable: true,
func: { srcRGB: "src alpha", srcAlpha: 1, dstRGB: "one minus src alpha", dstAlpha: 1 }
Expand All @@ -57,26 +55,21 @@
const n = 31;
const lineCount = 10;

// Detecting NaN in GLSL can be questionable, so we can just be verbose and use a separate
// attribute to indicate breaks.
const positions = [[0,0]];
const isBreak = [1];

function xy (line, i) {
let t = (i / (n - 1) * 2 - 1) * 0.9;
const y = ((line + 0.5) / lineCount * 2 - 1) * 0.9;
return [t, y + 1 / lineCount * Math.sin((t - line * 0.1) * 8.0)];
}

// Start with a break in order to signal a cap
const positions = [[NaN, NaN]];

for (let line = 0; line < lineCount; line++) {
for (let i = 0; i < n; i++) {
positions.push(xy(line, i));
isBreak.push(0);
}

// Add a dummy vertex and signal a break in the line
positions.push([0,0]);
isBreak.push(1);
// Signal a cap after each line
positions.push([NaN, NaN]);
}

// After this, render as normal!
Expand All @@ -86,7 +79,6 @@
vertexCount: positions.length,
vertexAttributes: {
xy: regl.buffer(positions),
break: regl.buffer(new Uint8Array(isBreak))
},
};

Expand Down Expand Up @@ -130,14 +122,11 @@
precision highp float;

#pragma lines: attribute vec2 xy;
#pragma lines: attribute float break;
#pragma lines: position = getPosition(xy, break);
#pragma lines: position = getPosition(xy);
#pragma lines: width = getWidth();
#pragma lines: varying vec2 pos = getXY(xy);

// Return w = 0 wherever there's a break
vec4 getPosition(vec2 xy, float isBreak) {
if (isBreak > 0.0) return vec4(0);
vec4 getPosition(vec2 xy) {
return vec4(xy, 0, 1);
}
float getWidth() { return 40.0; }
Expand All @@ -152,6 +141,7 @@
// Turn off depth and turn on blending to make it very clear if we accidentally
// draw end caps twice
depth: { enable: false },
cull: {enable: true, face: 'back'},
blend: {
enable: true,
func: { srcRGB: "src alpha", srcAlpha: 1, dstRGB: "one minus src alpha", dstAlpha: 1 }
Expand All @@ -161,26 +151,21 @@
const n = 31;
const lineCount = 10;

// Detecting NaN in GLSL can be questionable, so we can just be verbose and use a separate
// attribute to indicate breaks.
const positions = [[0,0]];
const isBreak = [1];

function xy (line, i) {
let t = (i / (n - 1) * 2 - 1) * 0.9;
const y = ((line + 0.5) / lineCount * 2 - 1) * 0.9;
return [t, y + 1 / lineCount * Math.sin((t - line * 0.1) * 8.0)];
}

// Start with a break in order to signal a cap
const positions = [[NaN, NaN]];

for (let line = 0; line < lineCount; line++) {
for (let i = 0; i < n; i++) {
positions.push(xy(line, i));
isBreak.push(0);
}

// Add a dummy vertex and signal a break in the line
positions.push([0,0]);
isBreak.push(1);
// Signal a cap after each line
positions.push([NaN, NaN]);
}

// After this, render as normal!
Expand All @@ -190,7 +175,6 @@
vertexCount: positions.length,
vertexAttributes: {
xy: regl.buffer(positions),
break: regl.buffer(new Uint8Array(isBreak))
},
};

Expand Down
2 changes: 1 addition & 1 deletion docs/tests.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "regl-gpu-lines",
"version": "1.0.1",
"version": "1.1.0",
"description": "Pure GPU instanced, screen-projected lines for regl",
"main": "dist/regl-gpu-lines.min.js",
"repository": {
Expand Down

0 comments on commit 0f47d4f

Please sign in to comment.