Shader output inverted

spin lud's icon

Hi, I am porting this shader https://www.shadertoy.com/view/wdGSzw in Max. It works but the particles direction is inverted (down-up instead of up-down) and I don't understand why.

Sand Rain.zip
zip

Any idea why the shader output is flipped?

Rob Ramirez's icon

It's just differing assumptions about what is up between the two domains I think. Easy enough to workaround using the jit.gl.slab rect attribute (e.g. rect 0 1 1 0 flips vertically). I also replaced the jit.gl.texture after the jit.movie with a jit.gl.slab which gave proper orientation for some reason.

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

riccardo dapelo's icon

Hi,

I was just testing the shader. Nice work! A question: if I send the main window to fullscreen the rendering stops. Why?

Does it have to do with the size/dimensions of the various slabs and shaders, or with the adapt 0 attribute?

spin lud's icon

Thank you very much ROB, now the orientation is fixed 🙏

@RICCARDO I have noticed the same but honestly I have no clue. Theoretically the window dimensions should not impact the shaders because they have fixed dimensions internally using @adapt 0 and also the video dimensions stay the same.
Maybe someone more expert could give us an hint 😅

Rob Ramirez's icon

It's due to the the mapping of VIEWPORT uniform state to iResolution in both the shaders. This should instead be TEXDIM0:

<param name="iResolution" type="vec2" state="TEXDIM0" />

I simplified the patch further and embedded the shaders:

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

riccardo dapelo's icon

Thanks Rob!

I would have definitely wasted a lot of time trying to figure out where the problem was....

hhelt's icon

Hello all,

This is really a nice shader!

Has someone an idea, how we can get rid of the 3 horizontal lines on the top without scaling or cutting the output?

All the best,
hhelt

spin lud's icon

Rob Ramirez

Dec 3, 2024, 7:44 PM

It's due to the the mapping of VIEWPORT uniform state to iResolution in both the shaders. This should instead be TEXDIM0:

<param name="iResolution" type="vec2" state="TEXDIM0" />

Awesome, thanks a lot Rob.
Is this change required for this particular shader or in general iResolution should be always the dimension of the internal texture processed by the shader instead of the dimensions of the output window?

Rob Ramirez's icon

depends on if you want window dims or texture dims in your shader! typically shadertoy ported shaders should use texture dims (TEXDIMn)

spin lud's icon

depends on if you want window dims or texture dims in your shader! typically shadertoy ported shaders should use texture dims (TEXDIMn)

Good to know, thank you!

Has someone an idea, how we can get rid of the 3 horizontal lines on the top without scaling or cutting the output?

Not sure, maybe this line of code on the bufferA?

// Random particles at the top; xy is position, zw is velocity        
if (fragCoord.y > iResolution.y - 3.0) { 

I don't know on your system guys but on mine the FPS is not so great. I have tried to lower the shaders resolution to something lower but for some reason I get a black output 😅.
Maybe also lowering the number of particles could be a way, but didn't manage to do it yet.

hhelt's icon

Hello spin lud,

Thanks for your suggestion.
With (fragCoord.y > iResolution.y - 2.0) we get rid of the first horizontal line, which is great!
I tryed (fragCoord.y > iResolution.y - 3.0) which stopped all particles.

It would be great, if we simply start the drawing (not the simulation itself) from the third line and add 3 lines of simulation at the buttom.

So that the simulation output has +3 lines and the output is shiftet up 3 lines.
Does this makes sense?

Perhaps someone with more experience has a hint.

hhelt