neu_glance.shaders¶
GLSL shaders for annotation layers, and the rule for choosing one.
A shader lives in the viewer state, not in the annotation source, so it ships in a link.
A shader naming a ``prop_`` the source does not declare fails to compile, and the layer
draws nothing, with the error shown only in the layer’s shader tab. pick_shader()
therefore checks a shader’s properties against the source’s info and refuses a
mismatch.
Attributes¶
Exceptions¶
A shader was named that this source cannot feed, or cannot be found. |
Functions¶
|
A colour as |
|
GLSL for an image-like layer, or |
|
|
|
|
|
The uicontrol a caller's |
|
The checkboxes of |
|
The checkboxes of |
|
The synapse shader for a source whose properties are |
|
A stable |
Module Contents¶
- exception neu_glance.shaders.ShaderProblem¶
Bases:
RuntimeErrorA shader was named that this source cannot feed, or cannot be found.
Initialize self. See help(type(self)) for accurate signature.
- neu_glance.shaders.as_hex_color(color: Any, what: str = 'color') str¶
A colour as
#rrggbb, which is the only form a shaderControl takes.Accepts:
"#ff0000"or"ff0000";a name from
BUILTIN_COLORS("red","cyan", …);any other name matplotlib knows (
"tab:blue"), if matplotlib is installed;a 3-sequence, read as 0..1 if every value is at most 1, else as 0..255 (so
(1, 1, 1)is white).
- neu_glance.shaders.image_shader(name: str | None, *, kind: str = 'image', channels: int = 1) str | None¶
GLSL for an image-like layer, or
Nonefor neuroglancer’s own default.nameis a built-in name,"none", orNonefor the default forkind:grayscalefor an image,probabilityfor a probability map, andrgbfor any 3-channel array. A shader whose channel count does not match the volume raises.
- neu_glance.shaders.pick_shader(info: Mapping[str, Any], name: str | None, read_bytes=None) tuple[str | None, str | None]¶
(shader source, why)for an annotation layer.nameis a built-in name, a path to a GLSL file,"none", orNonefor the first built-in whose properties the source declares.read_bytesreads a shader file (defaultneu_vol.location.read_bytes()).
- neu_glance.shaders.segment_color(segment_id: int, seed: int = 0) str¶
#rrggbbneuroglancer givessegment_idwith colour seedseed.A port of its
SegmentColorHash.compute, the same function the synapse shader’sid_colorimplements in GLSL.
- neu_glance.shaders.shader_color_control(name: str | None, *, kind: str = 'image', channels: int = 1) str¶
The uicontrol a caller’s
colorshould set, for the shader that will be chosen.Raises when that shader has no single colour, since neuroglancer would silently ignore the control.
- neu_glance.shaders.synapse_colorings(declared: Iterable[str]) list[str]¶
The checkboxes of
SYNAPSE_COLORINGSa source declaringdeclaredgets.
- neu_glance.shaders.synapse_filters(declared: Iterable[str]) list[str]¶
The checkboxes of
SYNAPSE_FILTERSa source declaringdeclaredgets.
- neu_glance.shaders.synapse_shader(declared: Iterable[str] = ()) str¶
The synapse shader for a source whose properties are
declared.show_pre/show_posttoggle the two endpoint markers, and the line is drawn only when both are on andshow_lineis ticked. Acolor_by_*checkbox is added for each colouring the properties allow; the first one ticked wins.The confidence test must stay discard-if-below. An unknown confidence is NaN, which fails every comparison, so
discard if conf < minkeeps those synapses at any threshold whilekeep if conf >= minwould hide them all. Unknown confidence usually means a synapse added by a proofreader, among the most trustworthy.
- neu_glance.shaders.value_color(value: str, seed: int = 0) str¶
A stable
#rrggbbfor a property value, in neuroglancer’s segment palette: the value is hashed to a 64-bit id (blake2b), whichsegment_color()colours.
- neu_glance.shaders.BUILTIN_COLORS¶
- neu_glance.shaders.COLORMAP_SHADER = Multiline-String¶
Show Value
"""#uicontrol invlerp normalized #uicontrol vec3 low_color color(default="#000060") #uicontrol vec3 high_color color(default="#ffe000") #uicontrol float threshold slider(min=0.0, max=1.0, default=0.0, step=0.01) #uicontrol float opacity slider(min=0.0, max=1.0, default=1.0, step=0.01) void main() { float v = normalized(); // v != v is true only for NaN: a voxel with no prediction is not drawn. if (v != v || v < threshold) discard; emitRGBA(vec4(mix(low_color, high_color, v), opacity)); } """
- neu_glance.shaders.GRAYSCALE_SHADER = Multiline-String¶
Show Value
"""#uicontrol invlerp normalized #uicontrol float gamma slider(min=0.05, max=3.0, default=1.0, step=0.05) void main() { float v = pow(normalized(), gamma); emitGrayscale(v); } """
- neu_glance.shaders.IMAGE_SHADERS: dict[str, dict[str, Any]]¶
- neu_glance.shaders.PROBABILITY_SHADER = Multiline-String¶
Show Value
"""#uicontrol invlerp normalized #uicontrol vec3 color color(default="#ff0000") #uicontrol float threshold slider(min=0.0, max=1.0, default=0.0, step=0.01) #uicontrol float gain slider(min=0.0, max=4.0, default=1.0, step=0.05) void main() { float v = normalized(); // v != v is true only for NaN: a voxel with no prediction is not drawn. if (v != v || v < threshold) discard; emitRGBA(vec4(color, clamp(v * gain, 0.0, 1.0))); } """
- neu_glance.shaders.RGB_SHADER = Multiline-String¶
Show Value
"""#uicontrol vec3 color0 color(default="#ff2000") #uicontrol vec3 color1 color(default="#00c000") #uicontrol vec3 color2 color(default="#2060ff") #uicontrol float gain0 slider(min=0.0, max=4.0, default=1.0, step=0.05) #uicontrol float gain1 slider(min=0.0, max=4.0, default=1.0, step=0.05) #uicontrol float gain2 slider(min=0.0, max=4.0, default=1.0, step=0.05) #uicontrol float opacity slider(min=0.0, max=1.0, default=1.0, step=0.01) void main() { vec3 rgb = color0 * (toNormalized(getDataValue(0)) * gain0) + color1 * (toNormalized(getDataValue(1)) * gain1) + color2 * (toNormalized(getDataValue(2)) * gain2); emitRGBA(vec4(clamp(rgb, 0.0, 1.0), opacity)); } """
- neu_glance.shaders.SHADERS: dict[str, dict[str, Any]]¶
- neu_glance.shaders.SYNAPSE_COLORINGS: tuple[tuple[str, tuple[str, ...], str], ...]¶
- neu_glance.shaders.SYNAPSE_FILTERS: tuple[tuple[str, tuple[str, ...], str], ...] = (('hide_unlisted', ('pre_listed', 'post_listed'), 'if (hide_unlisted && prop_pre_listed() == 0u...¶
- neu_glance.shaders.SYNAPSE_SHADER = ''¶