I'm going to try to convert this shadertoy example

estevancarlos's icon

I'm going to try to rewrite/construct this in jit.gl. Wish me luck. Any advice is welcome.

vichug's icon

no advice to give, but this thing is nice and i do wish u the best of luck :)

however is there a for loop in jit.gl.pix ? i wonder

syrinx's icon

Yeah, there totally is a for loop. Estevan, if you post whatever you get here, I'd be happy to take a look at it - I've been hacking my way through some Shadertoy ports as well (like this reaction-diffusion system from cornusammonis, ported to Gen here).

One thing that immediately stands out - Gen doesn't natively have a mat/mat2/mat3 datatype. The rot1 and rot2 values are in mat2. Rob Ramirez gives a tip on dealing with this: "you should be able to perform mat3 math simply using 3 vec3's as storing each row of the matrix."

estevancarlos's icon

@SYRINX
Thanks and yeah I saw your post with that patch and am using it for reference. I wasn't aware of that note from R.R. so I'll keep that in mind. However because I realized there aren't mat functions in Gen I decided to write a JXS instead. I have a few questions about that and maybe you can answer.

In gen, in order to get the dimensions you pass a value from the [dim] object which provides the resolution of a matrix. In other words, shadertoy uses the name iresolution and Max has [dim]. How do I do the same in JXS format?

syrinx's icon

If I understand correctly, I think that when you're setting up your variables (i.e., just after the <![CDATA[ tag) you include this line:

varying vec2 texdim0;

... and then reference it in your shader code as you would the dim/iResolution variable.

estevancarlos's icon

Thanks for your help. I've attached the project. It's not entirely working yet but I'm sure people can use this if they choose. I used the "sh.passthrudim.vp.glsl" file packaged with Max to get dimensions of matrix (I'm hoping I'm using the terms properly). So with that process I added the code you suggested. It's making more sense now.

starfield.zip
zip 5.40 KB
Based off this - https://www.shadertoy.com/view/XlfGRj

syrinx's icon

Nice, looks great!

Rob Ramirez's icon

i actually used this effect for a project a while back, so i went ahead and dug it up and cleaned it up a bit in case it's useful. one thing i've added is a jit.time object (from the jit.mo package) which is very useful for controlling parameters of these kinds of effects.

stars-patch.zip
zip 6.22 KB

estevancarlos's icon

Wow, this is great thanks. I will definitely analyze this patch in order to learn more. I have a question. You're sending a texture to the slab with stars.jxs. I believe I am sending a matrix in mine. Can you describe that aspect of things?

Let me see if I can narrow down my question. 1) Are they being used for equal reasons in these two patches? I copied the matrix from another example with only the vague impression it is defining cells/dimension. 2) Is there a performance difference? 3) Are these two things unrelated within our examples?

Thanks again.

Rob Ramirez's icon

they are doing the same thing: initializing the jit.gl.slab/pix object. no performance difference considering it happens one time.