Forums > MaxMSP

slab math operator

March 29, 2011 | 8:49 pm

Hi,

I just started using the slab shaders and had a question regarding the math shaders.

I understand how to call for an op.operation.jxs, but how would I do a multi-operation using these shaders? For instance, if I wanted to do a @op * * *, how would that look?

Thanks!


March 29, 2011 | 11:22 pm

There is not currently a way to do multi-ops in jit.gl.slab, in the way that you are expecting. If you don’t mind digging into a little shader programming, it’s pretty trivial to create something that does what you need.

http://cycling74.com/2007/05/23/your-first-shader/


April 1, 2011 | 1:18 pm

So if I wanted to do that, would I simply modify the op.multi.jxs file to say:
vec4 result = v0 * v1 * v1 *v1;

in line 54?

Or is it more complicated than that?


April 1, 2011 | 6:59 pm

to assign different ops for each color channel it would be more like:

vec4 result = vec4(v0.r*v1.r,v0.g*v1.g,v0.b*v1.b,v0.a*v1.a);

There are 2 important things going on here. First, we’re constructing a vec4 using vec4(r,g,b,a). This vec4 is a pixel value RGBA, and is made out of 4 floating point numbers. The other thing is using the swizzle (‘v0.r’) notation to access different elements of the input vec4. This is kind of like using @planemap. Swizzle can be done using either my_vec4.rgba or my_vec4.xyzw notation.


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