Skip to content

Commit

Permalink
feat: update invlerp shader
Browse files Browse the repository at this point in the history
  • Loading branch information
seankmartin committed May 30, 2024
1 parent 5320073 commit eb0a9e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/cryo_et_neuroglancer/shaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def build_shader(shader_parts: list[str]) -> str:
def _build_invlerp(
name: str, contrast_limits: tuple[float, float], window_limits: tuple[float, float]
) -> str:
return f"#uicontrol invlerp {name}(range=[{contrast_limits[0]}, {contrast_limits[1]}], window=[{window_limits[0]}, {window_limits[1]}], clamp=true)"
return f"#uicontrol invlerp {name}(range=[{contrast_limits[0]}, {contrast_limits[1]}], window=[{window_limits[0]}, {window_limits[1]}])"


def _build_invertable_invlerp_getter(name: str):
Expand Down Expand Up @@ -40,18 +40,22 @@ def get_default_image_shader(
threed_contrast_name = "contrast3D"
shader_parts = [
_build_invlerp(contrast_name, contrast_limits, window_limits),
_build_invlerp(threed_contrast_name, contrast_limits, window_limits),
*_build_invertable_invlerp_getter(contrast_name),
_build_invlerp(threed_contrast_name, contrast_limits, window_limits),
*_build_invertable_invlerp_getter(threed_contrast_name),
"",
"void main() {",
" float outputValue;",
*_build_volume_rendering_switch(
[f"outputValue = {threed_contrast_name}_get();"],
[f"outputValue = {contrast_name}_get();"],
[
f"outputValue = {threed_contrast_name}_get();",
"emitIntensity(outputValue);",
],
[
f"outputValue = {contrast_name}_get();",
],
),
" emitGrayscale(outputValue);",
" emitIntensity(outputValue);",
"}",
]
return build_shader(shader_parts)
Expand Down
6 changes: 3 additions & 3 deletions src/tests/test_shaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ def test_get_default_image_shader():
contrast_limits = (0.0, 1.0)
window_limits = (0.0, 1.0)
expected_shader = """
#uicontrol invlerp contrast(range=[0.0, 1.0], window=[0.0, 1.0], clamp=true)
#uicontrol invlerp contrast3D(range=[0.0, 1.0], window=[0.0, 1.0], clamp=true)
#uicontrol invlerp contrast(range=[0.0, 1.0], window=[0.0, 1.0])
#uicontrol bool invert_contrast checkbox(default=false)
float contrast_get() { return invert_contrast ? 1.0 - contrast() : contrast(); }
#uicontrol invlerp contrast3D(range=[0.0, 1.0], window=[0.0, 1.0])
#uicontrol bool invert_contrast3D checkbox(default=false)
float contrast3D_get() { return invert_contrast3D ? 1.0 - contrast3D() : contrast3D(); }
void main() {
float outputValue;
if (VOLUME_RENDERING) {
outputValue = contrast3D_get();
emitIntensity(outputValue);
} else {
outputValue = contrast_get();
}
emitGrayscale(outputValue);
emitIntensity(outputValue);
}
"""
actual_shader = get_default_image_shader(contrast_limits, window_limits)
Expand Down

0 comments on commit eb0a9e4

Please sign in to comment.