Skip to content

Commit b0eeb15

Browse files
author
HarshKhandeparkar
committed
v0.6.2
1 parent 54945a8 commit b0eeb15

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

dist/gpujs-real-renderer-browser.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -658,24 +658,22 @@
658658
var yDist = (y - y1);
659659
var dist = Math.sqrt(xDist * xDist + yDist * yDist);
660660
var graphColor = graphPixels[this.thread.y][this.thread.x];
661-
if (dist <= brushSize + 1) {
662-
var intensity = 0;
663-
// The following code basically blurs the line by convolving a simple average kernel
664-
// Very crude implementation of https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-22-fast-prefiltered-lines
665-
for (var i = x - 1; i <= x + 1; i++) {
666-
for (var j = y - 1; j <= y + 1; j++) {
667-
var xDist_1 = (i - x1);
668-
var yDist_1 = (j - y1);
669-
var dist_1 = Math.sqrt(Math.pow(xDist_1, 2) + Math.pow(yDist_1, 2));
670-
intensity += (1 / 9) * Math.min(1, Math.floor(brushSize / dist_1));
671-
}
672-
}
661+
if (dist >= brushSize &&
662+
dist <= brushSize + 1) {
663+
var intensity = Math.max(0, 1 - (dist - brushSize));
673664
return [
674665
brushColor[0] * intensity + graphColor[0] * (1 - intensity),
675666
brushColor[1] * intensity + graphColor[1] * (1 - intensity),
676667
brushColor[2] * intensity + graphColor[2] * (1 - intensity)
677668
];
678669
}
670+
else if (dist < brushSize) {
671+
return [
672+
brushColor[0],
673+
brushColor[1],
674+
brushColor[2]
675+
];
676+
}
679677
else
680678
return graphColor;
681679
}, {
@@ -710,7 +708,7 @@
710708
* @param yOffset
711709
*/
712710
function getInterpolateKernel(gpu, dimensions, xScaleFactor, yScaleFactor, xOffset, yOffset) {
713-
return gpu.createKernel("function(\n graphPixels,\n val1,\n val2,\n lineThickness,\n lineColor\n ) {\n const x = this.thread.x,\n y = this.thread.y;\n\n const outX = this.output.x, outY = this.output.y;\n\n const x1 = (val1[0] * this.constants.xScaleFactor) + outX * (this.constants.yOffset / 100);\n const y1 = (val1[1] * this.constants.yScaleFactor) + outY * (this.constants.xOffset / 100);\n\n const x2 = (val2[0] * this.constants.xScaleFactor) + outX * (this.constants.yOffset / 100);\n const y2 = (val2[1] * this.constants.yScaleFactor) + outY * (this.constants.xOffset / 100);\n\n let lineEqn = x * (y1 - y2) - x1 * (y1 - y2) - y * (x1 - x2) + y1 * (x1 - x2);\n let lineDist = Math.abs(lineEqn) / Math.sqrt((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));\n\n const lineSine = Math.abs(\n (y2 - y1) /\n Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n )\n\n const lineCosine = Math.abs(\n (x2 - x1) /\n Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n )\n\n const graphColor = graphPixels[this.thread.y][this.thread.x];\n\n if (\n (\n lineDist <= lineThickness + 1 &&\n x <= Math.max(x1, x2) + (lineThickness + 1) * lineSine &&\n x >= Math.min(x1, x2) - (lineThickness + 1) * lineSine &&\n y <= Math.max(y1, y2) + (lineThickness + 1) * lineCosine &&\n y >= Math.min(y1, y2) - (lineThickness + 1) * lineCosine\n )\n ) {\n let intensity = 0;\n\n // The following code basically blurs the line by convolving a simple average kernel\n // Very crude implementation of https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-22-fast-prefiltered-lines\n for (let i = x - 1; i <= x + 1; i++) {\n for (let j = y - 1; j <= y + 1; j++) {\n let lineEqn = i * (y1 - y2) - x1 * (y1 - y2) - j * (x1 - x2) + y1 * (x1 - x2);\n let lineDist = Math.abs(lineEqn) / Math.sqrt((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));\n\n intensity += (1 / 9) * Math.min(\n 1,\n Math.floor(lineThickness / lineDist)\n )\n }\n }\n\n return [\n lineColor[0] * intensity + graphColor[0] * (1 - intensity),\n lineColor[1] * intensity + graphColor[1] * (1 - intensity),\n lineColor[2] * intensity + graphColor[2] * (1 - intensity)\n ]\n }\n else return graphColor;\n }", {
711+
return gpu.createKernel("function(\n graphPixels,\n val1,\n val2,\n lineThickness,\n lineColor\n ) {\n const x = this.thread.x,\n y = this.thread.y;\n\n const outX = this.output.x, outY = this.output.y;\n\n const x1 = (val1[0] * this.constants.xScaleFactor) + outX * (this.constants.yOffset / 100);\n const y1 = (val1[1] * this.constants.yScaleFactor) + outY * (this.constants.xOffset / 100);\n\n const x2 = (val2[0] * this.constants.xScaleFactor) + outX * (this.constants.yOffset / 100);\n const y2 = (val2[1] * this.constants.yScaleFactor) + outY * (this.constants.xOffset / 100);\n\n let lineEqn = x * (y1 - y2) - x1 * (y1 - y2) - y * (x1 - x2) + y1 * (x1 - x2);\n let lineDist = Math.abs(lineEqn) / Math.sqrt((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));\n\n const lineSine = Math.abs(\n (y2 - y1) /\n Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n )\n\n const lineCosine = Math.abs(\n (x2 - x1) /\n Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)\n )\n\n const graphColor = graphPixels[this.thread.y][this.thread.x];\n\n if (\n lineDist >= lineThickness &&\n lineDist <= lineThickness + 1 &&\n x <= Math.max(x1, x2) + (lineThickness) * lineSine &&\n x >= Math.min(x1, x2) - (lineThickness) * lineSine &&\n y <= Math.max(y1, y2) + (lineThickness) * lineCosine &&\n y >= Math.min(y1, y2) - (lineThickness) * lineCosine\n ) {\n let intensity = Math.max(0, 1 - (lineDist - lineThickness));\n\n return [\n lineColor[0] * intensity + graphColor[0] * (1 - intensity),\n lineColor[1] * intensity + graphColor[1] * (1 - intensity),\n lineColor[2] * intensity + graphColor[2] * (1 - intensity)\n ]\n }\n else if (\n lineDist < lineThickness &&\n x <= Math.max(x1, x2) + (lineThickness) * lineSine &&\n x >= Math.min(x1, x2) - (lineThickness) * lineSine &&\n y <= Math.max(y1, y2) + (lineThickness) * lineCosine &&\n y >= Math.min(y1, y2) - (lineThickness) * lineCosine\n ) {\n return [\n lineColor[0],\n lineColor[1],\n lineColor[2]\n ]\n }\n else return graphColor;\n }", {
714712
output: dimensions,
715713
pipeline: true,
716714
constants: {

0 commit comments

Comments
 (0)