Why passing parameter is OK between Vertex and Fragment shader -


a typical shader this:

struct vin_vct          {             float4 vertex : position;             float4 color : color;             float2 texcoord : texcoord0;         };          struct v2f_vct         {             float4 vertex : position;             fixed4 color : color;             float2 texcoord : texcoord0;         };          v2f_vct vert_vct(vin_vct v)         {             v2f_vct o;             o.vertex = mul(unity_matrix_mvp, v.vertex);             o.color = v.color;             o.texcoord = v.texcoord;             return o;         }          fixed4 frag_mult(v2f_vct i) : color         {             fixed4 col = tex2d(_maintex, i.texcoord) * i.color;             return col;         } 

what i'm confused is: vert_vct called every vertex; frag_mult called every fragment (pixel in cases);

so frag_mult run different times vert_vct, example, frag mult runs 10 times, , vert_vct runs 3 times triangle. every time frag_mult runs accept parameter passed vert_vct, how map between frag , vert if run times different, how decide vert_vct pass specified frag_mult?

the counts vertex , fragment shader executions not directly connected.

if have triangle, correct hat vertex shader run 3 times, once each vertex. results interpolated -- is, rasterized -- onto many fragments covered final, projected on-screen triangle. might every pixel on screen huge triangle, or none triangle that's off-screen. if there visible pixels, fragment shader run once each 1 of pixels (err, fragments, gl nomenclature goes).

because values interpolated between vertices, may values on fragments not values single vertex, unless pass same value 3 of vertexes -- example, if have red vertices in model v.color pass o.color , i.color appear constant everywhere. then, values still being interpolated, since same, result constant.

does make sense you?


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -