Hallo all you Shader guys
Im a big shader noob and tried to write my first. So far I am pretty happy with my result. The shader does a circular texture blend between 2 texture and the center of this circle is the player. Now the circle has really jagged edges (see link below ). Probably because I calculate it in the vertex programm. I tried to move the calculation to the fregmant part but without luck. Hope you can help me with that
https://dl.dropboxusercontent.com/u/10920821/Unity-Help/texture-blend.png
Shader "Element/RadioTextureBlend"
{
Properties
{
_MainTex ("Main Texture", 2D) = "white" {}
_SecondTex ("Second Texture", 2D) = "black" {}
_Radius ("Radius", Float) = 0
_MyWorldPos ("my World Position", Vector) = (0, 0, 0, 0)
_TargetPos ("Target World Position", Vector) = (0, 0, 0, 0)
}
SubShader {
Pass
{
Tags {"Queue" = "Geometry"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform sampler2D _SecondTex;
uniform float4 _SecondTex_ST;
uniform float4 _MyWorldPos;
uniform float4 _TargetPos;
uniform float _Radius;
struct vertexInput
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct fragmentInput
{
float4 pos : SV_POSITION;
half2 uv : TEXCOORD0;
half2 uv2 : TEXCOORD1;
float dist;
};
fragmentInput vert(vertexInput i)
{
fragmentInput o;
o.pos = mul(UNITY_MATRIX_MVP, i.vertex);
o.uv = TRANSFORM_TEX(i.texcoord, _MainTex);
o.uv2 = TRANSFORM_TEX(i.texcoord, _SecondTex);
//float x = _TargetPos.x - o.pos.x;
//float y = _TargetPos.y - o.pos.y;
//float z = _TargetPos.z - o.pos.z;
//o.dist = sqrt( (x * x) + (y * y) + (z + z) );
o.dist = distance(mul(_Object2World ,i.vertex).xyz, _TargetPos.xyz);
return o;
}
half4 frag(fragmentInput i) : COLOR
{
if(i.dist - _Radius >= 0)
{
return tex2D(_MainTex, i.uv);
}
else
{
return tex2D(_SecondTex, i.uv2);
}
}
ENDCG
}
}
}
I also get a warning about dist (fragmentInput), not to have a semantic. What is the best way to get rid of it?