noob needs help with shaders

Linden's icon

Hello Forum,

i am a bloody shader noob who wanted to follow a simple tutorial. but it is much harder than i thought to replicate this example you see on the picture.
i would love to have more insight in the following questions
1. i am not sure if this is example is possible in a slab or if it has to be a shader (slabs cannot run vertex programs??)
2. i am not sure if this can be done in version 1.2 gl2 or 1.5 gl3 ?
3. what do i have to write instead of "varying vec3 v_position" ??
4.does the varying vec3 position has to be declared and bind at the beginning of the shader...
5. is this line necessary?? gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
6. is there a log which describes the use of terms in the different shader environments so that is easier to follow and port any tutorial. for example what is uv in jitter?
7. what are the idiosyncrasies of jitter to other shader environments?

thank you so much for your help

Jean-Francois Charles's icon

Hi, disclaimer first, I'm not a shader specialist. I'm going to talk about gl2. I found thebookofshaders.com to be useful, as a complement to the Max resources. In the Max reference, this page has useful information: Appendix C: The JXS File Format. Now, here is some information that might be useful to you:

When you write a shader, it has to include both vertex and fragment programs.
In many Max examples, the vertex program is given as a separate file. For instance in the shader co.average.jxs, you see the line
<program name="vp" type="vertex" source="sh.passthru.xform.vp.glsl" />
This sh.passthru.xform.vp.glsl file lies in the Max application folder, in Contents/Resources/C74/media/jitter/shaders/shared/glsl
Studying it, you'll see what's part of the Max/shader interface (gl_MultiTexCoord0 for instance) and what variables are created in this program, not part of the interface (texcoord0).
In other shaders coming with Max, the vertex program is included in the shader. For instance, look at td.lumadisplace.jxs: you'll see two main() programs.
I hope that helps,
J-F

Jean-Francois Charles's icon

Found a little time to make a patch. Try this with the attached shader.

color-test.jxs
jxs 0.79 KB

Max Patch
Copy patch and select New From Clipboard in Max.

In the shader, the following line is especially interesting, and shows how texdim is a variable you create, but receives the texture dimension as a state.
<param name="texdim" type="vec2" state="TEXDIM0" />

Linden's icon

how can i get this values in a jitter shader??

Thank you Jean-Francois for your help.
will have a look in the files you pointed out.

your example posted above is similar to one i found in the wonderful bookofshaders https://thebookofshaders.com/03/ (somehow the axes are shifted).
however my problem is exactly how i get from that example you posted to the example i posted in the picture....
how can i get a model position of a point? basically the example shifts the coordinates so that the middle has the coordinate 0.0 (instead of bottom left = 0.0). that why the color gradient is different.
it does it by simply declarying a vec3 position. but i have no clue how i can do that inside the jxs file and i would love to understand what is going on there.

Jean-Francois Charles's icon

In your code, vec3 stands for a "3-plane" cell, RGB. On line 17, with gl_FragColor = vec4(color, 1.0), the full RGBA is reconstituted: the whole alpha plane is set to 1. In my example, I just didn't use an intermediary vec3, but that really has no consequence on the rendering.
With my patch, the gradient progression doesn't look like your picture, but looks quite close to the picture on thebookofshaders page 03.
Then, when it comes to which cell has the coordinate (0, 0): in GLSL world, the cell (0,0) is the one in the bottom left corner. In Jitter matrices, it's the one on the top left corner. I can only "guess" that the interface between Jitter & the shaders was designed to keep the Jitter logic of cell numbering.
Just use the coordinate "1.-y" instead of "y", like this:

Max Patch
Copy patch and select New From Clipboard in Max.

color-test-reversed.jxs
jxs 0.79 KB

Linden's icon

thank you very much for clarifying.
i am just wondering if there is a more elegant way to achieve this other than scaling the coordinates...
something like snorm for shaders??
i achieved to get the result i wished by this shader:


Martin Beck's icon

...did not read all of the thread but maybe this here helps a little bit

You can see the shader code of a jit.gl.pix if you export the code with this message.

Max Patch
Copy patch and select New From Clipboard in Max.

Tutorial (gl2) by Federico Foderaro on translation of shader toy code to Jitter.
https://www.youtube.com/watch?v=WpcsiuqrjwQ&feature=emb_title

...but with gl3 this became even simpler.