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

Screenshot for 3D view #5324

Merged
merged 7 commits into from
Apr 8, 2021
Merged

Screenshot for 3D view #5324

merged 7 commits into from
Apr 8, 2021

Conversation

daniel-wer
Copy link
Member

@daniel-wer daniel-wer commented Mar 22, 2021

Also screenshot the 3D view when using the screenshot functionality.
Allow to screenshot using the menu button in view mode.

During testing I noticed that screenshots near the dataset border included a mirrored version of the actual screenshot. This bug was happening, because the screenshot needs to be flipped horizontally due to the inverted webgl y-axis. For pixels outside of the dataset, the alpha value is set to 0. Therefore, when flipping the image of a canvas in-place and drawing it to the same canvas, you could see-through the unflipped version of the image in some areas. I fixed that by drawing the flipped image to another canvas.

See the followup issue #5323 regarding antialiasing of the screenshots.

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • Open a dataset, move to the edge of the dataset and press "Q" to create screenshots of all four viewports.
  • Alternatively, use the "Screenshot" menu entry from the dropdown next to the save button.
  • Screenshot in flight mode.

Issues:


@daniel-wer
Copy link
Member Author

@MichaelBuessemeyer Could you have a look at this? :)

@MichaelBuessemeyer
Copy link
Contributor

I just tested this feature and it works very well 🎉

While looking at the screenshots, I noticed that rendering the "out of dataset" parts with nothing looks a bit weird. Maybe we could render these parts just the same way they are rendered in the viewports (black)? But this is only a guess whether this looks better. What do you think @daniel-wer? What about a follow-up issue for this?
image

@MichaelBuessemeyer
Copy link
Contributor

During testing I noticed that screenshots near the dataset border included a mirrored version of the actual screenshot. This bug was happening, because the screenshot needs to be flipped horizontally due to the inverted webgl y-axis.

@daniel-wer could you please provide me with a bit more details on how to reproduce this bug? I wasn't able to reproduce it in the master.

@daniel-wer
Copy link
Member Author

While looking at the screenshots, I noticed that rendering the "out of dataset" parts with nothing looks a bit weird. Maybe we could render these parts just the same way they are rendered in the viewports (black)? But this is only a guess whether this looks better. What do you think @daniel-wer? What about a follow-up issue for this?

Interesting, this seems to be browser-dependent - Chrome rendered the "out of dataset" parts in a yellowish white which was less obtrusive. This is because the "out of dataset" parts get an alpha value of 0 in the shader (which is the cause of the mirroring bug I fixed). We could either change this alpha value in the shader code or initialize the buffer that is rendered into with the correct background color, I think. I'll think about which solution I prefer.

@daniel-wer could you please provide me with a bit more details on how to reproduce this bug? I wasn't able to reproduce it in the master.

Doing a screenshot so that the upper half of the xy viewport is outside of the dataset bounding box should trigger this bug (I used chrome). The result looked like this:

ROI2017_wkw__249_148_512__PLANE_XY

Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good and works in each view. I also could reproduce the bug on the master (using firefox and chrome) and can confirm that it is solved on this branch 🚀

Interesting, this seems to be browser-dependent - Chrome rendered the "out of dataset" parts in a yellowish-white which was less obtrusive. This is because the "out of dataset" parts get an alpha value of 0 in the shader (which is the cause of the mirroring bug I fixed). We could either change this alpha value in the shader code or initialize the buffer that is rendered into with the correct background color, I think. I'll think about which solution I prefer.

I think we should wait for merging until you pushed a solution for this. But if you think this can be done in follow-up PR this is fine too, as the "out of dataset" parts are rendered as before.

Comment on lines 782 to 784
// Create a new canvas when flipping as otherwise pixels of the unflipped
// image would "shine through" for pixels which are not opaque when flipping the
// image in-place
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart solution 🤓 ✔️

<Menu.Item key="share-button" onClick={() => setShareDatasetModalVisibility(true)}>
<Icon type="share-alt" />
Share
</Menu.Item>
{screenshotMenuItem}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition 👍

@@ -137,7 +137,7 @@ ${compileShader(
void main() {
vec3 worldCoordUVW = getWorldCoordUVW();
if (isOutsideOfBoundingBox(worldCoordUVW)) {
gl_FragColor = vec4(0.0);
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philippotto Setting the alpha value to 1 for pixels outside of the bounding box, fixes both the mirroring issue (described in the PR description - would make my earlier fix obsolete) as well as the other transparency issue (see Michaels screenshot). Do you see any harm in that? I checked that the node picking is not affected.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds perfectly fine to me 👍 I don't think that a lot of reasoning went into this line when it was written. The result probably behaved like "black" in the critical use case (viewport is out of bounds) which was considered good enough. Cool that you found this solution :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find any case where it would result in a 🐛 too.

@MichaelBuessemeyer
Copy link
Contributor

I retested the changes on the dev deployment and they seem to work in all cases.

It should be ready for 🚢

@bulldozer-boy bulldozer-boy bot merged commit bebfffd into master Apr 8, 2021
@bulldozer-boy bulldozer-boy bot deleted the screenshot-3d-view branch April 8, 2021 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Screenshot for 3D view
3 participants