Hi, I need to pass the actual vertex coordinate from my vertex to my fragment shader without interpolation. I tried using a uniform variable but for some reason it seems not to hold a valid value at all.
An example:
Shader "Vertex Colored" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float3 _p1,_p2;
struct v2f {
float4 pos : SV_POSITION;
float3 color : COLOR0;
float3 bc : TEXCOORD2;
float3 p : TEXCOORD3;
};
float PtoLine(float3 a, float3 b, float3 p)
{
return length(cross(p-a, p-b))/length(b-a);
}
v2f vert (appdata_full v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
_p1 = v.vertex.xyz;
_p2 = v.tangent.xyz;
o.p = v.vertex;
o.color = v.color;
o.bc = v.tangent.xyz;
return o;
}
half4 frag (v2f i) : COLOR
{
//return half4(i.bc, 1);
return half4(_p1,1);
if(1>0)
return half4(0,0,0,1);
else
return half4 (i.color, 1);
}
ENDCG
}
}
Fallback " VertexLit", 1
}
This will ALWAYS render black, no matter what the vertex coordinate is. What is going on here ?