How to declare/use an array of varyings in TSL?

Hey, I can’t figure out how to create an array of varyings in TSL.
For instance, in GLSL, I would declare it like this: varying float myArray[LENGTH];
I tried using the TSL transpiler, but when writing varying, I got /* unknown statement */.

So, how do I do it in TSL?

Thank you!

There is an issue at GitHub that tracks this topic:

I don’t think TSL already supports arrays as varyings. We probably need a new issue for that.

Are you 100% sure that this works in GLSL? If so, how does it work, i didn’t know it was possible?

1 Like

A fiddle that demonstrate the usage of arrays as varyings would be indeed helpful. Use this as a starter template: https://jsfiddle.net/3mrkqyea/

1 Like

ChatGPT claims that it’s not something that should work? OP are you sure you weren’t thinking about uniforms?

demo: https://jsfiddle.net/Lsnvb2qy/

4 Likes

In this case, feel free to file a feature request. at GitHub.

Once again ChatGPT has proven that it’s better to not rely on its statements^^.

1 Like

will do, thanks !

2 Likes

Thank you for the example!!

2 Likes

you’re welcome @dubois
I opened an issue:

2 Likes

This is good :blush: GLSL has been pretty consistent, I’m surprised it got this wrong but it might mean that us graphics people might be employable for a bit longer.

Hi @qtnrtnd

This page deserves to be in showcase! :wink:

2 Likes

Does anyone have an alternative to replicate what I did in my demo without using arrays of varyings?

to use a uniformArray element in your TSL, you reference it like this

myarray.element(123)

instead of glsl version

myarray[123]

This TSL example has a uniformArray of colours.

I looked at your code, and i dont really know what it is doing. Do you need to use varyings?

Hi,
In the demo I provided, I use arrays of varyings to perform calculations related to textures in the vertex stage instead of the fragment stage. Essentially, this computes individual texture UVs and “bounds” for cropping in the fragment stage. However, for now, I will do everything in the vertex stage.

Edit: I could replicate what I did using varyings (but not as arrays) with a JavaScript for loop (not a TSL Loop). The downside is that a lot of code gets duplicated once the shader is transpiled.