feat: define DATA_VALUE_TYPE and DATA_VALUE_TYPE_IS_* for shaders#856
feat: define DATA_VALUE_TYPE and DATA_VALUE_TYPE_IS_* for shaders#856LDeakin wants to merge 6 commits intogoogle:masterfrom
DATA_VALUE_TYPE and DATA_VALUE_TYPE_IS_* for shaders#856Conversation
|
Just my thoughts... DATA_TYPE or dataType would be a preferable name. dataType x = toNormalized(getDataValue());Also, the several following |
|
Maybe |
|
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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));
#endifThere was a problem hiding this comment.
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());
}There was a problem hiding this comment.
I'm curious what your actual use case is for this.
There was a problem hiding this comment.
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.
SHADER_TYPE for shadersDATA_VALUE_TYPE and DATA_VALUE_TYPE_IS_* for shaders
Since `getDataValue` etc returns a single channel
This is handy for writing generic user shaders that use
getDataValue()etc