Global variables in GLSL?

Asked

Viewed 50 times

0

Is there any way to declare variables so that they can be used in other files, with the same value as the original? I have tried using varying but it only works for the file .vsh and .fsh of the same part. Example:

In the archive Composite.vsh:

bool isNight = false;
void main() {
    isNight = true;
}

Ay, I use that same variable in the file skybasic.vsh:

if (isNight) {
    //está noite
}

without having to "recreate" this variable all over again. How can I do this?

1 answer

1

I’m not sure what you’re trying to do. Variables like varying serve to pass data from Vertex Shader to Fragment Shader.

There are variables of type attribute that you send the values through your application, then from the application code, you can send to as many shaders as you want.

There are also the kind uniform, which are sent from the application, the difference in relation to the attribute is that the uniform cannot be modified after they are in Shader. I think your case is the uniform

Browser other questions tagged

You are not signed in. Login or sign up in order to post.