@luma.gl/shadertools
Advanced tools
Comparing version 7.3.0 to 7.4.0-alpha.1
@@ -11,4 +11,4 @@ "use strict"; | ||
pickingHighlightColor: DEFAULT_HIGHLIGHT_COLOR, | ||
pickingThreshold: 1.0, | ||
pickingActive: false | ||
pickingActive: false, | ||
pickingAttribute: false | ||
}; | ||
@@ -21,6 +21,6 @@ | ||
if (opts.pickingSelectedColor !== undefined) { | ||
if (opts.pickingSelectedColor === null) { | ||
if (!opts.pickingSelectedColor) { | ||
uniforms.picking_uSelectedColorValid = 0; | ||
} else { | ||
var selectedColor = [opts.pickingSelectedColor[0], opts.pickingSelectedColor[1], opts.pickingSelectedColor[2]]; | ||
var selectedColor = opts.pickingSelectedColor.slice(0, 3); | ||
uniforms.picking_uSelectedColorValid = 1; | ||
@@ -31,12 +31,11 @@ uniforms.picking_uSelectedColor = selectedColor; | ||
if (opts.pickingHighlightColor !== undefined) { | ||
uniforms.picking_uHighlightColor = opts.pickingHighlightColor; | ||
if (opts.pickingHighlightColor) { | ||
uniforms.picking_uHighlightColor = opts.pickingHighlightColor.map(function (x) { | ||
return x / 255; | ||
}); | ||
} | ||
if (opts.pickingThreshold !== undefined) { | ||
uniforms.picking_uThreshold = opts.pickingThreshold; | ||
} | ||
if (opts.pickingActive !== undefined) { | ||
uniforms.picking_uActive = opts.pickingActive ? 1 : 0; | ||
uniforms.picking_uActive = Boolean(opts.pickingActive); | ||
uniforms.picking_uAttribute = Boolean(opts.pickingAttribute); | ||
} | ||
@@ -47,4 +46,4 @@ | ||
var vs = "uniform vec3 picking_uSelectedColor;\nuniform float picking_uThreshold;\nuniform bool picking_uSelectedColorValid;\n\nout vec4 picking_vRGBcolor_Aselected;\n\nconst float COLOR_SCALE = 1. / 255.;\n\nbool isVertexPicked(vec3 vertexColor) {\n return\n picking_uSelectedColorValid &&\n abs(vertexColor.r - picking_uSelectedColor.r) < picking_uThreshold &&\n abs(vertexColor.g - picking_uSelectedColor.g) < picking_uThreshold &&\n abs(vertexColor.b - picking_uSelectedColor.b) < picking_uThreshold;\n}\n\nvoid picking_setPickingColor(vec3 pickingColor) {\n picking_vRGBcolor_Aselected.a =\n float(isVertexPicked(pickingColor));\n picking_vRGBcolor_Aselected.rgb = pickingColor * COLOR_SCALE;\n}\n"; | ||
var fs = "uniform bool picking_uActive;\nuniform vec3 picking_uSelectedColor;\nuniform vec4 picking_uHighlightColor;\n\nin vec4 picking_vRGBcolor_Aselected;\n\nconst float COLOR_SCALE = 1. / 255.;\nvec4 picking_filterHighlightColor(vec4 color) {\n bool selected = bool(picking_vRGBcolor_Aselected.a);\n\n if (selected) {\n vec4 highLightColor = picking_uHighlightColor * COLOR_SCALE;\n\n float highLightAlpha = highLightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, highLightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\nvec4 picking_filterPickingColor(vec4 color) {\n vec3 pickingColor = picking_vRGBcolor_Aselected.rgb;\n if (picking_uActive && length(pickingColor) < 0.001) {\n discard;\n }\n return picking_uActive ? vec4(pickingColor, 1.0) : color;\n}\nvec4 picking_filterColor(vec4 color) {\n vec4 highightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highightColor);\n}\n\n"; | ||
var vs = "uniform bool picking_uActive;\nuniform bool picking_uAttribute;\nuniform vec3 picking_uSelectedColor;\nuniform bool picking_uSelectedColorValid;\n\nout vec4 picking_vRGBcolor_Avalid;\n\nconst float COLOR_SCALE = 1. / 255.;\n\nbool picking_isColorValid(vec3 color) {\n return dot(color, vec3(1.0)) > 0.001;\n}\n\nbool isVertexPicked(vec3 vertexColor) {\n return\n picking_uSelectedColorValid &&\n !picking_isColorValid(abs(vertexColor - picking_uSelectedColor));\n}\n\nvoid picking_setPickingColor(vec3 pickingColor) {\n if (picking_uActive) {\n picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));\n\n if (!picking_uAttribute) {\n picking_vRGBcolor_Avalid.rgb = pickingColor * COLOR_SCALE;\n }\n } else {\n picking_vRGBcolor_Avalid.a = float(isVertexPicked(pickingColor));\n }\n}\n\nvoid picking_setPickingAttribute(float value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.r = value;\n }\n}\nvoid picking_setPickingAttribute(vec2 value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.rg = value;\n }\n}\nvoid picking_setPickingAttribute(vec3 value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.rgb = value;\n }\n}\n"; | ||
var fs = "uniform bool picking_uActive;\nuniform vec3 picking_uSelectedColor;\nuniform vec4 picking_uHighlightColor;\n\nin vec4 picking_vRGBcolor_Avalid;\nvec4 picking_filterHighlightColor(vec4 color) {\n if (picking_uActive) {\n return color;\n }\n bool selected = bool(picking_vRGBcolor_Avalid.a);\n\n if (selected) {\n float highLightAlpha = picking_uHighlightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, picking_uHighlightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\nvec4 picking_filterPickingColor(vec4 color) {\n if (picking_uActive) {\n if (picking_vRGBcolor_Avalid.a == 0.0) {\n discard;\n }\n return picking_vRGBcolor_Avalid;\n }\n return color;\n}\nvec4 picking_filterColor(vec4 color) {\n vec4 highightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highightColor);\n}\n\n"; | ||
var _default = { | ||
@@ -51,0 +50,0 @@ name: 'picking', |
@@ -5,4 +5,4 @@ const DEFAULT_HIGHLIGHT_COLOR = new Uint8Array([0, 255, 255, 255]); | ||
pickingHighlightColor: DEFAULT_HIGHLIGHT_COLOR, | ||
pickingThreshold: 1.0, | ||
pickingActive: false | ||
pickingActive: false, | ||
pickingAttribute: false | ||
}; | ||
@@ -14,6 +14,6 @@ | ||
if (opts.pickingSelectedColor !== undefined) { | ||
if (opts.pickingSelectedColor === null) { | ||
if (!opts.pickingSelectedColor) { | ||
uniforms.picking_uSelectedColorValid = 0; | ||
} else { | ||
const selectedColor = [opts.pickingSelectedColor[0], opts.pickingSelectedColor[1], opts.pickingSelectedColor[2]]; | ||
const selectedColor = opts.pickingSelectedColor.slice(0, 3); | ||
uniforms.picking_uSelectedColorValid = 1; | ||
@@ -24,12 +24,9 @@ uniforms.picking_uSelectedColor = selectedColor; | ||
if (opts.pickingHighlightColor !== undefined) { | ||
uniforms.picking_uHighlightColor = opts.pickingHighlightColor; | ||
if (opts.pickingHighlightColor) { | ||
uniforms.picking_uHighlightColor = opts.pickingHighlightColor.map(x => x / 255); | ||
} | ||
if (opts.pickingThreshold !== undefined) { | ||
uniforms.picking_uThreshold = opts.pickingThreshold; | ||
} | ||
if (opts.pickingActive !== undefined) { | ||
uniforms.picking_uActive = opts.pickingActive ? 1 : 0; | ||
uniforms.picking_uActive = Boolean(opts.pickingActive); | ||
uniforms.picking_uAttribute = Boolean(opts.pickingAttribute); | ||
} | ||
@@ -40,4 +37,4 @@ | ||
const vs = "uniform vec3 picking_uSelectedColor;\nuniform float picking_uThreshold;\nuniform bool picking_uSelectedColorValid;\n\nout vec4 picking_vRGBcolor_Aselected;\n\nconst float COLOR_SCALE = 1. / 255.;\n\nbool isVertexPicked(vec3 vertexColor) {\n return\n picking_uSelectedColorValid &&\n abs(vertexColor.r - picking_uSelectedColor.r) < picking_uThreshold &&\n abs(vertexColor.g - picking_uSelectedColor.g) < picking_uThreshold &&\n abs(vertexColor.b - picking_uSelectedColor.b) < picking_uThreshold;\n}\n\nvoid picking_setPickingColor(vec3 pickingColor) {\n picking_vRGBcolor_Aselected.a =\n float(isVertexPicked(pickingColor));\n picking_vRGBcolor_Aselected.rgb = pickingColor * COLOR_SCALE;\n}\n"; | ||
const fs = "uniform bool picking_uActive;\nuniform vec3 picking_uSelectedColor;\nuniform vec4 picking_uHighlightColor;\n\nin vec4 picking_vRGBcolor_Aselected;\n\nconst float COLOR_SCALE = 1. / 255.;\nvec4 picking_filterHighlightColor(vec4 color) {\n bool selected = bool(picking_vRGBcolor_Aselected.a);\n\n if (selected) {\n vec4 highLightColor = picking_uHighlightColor * COLOR_SCALE;\n\n float highLightAlpha = highLightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, highLightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\nvec4 picking_filterPickingColor(vec4 color) {\n vec3 pickingColor = picking_vRGBcolor_Aselected.rgb;\n if (picking_uActive && length(pickingColor) < 0.001) {\n discard;\n }\n return picking_uActive ? vec4(pickingColor, 1.0) : color;\n}\nvec4 picking_filterColor(vec4 color) {\n vec4 highightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highightColor);\n}\n\n"; | ||
const vs = "uniform bool picking_uActive;\nuniform bool picking_uAttribute;\nuniform vec3 picking_uSelectedColor;\nuniform bool picking_uSelectedColorValid;\n\nout vec4 picking_vRGBcolor_Avalid;\n\nconst float COLOR_SCALE = 1. / 255.;\n\nbool picking_isColorValid(vec3 color) {\n return dot(color, vec3(1.0)) > 0.001;\n}\n\nbool isVertexPicked(vec3 vertexColor) {\n return\n picking_uSelectedColorValid &&\n !picking_isColorValid(abs(vertexColor - picking_uSelectedColor));\n}\n\nvoid picking_setPickingColor(vec3 pickingColor) {\n if (picking_uActive) {\n picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));\n\n if (!picking_uAttribute) {\n picking_vRGBcolor_Avalid.rgb = pickingColor * COLOR_SCALE;\n }\n } else {\n picking_vRGBcolor_Avalid.a = float(isVertexPicked(pickingColor));\n }\n}\n\nvoid picking_setPickingAttribute(float value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.r = value;\n }\n}\nvoid picking_setPickingAttribute(vec2 value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.rg = value;\n }\n}\nvoid picking_setPickingAttribute(vec3 value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.rgb = value;\n }\n}\n"; | ||
const fs = "uniform bool picking_uActive;\nuniform vec3 picking_uSelectedColor;\nuniform vec4 picking_uHighlightColor;\n\nin vec4 picking_vRGBcolor_Avalid;\nvec4 picking_filterHighlightColor(vec4 color) {\n if (picking_uActive) {\n return color;\n }\n bool selected = bool(picking_vRGBcolor_Avalid.a);\n\n if (selected) {\n float highLightAlpha = picking_uHighlightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, picking_uHighlightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\nvec4 picking_filterPickingColor(vec4 color) {\n if (picking_uActive) {\n if (picking_vRGBcolor_Avalid.a == 0.0) {\n discard;\n }\n return picking_vRGBcolor_Avalid;\n }\n return color;\n}\nvec4 picking_filterColor(vec4 color) {\n vec4 highightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highightColor);\n}\n\n"; | ||
export default { | ||
@@ -44,0 +41,0 @@ name: 'picking', |
@@ -5,4 +5,4 @@ var DEFAULT_HIGHLIGHT_COLOR = new Uint8Array([0, 255, 255, 255]); | ||
pickingHighlightColor: DEFAULT_HIGHLIGHT_COLOR, | ||
pickingThreshold: 1.0, | ||
pickingActive: false | ||
pickingActive: false, | ||
pickingAttribute: false | ||
}; | ||
@@ -15,6 +15,6 @@ | ||
if (opts.pickingSelectedColor !== undefined) { | ||
if (opts.pickingSelectedColor === null) { | ||
if (!opts.pickingSelectedColor) { | ||
uniforms.picking_uSelectedColorValid = 0; | ||
} else { | ||
var selectedColor = [opts.pickingSelectedColor[0], opts.pickingSelectedColor[1], opts.pickingSelectedColor[2]]; | ||
var selectedColor = opts.pickingSelectedColor.slice(0, 3); | ||
uniforms.picking_uSelectedColorValid = 1; | ||
@@ -25,12 +25,11 @@ uniforms.picking_uSelectedColor = selectedColor; | ||
if (opts.pickingHighlightColor !== undefined) { | ||
uniforms.picking_uHighlightColor = opts.pickingHighlightColor; | ||
if (opts.pickingHighlightColor) { | ||
uniforms.picking_uHighlightColor = opts.pickingHighlightColor.map(function (x) { | ||
return x / 255; | ||
}); | ||
} | ||
if (opts.pickingThreshold !== undefined) { | ||
uniforms.picking_uThreshold = opts.pickingThreshold; | ||
} | ||
if (opts.pickingActive !== undefined) { | ||
uniforms.picking_uActive = opts.pickingActive ? 1 : 0; | ||
uniforms.picking_uActive = Boolean(opts.pickingActive); | ||
uniforms.picking_uAttribute = Boolean(opts.pickingAttribute); | ||
} | ||
@@ -41,4 +40,4 @@ | ||
var vs = "uniform vec3 picking_uSelectedColor;\nuniform float picking_uThreshold;\nuniform bool picking_uSelectedColorValid;\n\nout vec4 picking_vRGBcolor_Aselected;\n\nconst float COLOR_SCALE = 1. / 255.;\n\nbool isVertexPicked(vec3 vertexColor) {\n return\n picking_uSelectedColorValid &&\n abs(vertexColor.r - picking_uSelectedColor.r) < picking_uThreshold &&\n abs(vertexColor.g - picking_uSelectedColor.g) < picking_uThreshold &&\n abs(vertexColor.b - picking_uSelectedColor.b) < picking_uThreshold;\n}\n\nvoid picking_setPickingColor(vec3 pickingColor) {\n picking_vRGBcolor_Aselected.a =\n float(isVertexPicked(pickingColor));\n picking_vRGBcolor_Aselected.rgb = pickingColor * COLOR_SCALE;\n}\n"; | ||
var fs = "uniform bool picking_uActive;\nuniform vec3 picking_uSelectedColor;\nuniform vec4 picking_uHighlightColor;\n\nin vec4 picking_vRGBcolor_Aselected;\n\nconst float COLOR_SCALE = 1. / 255.;\nvec4 picking_filterHighlightColor(vec4 color) {\n bool selected = bool(picking_vRGBcolor_Aselected.a);\n\n if (selected) {\n vec4 highLightColor = picking_uHighlightColor * COLOR_SCALE;\n\n float highLightAlpha = highLightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, highLightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\nvec4 picking_filterPickingColor(vec4 color) {\n vec3 pickingColor = picking_vRGBcolor_Aselected.rgb;\n if (picking_uActive && length(pickingColor) < 0.001) {\n discard;\n }\n return picking_uActive ? vec4(pickingColor, 1.0) : color;\n}\nvec4 picking_filterColor(vec4 color) {\n vec4 highightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highightColor);\n}\n\n"; | ||
var vs = "uniform bool picking_uActive;\nuniform bool picking_uAttribute;\nuniform vec3 picking_uSelectedColor;\nuniform bool picking_uSelectedColorValid;\n\nout vec4 picking_vRGBcolor_Avalid;\n\nconst float COLOR_SCALE = 1. / 255.;\n\nbool picking_isColorValid(vec3 color) {\n return dot(color, vec3(1.0)) > 0.001;\n}\n\nbool isVertexPicked(vec3 vertexColor) {\n return\n picking_uSelectedColorValid &&\n !picking_isColorValid(abs(vertexColor - picking_uSelectedColor));\n}\n\nvoid picking_setPickingColor(vec3 pickingColor) {\n if (picking_uActive) {\n picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));\n\n if (!picking_uAttribute) {\n picking_vRGBcolor_Avalid.rgb = pickingColor * COLOR_SCALE;\n }\n } else {\n picking_vRGBcolor_Avalid.a = float(isVertexPicked(pickingColor));\n }\n}\n\nvoid picking_setPickingAttribute(float value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.r = value;\n }\n}\nvoid picking_setPickingAttribute(vec2 value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.rg = value;\n }\n}\nvoid picking_setPickingAttribute(vec3 value) {\n if (picking_uAttribute) {\n picking_vRGBcolor_Avalid.rgb = value;\n }\n}\n"; | ||
var fs = "uniform bool picking_uActive;\nuniform vec3 picking_uSelectedColor;\nuniform vec4 picking_uHighlightColor;\n\nin vec4 picking_vRGBcolor_Avalid;\nvec4 picking_filterHighlightColor(vec4 color) {\n if (picking_uActive) {\n return color;\n }\n bool selected = bool(picking_vRGBcolor_Avalid.a);\n\n if (selected) {\n float highLightAlpha = picking_uHighlightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, picking_uHighlightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\nvec4 picking_filterPickingColor(vec4 color) {\n if (picking_uActive) {\n if (picking_vRGBcolor_Avalid.a == 0.0) {\n discard;\n }\n return picking_vRGBcolor_Avalid;\n }\n return color;\n}\nvec4 picking_filterColor(vec4 color) {\n vec4 highightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highightColor);\n}\n\n"; | ||
export default { | ||
@@ -45,0 +44,0 @@ name: 'picking', |
{ | ||
"name": "@luma.gl/shadertools", | ||
"version": "7.3.0", | ||
"version": "7.4.0-alpha.1", | ||
"description": "Shader module system for luma.gl", | ||
@@ -42,3 +42,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "1e6b82df3cf73855fb7e412fcf1d268567a4e650" | ||
"gitHead": "77358f20783dde922070cc148c51353f57f70996" | ||
} |
@@ -6,4 +6,4 @@ const DEFAULT_HIGHLIGHT_COLOR = new Uint8Array([0, 255, 255, 255]); | ||
pickingHighlightColor: DEFAULT_HIGHLIGHT_COLOR, // Color of visual highlight of "selected" item | ||
pickingThreshold: 1.0, | ||
pickingActive: false // Set to true when rendering to off-screen "picking" buffer | ||
pickingActive: false, // Set to true when rendering to off-screen "picking" buffer | ||
pickingAttribute: false // Set to true when picking an attribute value instead of object index | ||
}; | ||
@@ -15,10 +15,6 @@ | ||
if (opts.pickingSelectedColor !== undefined) { | ||
if (opts.pickingSelectedColor === null) { | ||
if (!opts.pickingSelectedColor) { | ||
uniforms.picking_uSelectedColorValid = 0; | ||
} else { | ||
const selectedColor = [ | ||
opts.pickingSelectedColor[0], | ||
opts.pickingSelectedColor[1], | ||
opts.pickingSelectedColor[2] | ||
]; | ||
const selectedColor = opts.pickingSelectedColor.slice(0, 3); | ||
uniforms.picking_uSelectedColorValid = 1; | ||
@@ -28,11 +24,8 @@ uniforms.picking_uSelectedColor = selectedColor; | ||
} | ||
if (opts.pickingHighlightColor !== undefined) { | ||
uniforms.picking_uHighlightColor = opts.pickingHighlightColor; | ||
if (opts.pickingHighlightColor) { | ||
uniforms.picking_uHighlightColor = opts.pickingHighlightColor.map(x => x / 255); | ||
} | ||
// TODO - major hack - decide on normalization and remove | ||
if (opts.pickingThreshold !== undefined) { | ||
uniforms.picking_uThreshold = opts.pickingThreshold; | ||
} | ||
if (opts.pickingActive !== undefined) { | ||
uniforms.picking_uActive = opts.pickingActive ? 1 : 0; | ||
uniforms.picking_uActive = Boolean(opts.pickingActive); | ||
uniforms.picking_uAttribute = Boolean(opts.pickingAttribute); | ||
} | ||
@@ -43,37 +36,60 @@ return uniforms; | ||
const vs = `\ | ||
uniform bool picking_uActive; | ||
uniform bool picking_uAttribute; | ||
uniform vec3 picking_uSelectedColor; | ||
uniform float picking_uThreshold; | ||
uniform bool picking_uSelectedColorValid; | ||
out vec4 picking_vRGBcolor_Aselected; | ||
out vec4 picking_vRGBcolor_Avalid; | ||
const float COLOR_SCALE = 1. / 255.; | ||
bool picking_isColorValid(vec3 color) { | ||
return dot(color, vec3(1.0)) > 0.001; | ||
} | ||
bool isVertexPicked(vec3 vertexColor) { | ||
return | ||
picking_uSelectedColorValid && | ||
abs(vertexColor.r - picking_uSelectedColor.r) < picking_uThreshold && | ||
abs(vertexColor.g - picking_uSelectedColor.g) < picking_uThreshold && | ||
abs(vertexColor.b - picking_uSelectedColor.b) < picking_uThreshold; | ||
!picking_isColorValid(abs(vertexColor - picking_uSelectedColor)); | ||
} | ||
void picking_setPickingColor(vec3 pickingColor) { | ||
// Do the comparison with selected item color in vertex shader as it should mean fewer compares | ||
picking_vRGBcolor_Aselected.a = | ||
float(isVertexPicked(pickingColor)); | ||
if (picking_uActive) { | ||
// Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable | ||
picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor)); | ||
// Stores the picking color so that the fragment shader can render it during picking | ||
picking_vRGBcolor_Aselected.rgb = pickingColor * COLOR_SCALE; | ||
if (!picking_uAttribute) { | ||
// Stores the picking color so that the fragment shader can render it during picking | ||
picking_vRGBcolor_Avalid.rgb = pickingColor * COLOR_SCALE; | ||
} | ||
} else { | ||
// Do the comparison with selected item color in vertex shader as it should mean fewer compares | ||
picking_vRGBcolor_Avalid.a = float(isVertexPicked(pickingColor)); | ||
} | ||
} | ||
void picking_setPickingAttribute(float value) { | ||
if (picking_uAttribute) { | ||
picking_vRGBcolor_Avalid.r = value; | ||
} | ||
} | ||
void picking_setPickingAttribute(vec2 value) { | ||
if (picking_uAttribute) { | ||
picking_vRGBcolor_Avalid.rg = value; | ||
} | ||
} | ||
void picking_setPickingAttribute(vec3 value) { | ||
if (picking_uAttribute) { | ||
picking_vRGBcolor_Avalid.rgb = value; | ||
} | ||
} | ||
`; | ||
const fs = `\ | ||
uniform bool picking_uActive; // true during rendering to offscreen picking buffer | ||
uniform bool picking_uActive; | ||
uniform vec3 picking_uSelectedColor; | ||
uniform vec4 picking_uHighlightColor; | ||
in vec4 picking_vRGBcolor_Aselected; | ||
in vec4 picking_vRGBcolor_Avalid; | ||
const float COLOR_SCALE = 1. / 255.; | ||
/* | ||
@@ -83,12 +99,13 @@ * Returns highlight color if this item is selected. | ||
vec4 picking_filterHighlightColor(vec4 color) { | ||
bool selected = bool(picking_vRGBcolor_Aselected.a); | ||
if (picking_uActive) { | ||
return color; | ||
} | ||
bool selected = bool(picking_vRGBcolor_Avalid.a); | ||
if (selected) { | ||
vec4 highLightColor = picking_uHighlightColor * COLOR_SCALE; | ||
float highLightAlpha = highLightColor.a; | ||
float highLightAlpha = picking_uHighlightColor.a; | ||
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha); | ||
float highLightRatio = highLightAlpha / blendedAlpha; | ||
vec3 blendedRGB = mix(color.rgb, highLightColor.rgb, highLightRatio); | ||
vec3 blendedRGB = mix(color.rgb, picking_uHighlightColor.rgb, highLightRatio); | ||
return vec4(blendedRGB, blendedAlpha); | ||
@@ -104,7 +121,9 @@ } else { | ||
vec4 picking_filterPickingColor(vec4 color) { | ||
vec3 pickingColor = picking_vRGBcolor_Aselected.rgb; | ||
if (picking_uActive && length(pickingColor) < 0.001) { | ||
discard; | ||
if (picking_uActive) { | ||
if (picking_vRGBcolor_Avalid.a == 0.0) { | ||
discard; | ||
} | ||
return picking_vRGBcolor_Avalid; | ||
} | ||
return picking_uActive ? vec4(pickingColor, 1.0) : color; | ||
return color; | ||
} | ||
@@ -111,0 +130,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
1530107
21860
2