- Real-Time 3D Graphics with WebGL 2
- Farhad Ghayour Diego Cantor
- 96字
- 2021-06-10 19:43:06
Varyings
As described earlier, varyings allow for the vertex shader to pass information to the fragment shader. For example, if we want to carry the vertex color from the vertex shader to the fragment shader, we would first update our vertex shader:
#version 300 es
out vec4 vVertexColor;
void main(void) {
vVertexColor = vec4(1.0, 1.0, 1.0, 1.0);
}
And we would reference that varying inside of our fragment shader as follows:
in vec4 vVertexColor;
Keep in the mind that the Storage Qualifier, the declaration of varyings, needs to match between the vertex and fragment shaders.