Skip to content

Conversation

@keenancrane
Copy link
Contributor

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.

@nmwsharp
Copy link
Owner

This looks awesome! Thank you!

@nmwsharp
Copy link
Owner

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
Copy link
Owner

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.

@keenancrane
Copy link
Contributor Author

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.)

@nmwsharp
Copy link
Owner

These changes have already been merged in via #317. Thanks!

@nmwsharp nmwsharp closed this Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants