Forums > Jitter

min and max value in texture ?

Feb 25 2010 | 12:53 am

i’m still relatively new in shaderland and I’m trying to slabify a patch I made in ‘vanilla’ jitter ages ago.
It all seems to work out fine, but I’m getting stuck trying to replicate some of jit.3m’s functionality in/with a shader. I need to get minimum and maximum values of a texture.
Is that possible in a shader or do I have to go back to vanillajitterland for this ?

thanks for any insight,


Feb 25 2010 | 11:44 am

hello Joost:
maybe this post can help you:


Feb 25 2010 | 5:56 pm

as should be apparent from reading the linked thread, this is not really something shaders are used for (without devising some sort of complicated multi-pass method).

generally, you should think of your shader as operating on a single pixel or vertex at a time.

Feb 25 2010 | 6:31 pm

I think it would be more expensive to calculate the min and max values from the shader, am i correct?

Feb 25 2010 | 9:00 pm

Ok, thanks a lot for the answers and the pointers. I’m aware ‘global’ properties of a texture like max and min are not typically things you should do with a shader, but I’m trying to avoid having to go back to the CPU. was hoping for a magical trick that doesn’t exist.

The key to a possible solution is here:
see the bit about reductions.

Jitter comes with a gp.reduce.jxs shader that is identical to the example given on that page, but I haven’t figured out yet how to use it; my knowledge of openGL is not big enough for that to be obvious…

If anybody knows how to set up these reductions I would be very grateful if he/she would share it..



Feb 27 2010 | 9:04 am

hey joost. i couldn’t get the cg shader to work, but here’s a glsl one that seems to do the trick.
shader and patch below.




-- Pasted Max Patch, click to expand. --

Mar 01 2010 | 11:46 pm

Hey Rob, that’s great.
Sorry for not paying attention to the forum for a while: I got to pretty much the same point as you a couple of days ago, wrote a glsl shader as an excercise and yes, it works. The only thing is that there is a *big* difference between the maximum this calculates and the maximum jit.3m calculates directly out of the If you check the dishes movie, jit.3m gives a solid 255 255 255 255 and that is very different value than the maxima in the cellblock… Minimum same thing.

Perhaps it has to do with some kind of interpolation ?

hmm, had no idea why this is happening and found a way to get my slabbypatch to work without a maximum and a minimum. And yes, it is fast an gorgeous, so I’m happy and building a more robust version. Thanks for the help and advice..

Mar 01 2010 | 11:51 pm

hmm, when I read my post again I wonder why it would actually matter that jit.3m maxima are different from slab maxima. Perhaps that reflects a real situation (even though I don’t understand why that happens) and in the end we only care about the slabmaxima here, don’t we ?
Now I’m happy without them, so hopefully this will be of use in the future.



Viewing 8 posts - 1 through 8 (of 8 total)

Forums > Jitter