Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that accessed data is always non-negative in shader #4571

Merged
merged 4 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Fixed that `segmentationOpacity` could not be set anymore as part of the recommended settings for a task type. [#4545](https://github.com/scalableminds/webknossos/pull/4545)
- Fixed registration for setups with one organization and not configured defaultOrganization. [#4559](https://github.com/scalableminds/webknossos/pull/4559)
- Fixed a rendering error which could make some layers disappear in certain circumstances. [#4556](https://github.com/scalableminds/webknossos/pull/4556)
- Fixed a rendering error which caused negative float data to be rendered white. [#4556](https://github.com/scalableminds/webknossos/pull/4571)

### Removed

Expand Down
28 changes: 21 additions & 7 deletions frontend/javascripts/oxalis/shaders/texture_access.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export const getColorForCoords: ShaderModule = {
float packingDegree,
vec3 worldPositionUVW
) {
// This method looks up the color data at the given position.
// The data will be clamped to be non-negative, since negative data
// is reserved for missing buckets.

vec3 coords = floor(getRelativeCoords(worldPositionUVW, zoomStep));
vec3 relativeBucketPosition = div(coords, bucketWidth);
vec3 offsetInBucket = mod(coords, bucketWidth);
Expand Down Expand Up @@ -216,7 +220,7 @@ export const getColorForCoords: ShaderModule = {
);

if (packingDegree == 1.0) {
return bucketColor;
return max(bucketColor, 0.0);
}

float rgbaIndex = linearizeVec3ToIndexWithMod(offsetInBucket, bucketWidth, packingDegree);
Expand All @@ -226,21 +230,31 @@ export const getColorForCoords: ShaderModule = {
// The caller needs to unpack this vec4 according to the packingDegree, see getSegmentationId for an example.
// The same goes for the following code where the packingDegree is 4 and we only have 1 byte of information.
if (rgbaIndex == 0.0) {
return vec4(bucketColor.r, bucketColor.g, bucketColor.r, bucketColor.g);
return vec4(
max(bucketColor.r, 0.0),
max(bucketColor.g, 0.0),
max(bucketColor.r, 0.0),
max(bucketColor.g, 0.0)
);
} else if (rgbaIndex == 1.0) {
return vec4(bucketColor.b, bucketColor.a, bucketColor.b, bucketColor.a);
return vec4(
max(bucketColor.b, 0.0),
max(bucketColor.a, 0.0),
max(bucketColor.b, 0.0),
max(bucketColor.a, 0.0)
);
}
}

// The following code deals with packingDegree == 4.0
if (rgbaIndex == 0.0) {
return vec4(bucketColor.r);
return vec4(max(bucketColor.r, 0.0));
} else if (rgbaIndex == 1.0) {
return vec4(bucketColor.g);
return vec4(max(bucketColor.g, 0.0));
} else if (rgbaIndex == 2.0) {
return vec4(bucketColor.b);
return vec4(max(bucketColor.b, 0.0));
} else if (rgbaIndex == 3.0) {
return vec4(bucketColor.a);
return vec4(max(bucketColor.a, 0.0));
}

return vec4(0.0);
Expand Down