gl3 package update 0.1.1

Rob Ramirez's icon

Hey everyone, there is an update to the gl3 package currently live in the Package Manager.

Big thanks to everyone who has taken it for a spin and provided your feedback and bug reports.

Changelist below:
- jit.gl.slab fix read message (affecting some vizzie modules)
- jit.gl.mesh fix draw_modes that require splitting on matrix input rows
- put in some checks and warnings for opengl versions on specific features, prevent crashing
- allow OpenGL 3.2 supported contexts on Mac
- better error reporting when encountering unsupported hardware
- jit.gl.sketch fix cmd_enable message
- jit.gl.buffer fix context rebuilding when @texbuf enabled
- fix tb.point.lights.jxs lighting calculation
- jit.gl.texture fix for file read with @type float32
- jit.gl.mesh handle non-standard planecounts on input matrix

Guillaume's icon

Hey this package is great thank you very much for that. I especially like the shadertoy loader. Is it working also with Multipass shaders ?

Rob Ramirez's icon

hey GUILLAUME, the shadertoy loader is there mainly as as starting point (I am just now noticing that it will fail on any shaders that have cubemaps as input channels). I believe multi-pass shaders will just involve creating a jit.gl.slab for each buffer, and sending them as inputs to the main slab (don't use the leftmost inlet, that's just there to map to window size). if there's a particular one you're interested in please take a crack at it and post here if you get stuck.

billyanok's icon

Hey,
Are there any issues using GL3 on standalones?

Thx,
Bill

Guillaume's icon

Thank you Rob, I will try to post something today :)

Guillaume's icon

it's perfeclty working yes!

Rob Ramirez's icon

@BILLYANOK, I just tested and it does seem to work OK, but you'll have to manually copy the gl3 package into the c74/resources/packages folder of your standalone. You will also have to ensure that your app preference glengine setting is set to gl3. you can either manage this file yourself, or the first time you launch your app open a file with the a loadbang on a message box with:
; max glengine gl3

@GUILLAUME please share!

billyanok's icon

Rob,
Thank you for the reply.
Curious, How would I "manage this file yourself.."?
Is this in the Plist file?
Bill

billyanok's icon

Hey Rob,
The message box with "; max glengine gl3" and copying GL3 folder works a treat.
ThX!
Bill

Guillaume's icon

I'm so happy for the shadertoy loader, in 10min we can have beautifull results, I share the patch

glitch2.gl3.jxs
jxs 4.04 KB

shadertoy_example.maxpat
text/plain 10.24 KB

supernova.gl3.jxs
jxs 4.46 KB

Rob Ramirez's icon

very cool!

Guillaume's icon

hey Rob, I tried another shadertoy code, and I have this error:
error C1503: undefined variable "iChannelResolution"

I think max doesn't understand what is "iChannelResolution[0].xy" variable. I think is the resolution of the channel 0 in pixel. Do you know by what I need to replace this expression ?

by the way is this one : https://www.shadertoy.com/view/ldV3Wc

Rob Ramirez's icon

unforutnately the iChannelResolution uniform array does not easily map to Jitter's builtin texture-dimension state uniforms which are not passed as an array (TEXDIM0, TEXDIM1, etc). so you must first add in the uniform declarations and bindings for any of these variables used, noting that in the shadertoy jxs template the iChannel0 texture is actually bound to jitter texture 1 (first texture is simply a dummy texture)
<param name="iChannelResolution0" type="vec2" state="TEXDIM1" />
<param name="iChannelResolution1" type="vec2" state="TEXDIM2" />
<bind param="iChannelResolution0" program="fp" />
<bind param="iChannelResolution1" program="fp" />
...
uniform vec2 iChannelResolution0;
uniform vec2 iChannelResolution1;

finally you must find and replace the array with your newly declared uniform, e.g. find iChannelResolution[0] and replace with iChannelResolution0.

we can add all the declarations to the template for a future gl3 package update, leaving the only task for users the search and replace in the pasted in shadertoy glsl.

billyanok's icon

Guillaume,
Did you manage to get this working?
I must have missed something very simple?
No errors in console.
Thx,
Bill

Guillaume's icon

Hey thanks Rob, no errors in the console now with your code. But at the end my window is black so for me is not working but I don't know why and the code from shadertoy is too much complicated for me to understand... I will post the patch here if someone want to look inside

Guillaume's icon

So here is the patch. I tried to clean up so I hope it will be readable for you. I think problems starts in the jit.gl.slab buffer C. Have a nice day guys

Da.gl3.jxs
jxs 4.78 KB

Db.gl3.jxs
jxs 5.46 KB

Dc.gl3.jxs
jxs 8.68 KB

Dd.gl3.jxs
jxs 3.56 KB

Delaunay(not_working).maxpat
text/plain 47.99 KB

Di.gl3.jxs
jxs 6.53 KB

Jaky's icon

Hi there, very exciting upgrade! thanks

I get this error message
from 3D texture 1 & 2 in the xample patches

jit.gl.texture: update_teximage_state: GL Error: Out of memory

GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT

I am on a i7 + GTX 1060

Rob Ramirez's icon

hi JAKY, thanks much for testing. see the thread here regarding your report: https://cycling74.com/forums/issues-with-certain-gl3-features

Rob Ramirez's icon

GUILLAUME, I'll try to find some time to look at this in more detail in the not too distant future, but hopefully some others can also take a look.

Federico-AmazingMaxStuff's icon

Hi Rob,
seconding Byllianok, how can I create this file in order to have the external always to start with the gl3 engine? What's the syntax and where should it be put in the resources?
Thank you!

Rob Ramirez's icon

check out the "preffilename" attribute in the standalone object's reference page.

you could write out this preference file to the correct location using some script as part of the application install process.

easier may be to create a loader patch that first sets the preference via the ; max glengine gl3 message, and then loads the guts of the patch. As long as that preference is set prior to any jitter objects instantiating then you should be good.

Federico-AmazingMaxStuff's icon

Thank you a lot for the fast reply!

Federico-AmazingMaxStuff's icon

Hi again Rob, using a ; max glengine gl3 message prompts the user to restart the application with a pop-up dialogue.
Could you elaborate on the preference file further?
This should fix the issue with the pop-up box.

Rob Ramirez's icon

the message needs to be sent before any jitter objects are loaded (otherwise you get the restart dialog), so your app probably needs to have some type of loader patch that sets the pref and then immediately loads the "guts" of the app (either via scripting or pcontrol "load" message).

i've never tried messing with the standalone preference files, so the standalone object reference is your friend (as well as tim places's standalone walkthrough videos). In theory, you can copy the standalone preference file to the appropriate place via some installer script.

Federico-AmazingMaxStuff's icon

Thank you very much Rob!

So, for what I see there is no way on the standalone object to set the GL engine.
Am I missing something?

Federico-AmazingMaxStuff's icon

Also, changing the engine and then using the pcontrol to load the main patch, prompts the dialogue box to restart Max.

That's the loader patch I'm using:

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

Federico-AmazingMaxStuff's icon

Ok, I simply wrote: max glengine gl3 inside one of the txt files in the init folder of the standalone and it seems to work!

Rob Ramirez's icon

yes, that's the ticket! nice find!

Jaehoon Choi's icon

Hello everyone! I have a question related to shadertoy in Max.
I trying to implement a shadertoy which takes audio as an input for iChannel (https://www.shadertoy.com/view/lsV3W1)
Does anyone know how to take audio as an input to jit.gl.slab in Max?

Rob Ramirez's icon

the ISF package has a pretty great audio-to-texture utility for its audio-reactive shaders. I went ahead and adapted that to the format expected by shadertoy (512x2 texture, fft in first row, waveform in second) and ported the basic shadertoy sound shader.

this should give you enough to go on to port any audio based shader you like.

shadertoy.audio.maxpat
Max Patch

shadertoy.audio.gl3.jxs
jxs 3.13 KB

πŸ‘½'tWβˆ†s βˆ†lienzπŸ‘½'s icon

Thank you so much for those, Rob!

Federico-AmazingMaxStuff's icon

That's amazing Rob!!
Can I ask you what's the purpose of the [jit.scissors @rows 1 @columns 2] object?
And the jit.expr with the log is to uniformly represent the frequency spectrum?
Thank you!

Rob Ramirez's icon

the scissors is just chopping the lower half of the spectrum, as the upper half is redundant i believe? and that's my guess as well on the jit.expr.

lots of ideas in this domain to be mined searching the forums for "spectroscope" or some variation (including the origins of the ISF patcher). This one is pretty interesting as well.

Federico-AmazingMaxStuff's icon

Amazing! Thank you

Jaehoon Choi's icon

Thank you so much!!

Jaehoon Choi's icon

Hello Rob, I succeeded getting the audio input part working. Thanks alot!
I have one more question related to Rob's patch. The shadertoy that I would want to implement has one buffer and one image. The buffer takes the audio signal in iChannel0(which is now working!), and takes itself to iChannel1.

For Multi-buffer shadertoy, I tried the technique introduced by Federico in his youtube channel(you are awesome Federico!!). However, the patch Rob created takes iChannel0, which was the texture converted from the audio in his original patch, in the right inlet, whereas Ferderico took iChannel0 input to the left inlet, and iChannel1 input to the right inlet through a [jit.gl.slab @automatic0 @thru 0].

Did the syntax for jit.gl.slab have changed then before?; which totally makes sense since this tutorial was made almost 3 years ago. If this is the case, I would appreciate it if anyone knows how to deal with multi-buffer shadertoy in the current version.

Thanks! All of you are amazing :)

Rob Ramirez's icon

it depends on how your shader is structured. for the shadertoy example distributed with gl3, the leftmost inlet is simply used to size and trigger the output, and otherwise is ignored in the shader. This is not a requirement, but seemed to me at the time to make porting between the 2 spaces easier. I've also since realized that it probably makes more sense to require @rectangle 0 on all slabs and texture inputs, which gives better compatibility with Shadertoy source.

Implementing shadertoy buffers requires a separate jit.gl.slab for each buffer, so it probably makes sense to implement a more specific shader (rather than the general purpose one provided with the package). It also requires implementing some kind of initialization stage (ie sending a "dummy" texture input at the desired dimensions and texture type), and in cases where the buffer takes itself as input, a loopback stage (an extra jit.gl.slab to store the output and then patched back into the input).

I've got an example of this working for a fairly complicated shadertoy effect, but it requires an update to the gl3 engine to fix a bug with cubemap inputs. I will try and push this update out sometime this week, but in the meantime I've attached the shader and patch here. This archive also contains updated versions of the gl3 extension for both Mac and Windows, that should work with the current release version of Max 8, simply replace these files in Documents/Max 8/Packages/gl3/extensions.

molten.bismuth.zip
application/zip 1.28 MB

πŸ‘½'tWβˆ†s βˆ†lienzπŸ‘½'s icon

an emoji rendering of my reaction to your molten-bismuth: πŸ€―πŸ’¨πŸŒŠ

thanks again, Rob! πŸŒšπŸ†πŸŒ

(also, just noticed that gl3 itself is a max extern(.mxo/.mxe64)...interesting πŸ€”πŸ§πŸ€“)

Rob Ramirez's icon

always glad to get an emoji symphony Raja! and yes, that particular shadertoy is a beauty. all kudos to the original author, i just copied and pasted and moved some boxes around.