Reputation:
I'm using WebGL and I want to use structured code in my fragment and vertex shader code, not just define them globally, because of the sharpened eyes with a lot of work with OOP.
And I've got the next problem, that I can't define different qualifiers for different struct
members.
For e.g.:
struct Light
{
vec3 normal;
vec3 position;
bool isDirectional;
...
};
I can create an instance of this struct like:
uniform Light lightInstance;
But, as you're able to see, I can define only a single qualifier.
If to try use something like that:
varying Light.normal normalValue;
uniform Light.position lightPosition;
Then, also I can't use typedef
, memcpy
, pointers
with using GLSL.
I know, that I should read more about GLSL and I shall do it.
But it's rather difficult to get well documentation exactly about WebGL shading language.
So, the question is: I want to define different qualifiers for the different members of the single struct. Is it even possible in GLSL (which is for the WebGL)? If the answer is no, what is the elegant way to pass it?
Upvotes: 0
Views: 1302
Reputation:
Reference for the GLSL ES.
Programming a GPU through a shading language is not the same as programming a CPU with C, a GPU is not a CPU and GLSL is not C: some keywords and constructs are missing.
You should consider you vertex shader as function where uniform values are global read only variables and varying values are output values. A fragment shader is similar, but varying values are now the input values and uniform are still global read only variables.
So global vars are not what they usually are in a CPU application and shader rarely get complex enough to benefit from OOP, a procedural approach is still more elegant.
Why would you want to have a member of a structure qualified as uniform
and another member of the same structure as varying
?
Usually a light is uniform, between what values (i.e. vertex attributes) would the normal member of the light (the direction?) be interpolated?
This attempt of qualifiers use either means that you don't fully understand what uniform and varying variable are or you don't fully understand what struct
is used for in programming.
Upvotes: 2