Here's a very simple shader,
float4 vert (float4 vertex :POSITION, out PositionHolder o) :SV_POSITION
{
UNITY_INITIALIZE_OUTPUT(PositionHolder,o);
o.localPos = vertex;
return UnityObjectToClipPos(vertex);
}
fixed4 frag (PositionHolder IN) :SV_Target
{
if (IN.localPos.y > -.2)
return _UpperColor;
else
return _LowerColor;
}
(So, if on a quad it just paints the top 70% in one color and the bottom stripe in another color.)
Notice that the only thing vert
does is pass along the local on the mesh vertex position.
Here's the struct to do so
struct PositionHolder
{
float3 localPos;
};
However, (in Unity, anyway) it will want a semantic for that float3.
Reviewing Unity's doco, they don't have any of course, but there's a link to
https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-semantics
(Aside - which, as I understand it, is specifically for D3D, but, I guess that's the syntax/semantic to go with anyway?)
My reading of the situation,
suggests you should use say,
struct PositionHolder
{
float3 localPos :POSITION1;
};
Or really, position-any-number you're not already using as a resource.
What about,
struct PositionHolder
{
float3 localPos :POSITION8;
};
for luck.
(Confusingly, they seem to run only from blank to 9, I don't know if that reflects a hardware reality, or is just something shoddy somewhere - or what. But anyway, basically "any number 1 to 9 you're not already using elsewhere.)
Note that anyway,
POSITION
is a float4, really is that ok for my float3?? Is there something better than POSITION for a general-purpose float3? (I've noticed if you just use, say, a COLOR, it also works fine. Does it matter?)Is the "1 on the end" system actually correct? So, POSITION1 is good to go? I'm not melting the gpu or some such?
Hmm, I've noticed you can just type ANYTHING in there (say, "abcd1"). But surely then it's not actually a hardware register thingy???