Skip to content

Commit

Permalink
fix shader code when mappings are not supported, add test (#2173)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-wer committed Jun 28, 2018
1 parent dbfbaad commit bcfc991
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
29 changes: 13 additions & 16 deletions app/assets/javascripts/oxalis/shaders/main_data_fragment.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ${compileShader(
getRelativeCoords,
getWorldCoordUVW,
getMaybeFilteredColorOrFallback,
convertCellIdToRGB,
hasSegmentation ? convertCellIdToRGB : null,
hasSegmentation ? getBrushOverlay : null,
hasSegmentation ? getSegmentationId : null,
)}
Expand All @@ -150,9 +150,6 @@ void main() {
vec3 mousePosCoords = getRelativeCoords(flooredMousePosUVW, zoomStep);
vec4 cellIdUnderMouse = getSegmentationId(mousePosCoords, fallbackCoords, false);
<% } else { %>
vec4 id = vec4(0.0);
vec4 cellIdUnderMouse = vec4(0.0);
<% } %>
// Get Color Value(s)
Expand Down Expand Up @@ -197,20 +194,20 @@ void main() {
data_color = clamp(data_color, 0.0, 1.0);
<% } %>
// Color map (<= to fight rounding mistakes)
if ( length(id) > 0.1 ) {
// Increase cell opacity when cell is hovered
float hoverAlphaIncrement =
// Hover cell only if it's the active one, if the feature is enabled
// and if segmentation opacity is not zero
cellIdUnderMouse == id && highlightHoveredCellId && alpha > 0.0
? 0.2 : 0.0;
gl_FragColor = vec4(mix( data_color, convertCellIdToRGB(id), alpha + hoverAlphaIncrement ), 1.0);
} else {
gl_FragColor = vec4(data_color, 1.0);
}
gl_FragColor = vec4(data_color, 1.0);
<% if (hasSegmentation) { %>
// Color map (<= to fight rounding mistakes)
if ( length(id) > 0.1 ) {
// Increase cell opacity when cell is hovered
float hoverAlphaIncrement =
// Hover cell only if it's the active one, if the feature is enabled
// and if segmentation opacity is not zero
cellIdUnderMouse == id && highlightHoveredCellId && alpha > 0.0
? 0.2 : 0.0;
gl_FragColor = vec4(mix( data_color, convertCellIdToRGB(id), alpha + hoverAlphaIncrement ), 1.0);
}
vec4 brushOverlayColor = getBrushOverlay(worldCoordUVW);
brushOverlayColor.xyz = convertCellIdToRGB(activeCellId);
gl_FragColor = mix(gl_FragColor, brushOverlayColor, brushOverlayColor.a);
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/oxalis/shaders/segmentation.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { binarySearchIndex } from "./mappings.glsl";
import { getRgbaAtIndex } from "./texture_access.glsl";

export const convertCellIdToRGB: ShaderModuleType = {
requirements: [hsvToRgb],
requirements: [hsvToRgb, getRgbaAtIndex],
code: `
vec3 convertCellIdToRGB(vec4 id) {
float golden_ratio = 0.618033988749895;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/test/shaders/shader_syntax.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test("Shader syntax: Ortho Mode", t => {
segmentationPackingDegree: 1,
isRgb: false,
planeID: OrthoViews.PLANE_XY,
isMappingSupported: false,
isMappingSupported: true,
dataTextureCountPerLayer: 3,
resolutions,
datasetScale: [1, 1, 1],
Expand Down

0 comments on commit bcfc991

Please sign in to comment.