PurpleKingdomGames / ultraviolet

Scala 3 to GLSL transpiler library
https://ultraviolet.indigoengine.io/
MIT License
59 stars 2 forks source link

Improving for loops / for loops could support tuples #67

Open davesmith00000 opened 1 year ago

davesmith00000 commented 1 year ago

A collision of langugaes!

Scala has no c-like for loops on the notion that we use for for other things and anything you can encode as a for loop you can encode as a while loop.

for loops in GLSL are a big thing however, especially in demoscene-like code-golfing, but also because support for while loops is not universal across graphics hardware. :scream_cat: *

Things like this are common:

for(int i = 0, j = count - 1; i < count; j = i, i++) {
  ...
}

And that is tame compared to this:

vec2 p;for(float i,f;i++<1e1;o+=(1e1-f)/max(length(p=mod((FC.xy*2.-r)/r.y*f*rotate2D(i),2.)-1.)+cos(atan(p.y,p.x)*5.+t*cos(i))/3e1-vec4(7,8,9,0)/6e1,.01)/8e2)f=mod(i-t,1e1);

It would be nice, as a nod towards the former case to be able to use tuples as the initial type.

I also note that above we have a Float for i and I'm not sure we support that either? - Checked, this works fine.

(* Could be wrong / could be out of date advice)