Hello I’m trying to make a blender2.8 matcap imitation so far its fairly good , the error is in the corners (hopefully i have the image attached correctly , black with white edges) , i don’t really know how to fix my mistake the idea is to use a dot product on a surface to eye vector with a tangent of the normals.
thanks.
Shader "Unlit/matcatallsurface_vf"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_MatCap ("matcap",2D) = "black" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
Tags { "LightMode" = "Always" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
float2 mat : TEXCOORD1;
};
sampler2D _MainTex , _MatCap;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
float3 worldPos = mul(unity_ObjectToWorld, v.vertex);
float3 worldNormal = mul(unity_ObjectToWorld, v.normal);
float3 toCam = normalize(_WorldSpaceCameraPos.xyz - worldPos);
float3 cx = normalize( cross(-worldNormal, UNITY_MATRIX_V[1]) );
float3 cy = normalize( cross(-worldNormal, UNITY_MATRIX_V[0]) );
o.mat = float2( dot(toCam, cx) , dot(toCam, -cy) )*.5+.5;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 matcap = tex2D(_MatCap, i.mat.xy);
return col *2*matcap;
}
ENDCG
}
}
}