Sending More Information From
Vertex To Fragment
We can define a structure to send more information about
each vertex to its respective fragment program.
•
...
struct VertexToFragment {
float4 position : SV_POSITION;
float3 localPosition : TEXCOORD0;
};
VertexToFragment MyVertexProgram(float4 position : POSITION){
VertexToFragment v2f;
v2f.localPosition = position.xyz;
v2f.position = UnityObjectToClipPos(position);
return v2f;
Makes a copy of
the local position
of the vertex.
}
float4 MyFragmentProgram(VertexToFragment v2f) : SV_TARGET{
return float4(v2f.localPosition + 0.5, 1) * _Color;
}
Uses the local position of the
vertex to compute its color.
...