Hello guys !
I’m struggling with a custom shader :
Shader "Custom/HaloEffect" {
Properties{
_Position("Position", Vector) = (.0, .0, .0)
_HaloColor("Halo Color", Color) = (1.0, 1.0, 1.0, 1.0)
}
SubShader {
Tags { "Queue"="Transparent" "Render"="Transparent" "IgnoreProjector"="True"}
LOD 200
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
};
struct v2f {
float4 vertex : SV_POSITION;
float4 color : COLOR0;
};
uniform float3 _Position;
uniform float4 _HaloColor;
v2f vert(appdata v) {
v2f o;
o.color = _HaloColor;
o.color.a = 1 - distance(mul(unity_ObjectToWorld, v.vertex), _Position) ;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target {
return i.color;
}
ENDCG
}
}
FallBack "Diffuse"
}
The desired behaviour would have been to smootly set the alpha around the world coordinates named “_Position” on the mesh that would execute this shader. In this version the results are pretty near of what I expected. But the distances calculus are operated only on the vertices and the final interpolation is weird.
As you can see here the _Position is between 4 vertices of the plane:
And here is on one vertex:
I think It does the right work regarding what I wrote.
But, what I wished was a kind of a smooth circle.
I think I can managed to obtain this by doing the distance calculus in the Fragment Shader.
But I dont know how to get the world coordinates of the current pixel.
I try to compute an inverse of the MVP Matrix applied to the SV_POSITION, but it turns really bad.
Is the SV_POSITION is the same that gl_FragCoord ?
If I’am totally on the wrong way I wish you guys would tell me.
Please help me find a solution.