Hi Guys!
I'm starting to get to know GLSL a little bit better and I tried a simple Copper/Rasterbars Shader to get more familiar with the language.
The Shader uses a for-loop to determine if some bar are in distance of the current normalized position...
for (int c=RASTERS; c > 0; c--) {
float jd = sin(time+(ANG2RAD*float(c)))*0.2;
yd = 1. - (1./maxRast* abs( jd+YBASE - p.y));
if (yd > 0.) {
break;
}
}
I'm a little bit curious about the for-loop initialization and the scope of it's variable "c". If I declare the variable outside of the loop, it works but the value in c is not correct AFTER the for loop has finished - as you can see if no hit occures c should be 0, or should have the "bar"-counter. If I don't declare the variable outside the compiler mocks me that c is not declared (which is a C-like-scope behaviour).
So for now I took a 2nd variable, and if a bar is in distance I copy c to the 2nd variable..
The Scope-behaviour seems different from C.. or I didn't get it right. It seems that this behaviour of scope is only with for-loops...
Have I done something wrong with GLSL or is this the normal behaviour (which would be very curious!) ?
Have a nice day and greets
