polyscope icon indicating copy to clipboard operation
polyscope copied to clipboard

Add contour shader

Open keenancrane opened this issue 4 years ago • 4 comments

This PR adds a shader that visualizes level sets of a scalar quantity as contour lines that have constant thickness in screen space. For scalar quantities, the shader is exposed through under the Options menu, as Enable contours (just like Enable isolines). Contours have three parameters:

  • frequency — how many contours get drawn
  • width — width of stroke used to draw the contours
  • darkness — controls the stroke opacity

image

There are still some things that could be improved. For instance, contours are currently drawn as black, which may not be very visible over dark color gradients. Here it might be helpful to add a color picker, or at least an option to use a different effective blend mode (like "invert"). Also, stripe width is set using the screen-space gradient of the scalar quantity. Since vertex quantities are piecewise linear, these derivatives will be piecewise constant. Hence, stripe thickness will suddenly jump when going from one triangle to the next. This artifact is especially noticeable for thick contours. Not sure what the best solution is. One is to provide an option that disables constant thickness, and just sticks to uniform thickness (which will render contours as thicker/thinner). Another is to pass in a gradient magnitude per vertex, so that these magnitudes get interpolated linearly across triangles. This will work great, but requires additional setup that is not super compatible with the rest of the shader ecosystem.

I didn't see an obvious place in the docs to document shaders, but let me know if I've missed it and I can add something.

keenancrane avatar Oct 11 '21 11:10 keenancrane

This looks awesome! Thank you!

nmwsharp avatar Oct 12 '21 18:10 nmwsharp

One small software API question here is how to combine this with the "stripe" visualization already present. With this PR we'll have both equal-function-width alternating stripes, and equal-screen-space-width contours available. However, it doesn't really make sense to use both at once, and it'd be nice to present them alongside each other in the user-facing options.

Do you have any strong opinions about how to combine them? Right now I'm thinking to expose an isolineStyle option that takes an enum specifying either IsolineStyle::Contour (existing thing) or IsolineStyle::Stripe. That would also allow options such as the frequency and darkness to be shared.

nmwsharp avatar Oct 12 '21 18:10 nmwsharp

place in the docs to document shaders

Code-wise, there's no docs at all for the shader's right now :)

For user-facing options, right now the options are listed at the bottom of all the scalar quantities pages, like this. It would probably be wise to unify them, rather than having duplicated options docs for point scalar quantities, mesh scalar quantities, etc, but that has not happened yet.

nmwsharp avatar Oct 12 '21 18:10 nmwsharp

Yeah, in fact I think it may crash right now if you try to enable both shaders simultaneously. Would definitely make sense to make these radio buttons or something.

(I thought for a moment about putting all of these options into one mega-shader for both stripes and contours, but that felt a bit too bold for a Monday morning.)

keenancrane avatar Oct 12 '21 18:10 keenancrane