Skip to content

Conversation

@LDeakin
Copy link
Contributor

@LDeakin LDeakin commented Oct 28, 2025

This is handy for writing generic user shaders that use getDataValue() etc

@chrisj
Copy link
Contributor

chrisj commented Oct 28, 2025

Just my thoughts...

DATA_TYPE or dataType would be a preferable name.

dataType x = toNormalized(getDataValue());

Also, the several following ${getShaderType(dataType,)} could be replaced with the define.

@jbms
Copy link
Collaborator

jbms commented Nov 3, 2025

Maybe DATA_VALUE_TYPE --- since DATA_TYPE might be expected to more correspond to the typescript DataType.

@jbms
Copy link
Collaborator

jbms commented Nov 3, 2025

Can you also add this to the documentation (https://github.com/google/neuroglancer/blob/master/src/sliceview/image_layer_rendering.md)?


```glsl
DATA_VALUE_TYPE value = getDataValue();
#if DATA_VALUE_TYPE == float
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait does that actually work?

I thought the GLSL preprocessor was similar to the C preprocessor except more limited? Without token pasting ## most of the "advanced C preprocessor" tricks are unavailable.

In particular, using the C preprocessor it is possible through advanced techniques to perform an equality check like you have above but I don't know that it would be possible in GLSL.

Copy link
Contributor

Choose a reason for hiding this comment

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

Having float in the conditional errors for me, it seems to restricted to integer values.

  #define FOO 6

  #if FOO == 6
    setColor(vec4(1.0, 0.0, 0.0, 1.0));
  #endif

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks both for catching that! I should have tested that basic use case. How about the proposed solution in c93afc3?

E.g. shader

#uicontrol invlerp normalized
void main() {
  DATA_VALUE_TYPE value = getDataValue();
  #if DATA_VALUE_TYPE_IS_UINT8_T
  if (value.value > 80u) {
    emitRGBA(vec4(1.0f, 0.0, 0.0f, 1.0f));
    return;         
  }
  #endif
  emitGrayscale(normalized());
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious what your actual use case is for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main use case for my lab is to check for a data-type dependent sentinel value for masking. Doing this at runtime in neuroglancer is much simpler than what we do currently, and I'd guess other people may find some utility in this.

@LDeakin LDeakin changed the title feat: define SHADER_TYPE for shaders feat: define DATA_VALUE_TYPE and DATA_VALUE_TYPE_IS_* for shaders Nov 10, 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