Hey guys, as far as I understand, if you do something like this:
struct v2f
{
float4 vertex : POSITION;
float3 normal : COLOR; // or TEXCOORD
};
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.normal = float3(-1,0,0); // this
return o;
}
o.normal will be clamped to the 0…1 range, so it will be (0,0,0,1), so you have to do something like normal * 0.5 + 0.5 to compress it, and then in the fragment shader uncompress it with ( normal - 0.5 ) * 2.
But for some reason, having this fragment program:
fixed3 frag (v2f i) : SV_Target
{
return i.normal * -1;
}
the result is ALWAYS red ( since (-1,0,0) * -1 = (1,0,0) ), if unity were to clamp those values, then the result should be black since (0,0,0) * -1 = (0,0,0). So either there’s something that I didn’t read in the documentation, or I’m doing something wrong. Does someone have any clue whats going on ? Cheers