GLSL - Declaring global variables outside of the main loop
Does it help to declare variables outside of your main loop in GLSL? Do
these variables actually get reused and is it more efficient?
Here is the code in question:
varying vec2 vposition;
uniform float seed;
uniform float top;
uniform float bottom;
uniform float phi;
uniform float theta;
uniform float scaledPI;
uniform float yn;
uniform float ym;
uniform float rx;
uniform float ry;
uniform float radius;
const float PI = 3.141592653589793238462643383;
float left;
float right;
float mscaled;
float xn;
float xm;
void main() {
float t = vposition.y * yn + ym;
if(t <= 0.0 || t >= PI){
left = phi - PI;
right = phi + PI;
}else{
mscaled = scaledPI / (1 - abs(Math.cos(theta)));
mscaled = mscaled < PI ? mscaled : PI;
left = phi - mscaled;
right = phi + mscaled;
}
xn = (left - right) / ((-rx / 2.0) - (rx / 2.0));
xm = left - ((-rx/2.0) * xn);
float p = vposition.x * xn + xm;
vec3 coords = vec3( sin(p) * sin(t), cos(t), cos(p) * sin(t) );
float nv = surface( vec4( coords, seed ) );
gl_FragColor = vec4( vec3( nv, nv, nv ), 1.0 );
}
No comments:
Post a Comment