I am a newbie in programming shaders… I want to calculate the distance between camera and the object (attached shader). I found something like this…
float curDistance = distance(_CentrePoint.xyz, IN.worldPos);
my shader looks like this…
Shader "Custom/VertexColor" {
Properties {
_PointSize ("Point Size", Float) = 1
}
SubShader {
Pass {
LOD 200
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
float _PointSize;
struct VertexInput {
float4 v : POSITION;
float4 color: COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float4 col : COLOR;
float4 size : PSIZE;
};
VertexOutput vert(VertexInput v) {
VertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.v);
o.col = v.color;
o.size = _PointSize;
return o;
}
float4 frag(VertexOutput o) : COLOR {
return o.col;
}
ENDCG
}
}
}