@sigma/node-border
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
@@ -217,15 +217,2 @@ 'use strict'; | ||
function getFragmentShader(_ref) { | ||
var borders = _ref.borders; | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec2 v_diffVector;\nvarying float v_aaBorder;\nvarying float v_radius;\n".concat(borders.map(function (_, i) { | ||
return "varying float v_borderSize_".concat(i + 1, ";"); | ||
}).join("\n"), "\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n").concat(borders.map(function (_, i) { | ||
return "varying vec4 v_borderColor_".concat(i + 1, ";"); | ||
}).join("\n"), "\n#endif\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = length(v_diffVector);\n float v_borderSize_0 = v_radius;\n vec4 v_borderColor_0 = transparent;\n\n // No antialiasing for picking mode:\n #ifdef PICKING_MODE\n if (dist > v_radius)\n gl_FragColor = transparent;\n else\n gl_FragColor = v_color;\n\n #else\n if (dist > v_borderSize_0) {\n gl_FragColor = v_borderColor_0;\n } else ").concat(borders.map(function (_, i) { | ||
return "if (dist > v_borderSize_".concat(i, " - v_aaBorder) {\n gl_FragColor = mix(v_borderColor_").concat(i + 1, ", v_borderColor_").concat(i, ", (dist - v_borderSize_").concat(i, " + v_aaBorder) / v_aaBorder);\n } else if (dist > v_borderSize_").concat(i + 1, ") {\n gl_FragColor = v_borderColor_").concat(i + 1, ";\n } else "); | ||
}).join(""), " { /* Nothing to add here */ }\n #endif\n}\n"); | ||
return SHADER; | ||
} | ||
var DEFAULT_BORDER_SIZE_MODE = "relative"; | ||
@@ -254,3 +241,3 @@ var DEFAULT_CREATE_NODE_BORDER_OPTIONS = { | ||
function getVertexShader(_ref) { | ||
function getFragmentShader(_ref) { | ||
var borders = _ref.borders; | ||
@@ -261,44 +248,59 @@ var fillCounts = numberToGLSLFloat(borders.filter(function (_ref2) { | ||
}).length); | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec2 a_position;\nattribute float a_size;\nattribute float a_angle;\n".concat(borders.flatMap(function (_ref3, i) { | ||
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec2 v_diffVector;\nvarying float v_radius;\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n".concat(borders.flatMap(function (_ref3, i) { | ||
var size = _ref3.size; | ||
return "attribute" in size ? ["attribute float a_borderSize_".concat(i + 1, ";")] : []; | ||
return "attribute" in size ? ["varying float v_borderSize_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref4, i) { | ||
var color = _ref4.color; | ||
return "attribute" in color ? ["attribute vec4 a_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\n").concat(borders.flatMap(function (_ref5, i) { | ||
var color = _ref5.color; | ||
return "value" in color ? ["uniform vec4 u_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n\nvarying vec2 v_diffVector;\nvarying float v_aaBorder;\nvarying float v_radius;\n").concat(borders.map(function (_, i) { | ||
return "varying float v_borderSize_".concat(i + 1, ";"); | ||
}).join("\n"), "\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n").concat(borders.map(function (_, i) { | ||
return "varying vec4 v_borderColor_".concat(i + 1, ";"); | ||
}).join("\n"), "\n#endif\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main() {\n float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;\n vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));\n vec2 position = a_position + diffVector;\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_radius = size / 2.0;\n v_aaBorder = u_correctionRatio * 2.0;\n v_diffVector = diffVector;\n\n // Let's first compute the size of \"non-fill\" borders:\n").concat(borders.flatMap(function (_ref6, i) { | ||
var size = _ref6.size; | ||
return "attribute" in color ? ["varying vec4 v_borderColor_".concat(i + 1, ";")] : "value" in color ? ["uniform vec4 u_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n#endif\n\nuniform float u_correctionRatio;\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = length(v_diffVector);\n float aaBorder = 2.0 * u_correctionRatio;\n float v_borderSize_0 = v_radius;\n vec4 v_borderColor_0 = transparent;\n\n // No antialiasing for picking mode:\n #ifdef PICKING_MODE\n if (dist > v_radius)\n gl_FragColor = transparent;\n else {\n gl_FragColor = v_color;\n gl_FragColor.a *= bias;\n }\n #else\n // Sizes:\n").concat(borders.flatMap(function (_ref5, i) { | ||
var size = _ref5.size; | ||
if ("fill" in size) return []; | ||
size = size; | ||
var value = "attribute" in size ? "a_borderSize_".concat(i + 1) : numberToGLSLFloat(size.value); | ||
var value = "attribute" in size ? "v_borderSize_".concat(i + 1) : numberToGLSLFloat(size.value); | ||
var factor = (size.mode || DEFAULT_BORDER_SIZE_MODE) === "pixels" ? "u_correctionRatio" : "v_radius"; | ||
return [" float borderSize_".concat(i + 1, " = ").concat(factor, " * ").concat(value, ";")]; | ||
}).join("\n"), "\n // Now, let's split the remaining space between \"fill\" borders:\n float fillBorderSize = (v_radius - (").concat(borders.flatMap(function (_ref7, i) { | ||
}).join("\n"), "\n // Now, let's split the remaining space between \"fill\" borders:\n float fillBorderSize = (v_radius - (").concat(borders.flatMap(function (_ref6, i) { | ||
var size = _ref6.size; | ||
return !("fill" in size) ? ["borderSize_".concat(i + 1)] : []; | ||
}).join(" + "), ") ) / ").concat(fillCounts, ";\n").concat(borders.flatMap(function (_ref7, i) { | ||
var size = _ref7.size; | ||
return !("fill" in size) ? ["borderSize_".concat(i + 1)] : []; | ||
}).join(" + "), ") ) / ").concat(fillCounts, ";\n").concat(borders.flatMap(function (_ref8, i) { | ||
var size = _ref8.size; | ||
return "fill" in size ? [" float borderSize_".concat(i + 1, " = fillBorderSize;")] : []; | ||
}).join("\n"), "\n\n // Finally, normalize all border sizes, to start from the full size and to end with the smallest:\n float v_borderSize_0 = v_radius;\n").concat(borders.map(function (_, i) { | ||
return " v_borderSize_".concat(i + 1, " = v_borderSize_").concat(i, " - borderSize_").concat(i + 1, ";"); | ||
}).join("\n"), "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n v_color.a *= bias;\n #else\n vec4 v_borderColor_0 = transparent;\n").concat(borders.map(function (_ref9, i) { | ||
var color = _ref9.color; | ||
}).join("\n"), "\n\n // Finally, normalize all border sizes, to start from the full size and to end with the smallest:\n float adjustedBorderSize_0 = v_radius;\n").concat(borders.map(function (_, i) { | ||
return " float adjustedBorderSize_".concat(i + 1, " = adjustedBorderSize_").concat(i, " - borderSize_").concat(i + 1, ";"); | ||
}).join("\n"), "\n\n // Colors:\n vec4 borderColor_0 = transparent;\n").concat(borders.map(function (_ref8, i) { | ||
var color = _ref8.color; | ||
var res = []; | ||
if ("attribute" in color) { | ||
res.push(" v_borderColor_".concat(i + 1, " = a_borderColor_").concat(i + 1, ";")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = v_borderColor_").concat(i + 1, ";")); | ||
} else if ("transparent" in color) { | ||
res.push(" v_borderColor_".concat(i + 1, " = vec4(0.0, 0.0, 0.0, 0.0);")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = vec4(0.0, 0.0, 0.0, 0.0);")); | ||
} else { | ||
res.push(" v_borderColor_".concat(i + 1, " = u_borderColor_").concat(i + 1, ";")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = u_borderColor_").concat(i + 1, ";")); | ||
} | ||
res.push(" v_borderColor_".concat(i + 1, ".a *= bias;")); | ||
res.push(" if (borderSize_".concat(i + 1, " <= 1.0 * u_correctionRatio) { v_borderColor_").concat(i + 1, " = v_borderColor_").concat(i, "; }")); | ||
res.push(" borderColor_".concat(i + 1, ".a *= bias;")); | ||
res.push(" if (borderSize_".concat(i + 1, " <= 1.0 * u_correctionRatio) { borderColor_").concat(i + 1, " = borderColor_").concat(i, "; }")); | ||
return res.join("\n"); | ||
}).join("\n"), "\n if (dist > adjustedBorderSize_0) {\n gl_FragColor = borderColor_0;\n } else ").concat(borders.map(function (_, i) { | ||
return "if (dist > adjustedBorderSize_".concat(i, " - aaBorder) {\n gl_FragColor = mix(borderColor_").concat(i + 1, ", borderColor_").concat(i, ", (dist - adjustedBorderSize_").concat(i, " + aaBorder) / aaBorder);\n } else if (dist > adjustedBorderSize_").concat(i + 1, ") {\n gl_FragColor = borderColor_").concat(i + 1, ";\n } else "); | ||
}).join(""), " { /* Nothing to add here */ }\n #endif\n}\n"); | ||
return SHADER; | ||
} | ||
function getVertexShader(_ref) { | ||
var borders = _ref.borders; | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nattribute vec2 a_position;\nattribute float a_size;\nattribute float a_angle;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\n\nvarying vec2 v_diffVector;\nvarying float v_radius;\n\n#ifdef PICKING_MODE\nattribute vec4 a_id;\nvarying vec4 v_color;\n#else\n".concat(borders.flatMap(function (_ref2, i) { | ||
var size = _ref2.size; | ||
return "attribute" in size ? ["attribute float a_borderSize_".concat(i + 1, ";"), "varying float v_borderSize_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref3, i) { | ||
var color = _ref3.color; | ||
return "attribute" in color ? ["attribute vec4 a_borderColor_".concat(i + 1, ";"), "varying vec4 v_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n#endif\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main() {\n float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;\n vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));\n vec2 position = a_position + diffVector;\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_radius = size / 2.0;\n v_diffVector = diffVector;\n\n #ifdef PICKING_MODE\n v_color = a_id;\n #else\n").concat(borders.flatMap(function (_ref4, i) { | ||
var size = _ref4.size; | ||
return "attribute" in size ? [" v_borderSize_".concat(i + 1, " = a_borderSize_").concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref5, i) { | ||
var color = _ref5.color; | ||
return "attribute" in color ? [" v_borderColor_".concat(i + 1, " = a_borderColor_").concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n #endif\n}\n"); | ||
@@ -305,0 +307,0 @@ return SHADER; |
@@ -217,15 +217,2 @@ 'use strict'; | ||
function getFragmentShader(_ref) { | ||
var borders = _ref.borders; | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec2 v_diffVector;\nvarying float v_aaBorder;\nvarying float v_radius;\n".concat(borders.map(function (_, i) { | ||
return "varying float v_borderSize_".concat(i + 1, ";"); | ||
}).join("\n"), "\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n").concat(borders.map(function (_, i) { | ||
return "varying vec4 v_borderColor_".concat(i + 1, ";"); | ||
}).join("\n"), "\n#endif\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = length(v_diffVector);\n float v_borderSize_0 = v_radius;\n vec4 v_borderColor_0 = transparent;\n\n // No antialiasing for picking mode:\n #ifdef PICKING_MODE\n if (dist > v_radius)\n gl_FragColor = transparent;\n else\n gl_FragColor = v_color;\n\n #else\n if (dist > v_borderSize_0) {\n gl_FragColor = v_borderColor_0;\n } else ").concat(borders.map(function (_, i) { | ||
return "if (dist > v_borderSize_".concat(i, " - v_aaBorder) {\n gl_FragColor = mix(v_borderColor_").concat(i + 1, ", v_borderColor_").concat(i, ", (dist - v_borderSize_").concat(i, " + v_aaBorder) / v_aaBorder);\n } else if (dist > v_borderSize_").concat(i + 1, ") {\n gl_FragColor = v_borderColor_").concat(i + 1, ";\n } else "); | ||
}).join(""), " { /* Nothing to add here */ }\n #endif\n}\n"); | ||
return SHADER; | ||
} | ||
var DEFAULT_BORDER_SIZE_MODE = "relative"; | ||
@@ -254,3 +241,3 @@ var DEFAULT_CREATE_NODE_BORDER_OPTIONS = { | ||
function getVertexShader(_ref) { | ||
function getFragmentShader(_ref) { | ||
var borders = _ref.borders; | ||
@@ -261,44 +248,59 @@ var fillCounts = numberToGLSLFloat(borders.filter(function (_ref2) { | ||
}).length); | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec2 a_position;\nattribute float a_size;\nattribute float a_angle;\n".concat(borders.flatMap(function (_ref3, i) { | ||
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec2 v_diffVector;\nvarying float v_radius;\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n".concat(borders.flatMap(function (_ref3, i) { | ||
var size = _ref3.size; | ||
return "attribute" in size ? ["attribute float a_borderSize_".concat(i + 1, ";")] : []; | ||
return "attribute" in size ? ["varying float v_borderSize_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref4, i) { | ||
var color = _ref4.color; | ||
return "attribute" in color ? ["attribute vec4 a_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\n").concat(borders.flatMap(function (_ref5, i) { | ||
var color = _ref5.color; | ||
return "value" in color ? ["uniform vec4 u_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n\nvarying vec2 v_diffVector;\nvarying float v_aaBorder;\nvarying float v_radius;\n").concat(borders.map(function (_, i) { | ||
return "varying float v_borderSize_".concat(i + 1, ";"); | ||
}).join("\n"), "\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n").concat(borders.map(function (_, i) { | ||
return "varying vec4 v_borderColor_".concat(i + 1, ";"); | ||
}).join("\n"), "\n#endif\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main() {\n float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;\n vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));\n vec2 position = a_position + diffVector;\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_radius = size / 2.0;\n v_aaBorder = u_correctionRatio * 2.0;\n v_diffVector = diffVector;\n\n // Let's first compute the size of \"non-fill\" borders:\n").concat(borders.flatMap(function (_ref6, i) { | ||
var size = _ref6.size; | ||
return "attribute" in color ? ["varying vec4 v_borderColor_".concat(i + 1, ";")] : "value" in color ? ["uniform vec4 u_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n#endif\n\nuniform float u_correctionRatio;\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = length(v_diffVector);\n float aaBorder = 2.0 * u_correctionRatio;\n float v_borderSize_0 = v_radius;\n vec4 v_borderColor_0 = transparent;\n\n // No antialiasing for picking mode:\n #ifdef PICKING_MODE\n if (dist > v_radius)\n gl_FragColor = transparent;\n else {\n gl_FragColor = v_color;\n gl_FragColor.a *= bias;\n }\n #else\n // Sizes:\n").concat(borders.flatMap(function (_ref5, i) { | ||
var size = _ref5.size; | ||
if ("fill" in size) return []; | ||
size = size; | ||
var value = "attribute" in size ? "a_borderSize_".concat(i + 1) : numberToGLSLFloat(size.value); | ||
var value = "attribute" in size ? "v_borderSize_".concat(i + 1) : numberToGLSLFloat(size.value); | ||
var factor = (size.mode || DEFAULT_BORDER_SIZE_MODE) === "pixels" ? "u_correctionRatio" : "v_radius"; | ||
return [" float borderSize_".concat(i + 1, " = ").concat(factor, " * ").concat(value, ";")]; | ||
}).join("\n"), "\n // Now, let's split the remaining space between \"fill\" borders:\n float fillBorderSize = (v_radius - (").concat(borders.flatMap(function (_ref7, i) { | ||
}).join("\n"), "\n // Now, let's split the remaining space between \"fill\" borders:\n float fillBorderSize = (v_radius - (").concat(borders.flatMap(function (_ref6, i) { | ||
var size = _ref6.size; | ||
return !("fill" in size) ? ["borderSize_".concat(i + 1)] : []; | ||
}).join(" + "), ") ) / ").concat(fillCounts, ";\n").concat(borders.flatMap(function (_ref7, i) { | ||
var size = _ref7.size; | ||
return !("fill" in size) ? ["borderSize_".concat(i + 1)] : []; | ||
}).join(" + "), ") ) / ").concat(fillCounts, ";\n").concat(borders.flatMap(function (_ref8, i) { | ||
var size = _ref8.size; | ||
return "fill" in size ? [" float borderSize_".concat(i + 1, " = fillBorderSize;")] : []; | ||
}).join("\n"), "\n\n // Finally, normalize all border sizes, to start from the full size and to end with the smallest:\n float v_borderSize_0 = v_radius;\n").concat(borders.map(function (_, i) { | ||
return " v_borderSize_".concat(i + 1, " = v_borderSize_").concat(i, " - borderSize_").concat(i + 1, ";"); | ||
}).join("\n"), "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n v_color.a *= bias;\n #else\n vec4 v_borderColor_0 = transparent;\n").concat(borders.map(function (_ref9, i) { | ||
var color = _ref9.color; | ||
}).join("\n"), "\n\n // Finally, normalize all border sizes, to start from the full size and to end with the smallest:\n float adjustedBorderSize_0 = v_radius;\n").concat(borders.map(function (_, i) { | ||
return " float adjustedBorderSize_".concat(i + 1, " = adjustedBorderSize_").concat(i, " - borderSize_").concat(i + 1, ";"); | ||
}).join("\n"), "\n\n // Colors:\n vec4 borderColor_0 = transparent;\n").concat(borders.map(function (_ref8, i) { | ||
var color = _ref8.color; | ||
var res = []; | ||
if ("attribute" in color) { | ||
res.push(" v_borderColor_".concat(i + 1, " = a_borderColor_").concat(i + 1, ";")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = v_borderColor_").concat(i + 1, ";")); | ||
} else if ("transparent" in color) { | ||
res.push(" v_borderColor_".concat(i + 1, " = vec4(0.0, 0.0, 0.0, 0.0);")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = vec4(0.0, 0.0, 0.0, 0.0);")); | ||
} else { | ||
res.push(" v_borderColor_".concat(i + 1, " = u_borderColor_").concat(i + 1, ";")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = u_borderColor_").concat(i + 1, ";")); | ||
} | ||
res.push(" v_borderColor_".concat(i + 1, ".a *= bias;")); | ||
res.push(" if (borderSize_".concat(i + 1, " <= 1.0 * u_correctionRatio) { v_borderColor_").concat(i + 1, " = v_borderColor_").concat(i, "; }")); | ||
res.push(" borderColor_".concat(i + 1, ".a *= bias;")); | ||
res.push(" if (borderSize_".concat(i + 1, " <= 1.0 * u_correctionRatio) { borderColor_").concat(i + 1, " = borderColor_").concat(i, "; }")); | ||
return res.join("\n"); | ||
}).join("\n"), "\n if (dist > adjustedBorderSize_0) {\n gl_FragColor = borderColor_0;\n } else ").concat(borders.map(function (_, i) { | ||
return "if (dist > adjustedBorderSize_".concat(i, " - aaBorder) {\n gl_FragColor = mix(borderColor_").concat(i + 1, ", borderColor_").concat(i, ", (dist - adjustedBorderSize_").concat(i, " + aaBorder) / aaBorder);\n } else if (dist > adjustedBorderSize_").concat(i + 1, ") {\n gl_FragColor = borderColor_").concat(i + 1, ";\n } else "); | ||
}).join(""), " { /* Nothing to add here */ }\n #endif\n}\n"); | ||
return SHADER; | ||
} | ||
function getVertexShader(_ref) { | ||
var borders = _ref.borders; | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nattribute vec2 a_position;\nattribute float a_size;\nattribute float a_angle;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\n\nvarying vec2 v_diffVector;\nvarying float v_radius;\n\n#ifdef PICKING_MODE\nattribute vec4 a_id;\nvarying vec4 v_color;\n#else\n".concat(borders.flatMap(function (_ref2, i) { | ||
var size = _ref2.size; | ||
return "attribute" in size ? ["attribute float a_borderSize_".concat(i + 1, ";"), "varying float v_borderSize_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref3, i) { | ||
var color = _ref3.color; | ||
return "attribute" in color ? ["attribute vec4 a_borderColor_".concat(i + 1, ";"), "varying vec4 v_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n#endif\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main() {\n float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;\n vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));\n vec2 position = a_position + diffVector;\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_radius = size / 2.0;\n v_diffVector = diffVector;\n\n #ifdef PICKING_MODE\n v_color = a_id;\n #else\n").concat(borders.flatMap(function (_ref4, i) { | ||
var size = _ref4.size; | ||
return "attribute" in size ? [" v_borderSize_".concat(i + 1, " = a_borderSize_").concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref5, i) { | ||
var color = _ref5.color; | ||
return "attribute" in color ? [" v_borderColor_".concat(i + 1, " = a_borderColor_").concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n #endif\n}\n"); | ||
@@ -305,0 +307,0 @@ return SHADER; |
@@ -213,15 +213,2 @@ import { NodeProgram } from 'sigma/rendering'; | ||
function getFragmentShader(_ref) { | ||
var borders = _ref.borders; | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec2 v_diffVector;\nvarying float v_aaBorder;\nvarying float v_radius;\n".concat(borders.map(function (_, i) { | ||
return "varying float v_borderSize_".concat(i + 1, ";"); | ||
}).join("\n"), "\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n").concat(borders.map(function (_, i) { | ||
return "varying vec4 v_borderColor_".concat(i + 1, ";"); | ||
}).join("\n"), "\n#endif\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = length(v_diffVector);\n float v_borderSize_0 = v_radius;\n vec4 v_borderColor_0 = transparent;\n\n // No antialiasing for picking mode:\n #ifdef PICKING_MODE\n if (dist > v_radius)\n gl_FragColor = transparent;\n else\n gl_FragColor = v_color;\n\n #else\n if (dist > v_borderSize_0) {\n gl_FragColor = v_borderColor_0;\n } else ").concat(borders.map(function (_, i) { | ||
return "if (dist > v_borderSize_".concat(i, " - v_aaBorder) {\n gl_FragColor = mix(v_borderColor_").concat(i + 1, ", v_borderColor_").concat(i, ", (dist - v_borderSize_").concat(i, " + v_aaBorder) / v_aaBorder);\n } else if (dist > v_borderSize_").concat(i + 1, ") {\n gl_FragColor = v_borderColor_").concat(i + 1, ";\n } else "); | ||
}).join(""), " { /* Nothing to add here */ }\n #endif\n}\n"); | ||
return SHADER; | ||
} | ||
var DEFAULT_BORDER_SIZE_MODE = "relative"; | ||
@@ -250,3 +237,3 @@ var DEFAULT_CREATE_NODE_BORDER_OPTIONS = { | ||
function getVertexShader(_ref) { | ||
function getFragmentShader(_ref) { | ||
var borders = _ref.borders; | ||
@@ -257,44 +244,59 @@ var fillCounts = numberToGLSLFloat(borders.filter(function (_ref2) { | ||
}).length); | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec2 a_position;\nattribute float a_size;\nattribute float a_angle;\n".concat(borders.flatMap(function (_ref3, i) { | ||
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec2 v_diffVector;\nvarying float v_radius;\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n".concat(borders.flatMap(function (_ref3, i) { | ||
var size = _ref3.size; | ||
return "attribute" in size ? ["attribute float a_borderSize_".concat(i + 1, ";")] : []; | ||
return "attribute" in size ? ["varying float v_borderSize_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref4, i) { | ||
var color = _ref4.color; | ||
return "attribute" in color ? ["attribute vec4 a_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\n").concat(borders.flatMap(function (_ref5, i) { | ||
var color = _ref5.color; | ||
return "value" in color ? ["uniform vec4 u_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n\nvarying vec2 v_diffVector;\nvarying float v_aaBorder;\nvarying float v_radius;\n").concat(borders.map(function (_, i) { | ||
return "varying float v_borderSize_".concat(i + 1, ";"); | ||
}).join("\n"), "\n\n#ifdef PICKING_MODE\nvarying vec4 v_color;\n#else\n// For normal mode, we use the border colors defined in the program:\n").concat(borders.map(function (_, i) { | ||
return "varying vec4 v_borderColor_".concat(i + 1, ";"); | ||
}).join("\n"), "\n#endif\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main() {\n float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;\n vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));\n vec2 position = a_position + diffVector;\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_radius = size / 2.0;\n v_aaBorder = u_correctionRatio * 2.0;\n v_diffVector = diffVector;\n\n // Let's first compute the size of \"non-fill\" borders:\n").concat(borders.flatMap(function (_ref6, i) { | ||
var size = _ref6.size; | ||
return "attribute" in color ? ["varying vec4 v_borderColor_".concat(i + 1, ";")] : "value" in color ? ["uniform vec4 u_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n#endif\n\nuniform float u_correctionRatio;\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = length(v_diffVector);\n float aaBorder = 2.0 * u_correctionRatio;\n float v_borderSize_0 = v_radius;\n vec4 v_borderColor_0 = transparent;\n\n // No antialiasing for picking mode:\n #ifdef PICKING_MODE\n if (dist > v_radius)\n gl_FragColor = transparent;\n else {\n gl_FragColor = v_color;\n gl_FragColor.a *= bias;\n }\n #else\n // Sizes:\n").concat(borders.flatMap(function (_ref5, i) { | ||
var size = _ref5.size; | ||
if ("fill" in size) return []; | ||
size = size; | ||
var value = "attribute" in size ? "a_borderSize_".concat(i + 1) : numberToGLSLFloat(size.value); | ||
var value = "attribute" in size ? "v_borderSize_".concat(i + 1) : numberToGLSLFloat(size.value); | ||
var factor = (size.mode || DEFAULT_BORDER_SIZE_MODE) === "pixels" ? "u_correctionRatio" : "v_radius"; | ||
return [" float borderSize_".concat(i + 1, " = ").concat(factor, " * ").concat(value, ";")]; | ||
}).join("\n"), "\n // Now, let's split the remaining space between \"fill\" borders:\n float fillBorderSize = (v_radius - (").concat(borders.flatMap(function (_ref7, i) { | ||
}).join("\n"), "\n // Now, let's split the remaining space between \"fill\" borders:\n float fillBorderSize = (v_radius - (").concat(borders.flatMap(function (_ref6, i) { | ||
var size = _ref6.size; | ||
return !("fill" in size) ? ["borderSize_".concat(i + 1)] : []; | ||
}).join(" + "), ") ) / ").concat(fillCounts, ";\n").concat(borders.flatMap(function (_ref7, i) { | ||
var size = _ref7.size; | ||
return !("fill" in size) ? ["borderSize_".concat(i + 1)] : []; | ||
}).join(" + "), ") ) / ").concat(fillCounts, ";\n").concat(borders.flatMap(function (_ref8, i) { | ||
var size = _ref8.size; | ||
return "fill" in size ? [" float borderSize_".concat(i + 1, " = fillBorderSize;")] : []; | ||
}).join("\n"), "\n\n // Finally, normalize all border sizes, to start from the full size and to end with the smallest:\n float v_borderSize_0 = v_radius;\n").concat(borders.map(function (_, i) { | ||
return " v_borderSize_".concat(i + 1, " = v_borderSize_").concat(i, " - borderSize_").concat(i + 1, ";"); | ||
}).join("\n"), "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n v_color.a *= bias;\n #else\n vec4 v_borderColor_0 = transparent;\n").concat(borders.map(function (_ref9, i) { | ||
var color = _ref9.color; | ||
}).join("\n"), "\n\n // Finally, normalize all border sizes, to start from the full size and to end with the smallest:\n float adjustedBorderSize_0 = v_radius;\n").concat(borders.map(function (_, i) { | ||
return " float adjustedBorderSize_".concat(i + 1, " = adjustedBorderSize_").concat(i, " - borderSize_").concat(i + 1, ";"); | ||
}).join("\n"), "\n\n // Colors:\n vec4 borderColor_0 = transparent;\n").concat(borders.map(function (_ref8, i) { | ||
var color = _ref8.color; | ||
var res = []; | ||
if ("attribute" in color) { | ||
res.push(" v_borderColor_".concat(i + 1, " = a_borderColor_").concat(i + 1, ";")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = v_borderColor_").concat(i + 1, ";")); | ||
} else if ("transparent" in color) { | ||
res.push(" v_borderColor_".concat(i + 1, " = vec4(0.0, 0.0, 0.0, 0.0);")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = vec4(0.0, 0.0, 0.0, 0.0);")); | ||
} else { | ||
res.push(" v_borderColor_".concat(i + 1, " = u_borderColor_").concat(i + 1, ";")); | ||
res.push(" vec4 borderColor_".concat(i + 1, " = u_borderColor_").concat(i + 1, ";")); | ||
} | ||
res.push(" v_borderColor_".concat(i + 1, ".a *= bias;")); | ||
res.push(" if (borderSize_".concat(i + 1, " <= 1.0 * u_correctionRatio) { v_borderColor_").concat(i + 1, " = v_borderColor_").concat(i, "; }")); | ||
res.push(" borderColor_".concat(i + 1, ".a *= bias;")); | ||
res.push(" if (borderSize_".concat(i + 1, " <= 1.0 * u_correctionRatio) { borderColor_").concat(i + 1, " = borderColor_").concat(i, "; }")); | ||
return res.join("\n"); | ||
}).join("\n"), "\n if (dist > adjustedBorderSize_0) {\n gl_FragColor = borderColor_0;\n } else ").concat(borders.map(function (_, i) { | ||
return "if (dist > adjustedBorderSize_".concat(i, " - aaBorder) {\n gl_FragColor = mix(borderColor_").concat(i + 1, ", borderColor_").concat(i, ", (dist - adjustedBorderSize_").concat(i, " + aaBorder) / aaBorder);\n } else if (dist > adjustedBorderSize_").concat(i + 1, ") {\n gl_FragColor = borderColor_").concat(i + 1, ";\n } else "); | ||
}).join(""), " { /* Nothing to add here */ }\n #endif\n}\n"); | ||
return SHADER; | ||
} | ||
function getVertexShader(_ref) { | ||
var borders = _ref.borders; | ||
// language=GLSL | ||
var SHADER = /*glsl*/"\nattribute vec2 a_position;\nattribute float a_size;\nattribute float a_angle;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\n\nvarying vec2 v_diffVector;\nvarying float v_radius;\n\n#ifdef PICKING_MODE\nattribute vec4 a_id;\nvarying vec4 v_color;\n#else\n".concat(borders.flatMap(function (_ref2, i) { | ||
var size = _ref2.size; | ||
return "attribute" in size ? ["attribute float a_borderSize_".concat(i + 1, ";"), "varying float v_borderSize_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref3, i) { | ||
var color = _ref3.color; | ||
return "attribute" in color ? ["attribute vec4 a_borderColor_".concat(i + 1, ";"), "varying vec4 v_borderColor_".concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n#endif\n\nconst float bias = 255.0 / 254.0;\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main() {\n float size = a_size * u_correctionRatio / u_sizeRatio * 4.0;\n vec2 diffVector = size * vec2(cos(a_angle), sin(a_angle));\n vec2 position = a_position + diffVector;\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_radius = size / 2.0;\n v_diffVector = diffVector;\n\n #ifdef PICKING_MODE\n v_color = a_id;\n #else\n").concat(borders.flatMap(function (_ref4, i) { | ||
var size = _ref4.size; | ||
return "attribute" in size ? [" v_borderSize_".concat(i + 1, " = a_borderSize_").concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n").concat(borders.flatMap(function (_ref5, i) { | ||
var color = _ref5.color; | ||
return "attribute" in color ? [" v_borderColor_".concat(i + 1, " = a_borderColor_").concat(i + 1, ";")] : []; | ||
}).join("\n"), "\n #endif\n}\n"); | ||
@@ -301,0 +303,0 @@ return SHADER; |
{ | ||
"name": "@sigma/node-border", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"description": "A node program that renders concentric discs in nodes for sigma.js", | ||
@@ -46,3 +46,3 @@ "main": "dist/sigma-node-border.cjs.js", | ||
}, | ||
"gitHead": "1601d32c9b88cf687e3bff960200ade72dead3db" | ||
"gitHead": "89a1be9953dd3488546fabc880dac262d5019c67" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58419
1220