The PVAs come into the vertex shader "unbundled", but can then be copied into an interface block that will be passed on to subsequent stages. For example, consider the following global declarations in a vertex shader:
in float granularity; in vec2 delta; in vec3 direction; out GranularityInformation { float granularity; vec2 delta; vec3 direction; } granOut;
Then in, say, the main function of the vertex shader:
granOut.granularity = granularity; granOut.delta = delta; granOut.direction = direction;
Now suppose this information is to be used in a geometry shader and passed out of it to the next stage. We would have the following global declarations at the start of the geometry shader:
in GranularityInformation { float granularity; vec2 delta; vec3 direction; } granIn[]; // the size of the array will be determined based on the layout specification for the geometry shader out GranularityInformation { float granularity; vec2 delta; vec3 direction; } granOut;
Before each EmitVertex call, the geometry shader can use granIn to compute values for granOut for that vertex. Suppose a triangle is coming in, for example, and we have computed weights w0, w1, and w2 for a vertex to be emitted. We could then write:
granOut.granularity = w0 * granIn[0].granularity + w1 * granIn[1].granularity + w2 * granIn[2].granularity; … EmitVertex(); …
The entire declaration of an interface block starting from its name ("GranularityInformation" above) to the closing brace ("}") must be exactly the same in every shader stage that uses it.
in float puktocity;If this PVA will only be used in the vertex shader, then simply write your vertex shader code to use it as desired. Skip the rest of this step, skip step 2, and go directly to step 3.
On the other hand, if this PVA needs to be passed to another shader stage (geometry shader, fragment shader, etc.), then it is oftentimes most convenient to use interface blocks as described above. Depending on your program, you may be able to add it to an existing one, or you may want to create a new interface block for this (and possibly other) variables.
out ThePVABlockToBeUsed { … // other variables, if any float puktocity; } pva_out;Then at an appropriate place in the vertex shader code:
pva_out.puktocity = puktocity;
in ThePVABlockToBeUsed { … // other variables, if any float puktocity; } pva_in;Note that pva_in will be a singleton instance as shown here in, say, the fragment shader. However, it will need to be an array (e.g., pva_in[]) in others (e.g., the geometry shader).
uniform int flag;Then simply use flag in the shader program however you wish.