How to order the inputs of a GLSL shader

jrs's picture

Hi All - I had a search through the forums as I assumed this would have been covered but can't find anything.

I have a heap of points (48) being fed into a GLSL patch and I'd like to keep them ordered but no matter what I name them (ie they are not sorted alphabetically) or the order I create them they seem to choose some random order.

Attached is an image with half of them - Surely there is an easier/prettier way?

Cheers James

PreviewAttachmentSize
BoundingBox-Poles2.qtz - Editor.jpg
BoundingBox-Poles2.qtz - Editor.jpg29.21 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

jrs's picture
Re: How to order the inputs of a GLSL shader

Can I pass a structure with 3 points in and access its elements from within the GLSL? if so what format should the structure be in (named with keyx x,y,z or index based with 1,2,3 etc) - forgive me for any short sightedness as this is my first attempt at GLSL.

Cheers James

gtoledo3's picture
Re: How to order the inputs of a GLSL shader

Ports usually get placed in the order that they've been used in the code, but I've noticed that some version of OS X doesn't do that correctly(10.7.something)... or maybe it stopped working that way all together (?).

So, not the order that you list the ports, but the order which they are invoked in functions/the main/assigned to other variables. If it's really annoying to you, you can do something like:

uniform vec4 inputVariable; vec4 var1 = inputVariable;

So that you immediately use "inputVariable" in code, and spawn an input. It's kinda crappy to beef up the code like that - hard to say if it makes much difference in performance or not without testing. It probably will not with most shaders.

gtoledo3's picture
Re: How to order the inputs of a GLSL shader

QCStructure is a kind of container that holds a few different structure types and data (some that exist outside of QC, some that do not) - it's best to think of it as a custom thing that only exists in QC. The public types that a QCStructure can consist of don't have any kind of native match to what's going on in GLSL. GLSL doesn't have a notion of directly inputting a NSArray, for example.

The closest thing you can do in this version of glsl is to use a color port to control four points at a time, or use a texture and read the color values of that texture. A texture is essentially a structure of vec4's mapped in x/y space.

I don't recommend doing that - color or texture color is going to usually fall in a 0~1 range, and your resolution of steps will be limited. It probably doesn't solve any problems for you either.

You're probably best manually fanning out the structure manually to input floats (or whatever other value types) to control your inputs from some incoming structure.

BTW, off the top of my head, the supported input port types in the shader are image, float, vec2, vec3, vec4, bool, int, color. I may be missing something.

jrs's picture
Re: How to order the inputs of a GLSL shader

I bit the bullet and just noodled em up....it was painful. I'm on 10.8 and it doesn't seem to be the order I use the variables as the first thing I do with each x/y/z variable is make them back into a point (see attached screenshot). Whilst its done now it made me really consider doing this task outside of QC.

gtoledo3's picture
Re: How to order the inputs of a GLSL shader

Yeah, but if you did it outside of qc you'd still have a shitload of "ObjectAtIndex" stuff to manually code. I can't think of any freebie.

gtoledo3's picture
Re: How to order the inputs of a GLSL shader

Did a port spawn after you list the variable? If so, did the order change afterwards or something? No big deal, just curious what's going on with that now.

jrs's picture
Re: How to order the inputs of a GLSL shader

The ports spawn when you use them in an equation at which point they seem to choose some random ordering