You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interesting. I've been wondering about how to do complex colormaps and ruled out this approach because of this artifact. Presumably it's because the argument loops around from 359˚ back to 0˚. My only thought is that, given two arguments θ1 and θ2, to interpolate between θ1 and θ2 + n * 360˚, for whatever n minimizes |θ1 - (θ2 + n * 360˚)|. That way it will be smart enough to know that 359˚ -> 0˚ is a small change, not a large change.
Edit: Ah, but colormap knows nothing of angles. But maybe it's the same though with the colormap parameterized, whether it loops around from 0.999 -> 0 or not.
In thinking about it though, this might need to be a configuration option. Sometimes you might really just want to capture the whole colormap range between two adjacent points…
If I get it right, the function has discontinuity in the place of "lines", in terms of linear space:
Not sure what exactly happens in gl-surface3d, but it seems to build verteces based on passed samples, connecting all the values by verteces. Therefore some verteces connect the opposite sides of that discontinuous "jump", which is proper behaviour. Therefore these samples interpolate over the whole colormap (low-res):
Possible solution to that would be avoiding verteces with discontinuities. Or detect these discontinuities somehow and take edge color for these verteces.
But it has nothing to do with colormap.
Sorry to stick my nose in, but I've been trying to get a better handle on shaders. Yeah, I get it now. The definition of vertex vs fragment shaders means there's really no way to handle this without complicated preprocessing. The fragment shader would need to know about all three pre-interpolated vertex values, which, unless I'm wrong, it just doesn't. Could compute the color in the vertex shader and interpolate the color instead of the value, but that leads to different artifacts.
Here's an example that uses a geometry shader to pass the values at each vertex to the fragment shader. That would make it possible to (optionally?) detect and fix this case in the shader, except… geometry shaders.
So yeah, seems like a feature and not a bug that the colormap is applied in the fragment shader itself.
(Having only thought a little about this, I'd think the best approach would be to somehow add actual knowledge of real and imaginary parts (or modulus/argument?) so that proper color wheel, domain coloring or similar could be used—but the market for complex variables is likely very small 😞)
Again, pardon my interest… last thing: Moved the colormap eval to the vertex shader instead. Works perfectly, but in general colors are then interpolated and don't necessary lie on the color wheel itself, depending on the density of the data. But does work… can't think of a way to have cake and eat it too though…
The only downside is that it might not always be desired. At the very least, be aware that it might not pass the existing image tests due to slight differences in the order of operations.
Like you might want a single quad to span the whole colormap gamut. With evaluation in the fragment shader you get a whole rainbow. With evaluation in the vertex shader, you get a single flat color (red at both ends?).
It might be reasonable to create a switch to opt for one or the other since short of some wild shader trickery, I don't think the choice can be avoided. I don't love the idea of low-level switches, but I just don't know how else to handle a colormap on a variable that repeats.
It feels almost like a hairy ball theorem sort of conundrum… (though I guess simple continuity is enough to explain the dilemma. I guess I sorta just wanted to find a legitimate reason to mention the theorem. 😄 )
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
Not for this since it's complex-aware and so is a bigger project, but I made a glslify shader, glsl-domain-coloring that tries to really do complex colormaps the right way. If it were possible to pass extra real/imag components, then this could conceivably be dropped in. But again, that's a bigger project.
Activity
etpinard commentedon Sep 14, 2016
@dfcreative would you be interested in looking into this?
dy commentedon Sep 14, 2016
@etpinard ok, sure
rreusser commentedon Sep 14, 2016
Interesting. I've been wondering about how to do complex colormaps and ruled out this approach because of this artifact. Presumably it's because the argument loops around from 359˚ back to 0˚. My only thought is that, given two arguments
θ1
andθ2
, to interpolate betweenθ1
andθ2 + n * 360˚
, for whatevern
minimizes|θ1 - (θ2 + n * 360˚)|
. That way it will be smart enough to know that 359˚ -> 0˚ is a small change, not a large change.Edit: Ah, but colormap knows nothing of angles. But maybe it's the same though with the colormap parameterized, whether it loops around from 0.999 -> 0 or not.
rreusser commentedon Sep 14, 2016
In thinking about it though, this might need to be a configuration option. Sometimes you might really just want to capture the whole colormap range between two adjacent points…
dy commentedon Sep 14, 2016
If I get it right, the function has discontinuity in the place of "lines", in terms of linear space:

Not sure what exactly happens in

gl-surface3d
, but it seems to build verteces based on passed samples, connecting all the values by verteces. Therefore some verteces connect the opposite sides of that discontinuous "jump", which is proper behaviour. Therefore these samples interpolate over the whole colormap (low-res):Possible solution to that would be avoiding verteces with discontinuities. Or detect these discontinuities somehow and take edge color for these verteces.
But it has nothing to do with colormap.
rreusser commentedon Sep 14, 2016
Sorry to stick my nose in, but I've been trying to get a better handle on shaders. Yeah, I get it now. The definition of vertex vs fragment shaders means there's really no way to handle this without complicated preprocessing. The fragment shader would need to know about all three pre-interpolated vertex values, which, unless I'm wrong, it just doesn't. Could compute the color in the vertex shader and interpolate the color instead of the value, but that leads to different artifacts.
Here's an example that uses a geometry shader to pass the values at each vertex to the fragment shader. That would make it possible to (optionally?) detect and fix this case in the shader, except… geometry shaders.
So yeah, seems like a feature and not a bug that the colormap is applied in the fragment shader itself.
(Having only thought a little about this, I'd think the best approach would be to somehow add actual knowledge of real and imaginary parts (or modulus/argument?) so that proper color wheel, domain coloring or similar could be used—but the market for complex variables is likely very small 😞)
rreusser commentedon Sep 15, 2016
Again, pardon my interest… last thing: Moved the colormap eval to the vertex shader instead. Works perfectly, but in general colors are then interpolated and don't necessary lie on the color wheel itself, depending on the density of the data. But does work… can't think of a way to have cake and eat it too though…
dy commentedon Sep 16, 2016
@rreusser oh, that is nice solution, all we have to do is just to pick color in vertex shader indeed.

I’ll make a PR to gl-surface3d
rreusser commentedon Sep 16, 2016
The only downside is that it might not always be desired. At the very least, be aware that it might not pass the existing image tests due to slight differences in the order of operations.
Like you might want a single quad to span the whole colormap gamut. With evaluation in the fragment shader you get a whole rainbow. With evaluation in the vertex shader, you get a single flat color (red at both ends?).
It might be reasonable to create a switch to opt for one or the other since short of some wild shader trickery, I don't think the choice can be avoided. I don't love the idea of low-level switches, but I just don't know how else to handle a colormap on a variable that repeats.
It feels almost like a hairy ball theorem sort of conundrum… (though I guess simple continuity is enough to explain the dilemma. I guess I sorta just wanted to find a legitimate reason to mention the theorem. 😄 )
dy commentedon Sep 16, 2016
Ok I’ve made a PR with mode switch.
etpinard commentedon Sep 16, 2016
@dfcreative
TODO:
npm publish
gl-surface3d (you might need @mikolalysenko to get you publish rights for that)src/traces/surface/convert.js
test/image/
rreusser commentedon Sep 20, 2016
Not for this since it's complex-aware and so is a bigger project, but I made a glslify shader, glsl-domain-coloring that tries to really do complex colormaps the right way. If it were possible to pass extra real/imag components, then this could conceivably be dropped in. But again, that's a bigger project.