I am new to 3d programming. Recently I found uv mapping is confusing to me.
using
tex ft0, v1, fs0 <2d,repeat,nomip>
mov oc, ft0
I gives v1 as uv coordinate and fs0 for texture bitmap, this worked as it is. Textures wrapped the 3D objects.
But I only copied ft0 to oc once with one coordinate v1, how the system knows what to fill the else area ?
and I didn't provide the vertex coordinate either, did fragment program get call every pixel or every vertex render?
Well, first you're getting 'v1':(Varying register 1) from the vertex shader: By setting it from one of your (Vertex attributes) 'vaX', usually: mov vX, vaX
or other operations.
What a varying register does (ie 'v1') is interpolate the values of uv (ie 'vaX') for the three vertices which make up the triangle.
Note:Varying registers are the only way you can communicate between vertex and fragment shaders.
For each pixel, the 'tex' function will sample an area 'v1' (rasterise) from the texture sampler 'fs0' with the rules between the brackets (ie <2d,repeat,nomip>).
Think of the first line as ft0 = fs0.getPixel(v1)
, with v1 running from say va1(1)[x, y, z, w] to va1(2)[x, y, z, w] (z can be used for lighting and other effects), you are then outputting this one pixel/fragment to 'oc' (Output color).
Fragment shader are also called Pixel shaders -> get called once for every pixel.
On the other hand Pixel Shaders are called once for every vertex.
There is a third type of shaders called Geometry shaders, but aren't available in Stage3D/AGAL.