Skip to content

Conversation

@seankmartin
Copy link
Contributor

For both invlerp and transferFunction shader ui controls, we could add an interpolation parameter to them, which would turn on trilinear interpolation when sampling the data.

There are two ways this parameter could be added, and we might want to have just one or both. For invlerps, to demonstrate the process, I've added both. Transfer functions only has the simpler version.

Option 1 - passing it as a parameter in the shader when calling the control.

This option would allow something like:

#uicontrol invlerp contrast
#uicontrol vec3 color color
void main() {
  if (VOLUME_RENDERING) {
    float contrast_value = contrast(true /* interpolation */);
    emitRGBA(vec4(color * contrast_value, contrast_value));
  }
  else {
    float contrast_value = contrast(false /* no interpolation */);
    emitRGB(color * contrast_value);
  }
}

to be possible, where a single UI control can be created, but used in two different ways. In other words, the switch between interpolation on/off does not happen at build time.

Option 2 - provide a build time option to the shader control to enable interpolation when called with no parameters

This would be a shader build time switch, so no if statement inside the shader.

#uicontrol invlerp contrast(interpolate=true)

There's nothing I can see that prevents having both. I also hooked the multi-channel image creation into having interpolation enabled for volume rendering, and disabled for slice rendering, if you want to try the performance @fcollman @dyf

Leaving in draft for now to see if we want one/both options or any changes to naming etc. Then could expand whatever we choose so that both the invlerp and transferFunction share the same parameters for this interpolation. Would also expand the shader_ui_controls browser tests for the interpolation.

@jbms
Copy link
Collaborator

jbms commented Nov 3, 2025

I suppose it may commonly be desired to have interpolation enabled for volume rendering and disabled otherwise, which indeed makes it less useful to have as a property of the invlerp control unless we also add separate volume rendering and non-volume rendering options.

@seankmartin
Copy link
Contributor Author

seankmartin commented Nov 4, 2025

Thanks Jeremy, I think maybe best to go down a route similar to Option 1 for now then. Unsure what would be clearer for the user in the shader.

Could do something like:

#uicontrol invlerp contrast

contrast() /* as normal, has all the available parameters */
contrastInterpolated() /* with interpolation */

As opposed to an overload of the contrast function that takes in a bool as a parameter.

Edit: just realised we can't do that because we could get redefinition if the user has another invlerp called contrastInterpolated. Will set back to using overloads.

@seankmartin seankmartin changed the title Feat: interpolation in shader UI controls invlerp/transfer function feat: interpolation in shader UI controls invlerp/transfer function and use interpolation in multi-channel setup for volume rendering Nov 4, 2025
@seankmartin seankmartin marked this pull request as ready for review November 4, 2025 12:28
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.

2 participants