glsl - How does OpenGL interpolate varying variables on the fragment shader even if they are only set three times on the vertex shader? -


since vertex shader run once per vertex (that mean in triangle 3 times), how varying variable gets computed every fragment, if it's assigned (as in example) 3 times?

fragment shader:

precision mediump float; varying vec4 v_color;  void main() {     gl_fragcolor = v_color; } 

vertex shader:

attribute vec4 a_position; attribute vec4 a_color;  varying vec4 v_color;  void main() {     v_color = a_color;     gl_position = a_position; } 

so, question is, how system behind know, how compute variable v_color @ every fragment, since shader assigns v_color 3 times (in triangle).

all outputs of vertex shader per vertex. when set v_color in vertex shader, sets on current vertex. when fragment shader runs, reads v_color value each vertex in primitive , interpolates between them based on fragment's location.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -