Конечно же, намного оптимальнее сделать текстуру сразу с таким эффектом .
При удалении от объекта смотрится намного хуже, интересно какими способами можно это бороть .
Синтаксис:
Используется glsl
Shader "ImageProc EdgeDetectionSobel_BorderLands" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o)
{
float off = 1.0/1024;
// Sample the neighbor pixels
float s00 = tex2D(_MainTex, IN.uv_MainTex + float2(-off, -off));
float s01 = tex2D(_MainTex, IN.uv_MainTex + float2( 0, -off));
float s02 = tex2D(_MainTex, IN.uv_MainTex + float2( off, -off));
float s10 = tex2D(_MainTex, IN.uv_MainTex + float2(-off, 0));
float s12 = tex2D(_MainTex, IN.uv_MainTex + float2( off, 0));
float s20 = tex2D(_MainTex, IN.uv_MainTex + float2(-off, off));
float s21 = tex2D(_MainTex, IN.uv_MainTex + float2( 0, off));
float s22 = tex2D(_MainTex, IN.uv_MainTex + float2( off, off));
// Sobel filter in X and Y direction
float sobelX = s00 + 2 * s10 + s20 - s02 - 2 * s12 - s22;
float sobelY = s00 + 2 * s01 + s02 - s20 - 2 * s21 - s22;
// Find edge using a threshold of 0.07 which works generally
// well for general edge detection.
float edgeSqr = (sobelX * sobelX + sobelY * sobelY);
float threshold = 0.0049;//0.07*0.07;
half3 tmp = half3(0,0,0);
half3 one = half3(1,1,1);
if(edgeSqr > threshold)
{
tmp = one;
}
o.Albedo = one-tmp;
half4 color = tex2D(_MainTex, IN.uv_MainTex);
if(o.Albedo.r > 0.2)
{
o.Albedo = color;
}
}
ENDCG
}
Fallback "Diffuse"
}
Properties {
_MainTex ("Texture", 2D) = "white" {}
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
struct Input {
float2 uv_MainTex;
};
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o)
{
float off = 1.0/1024;
// Sample the neighbor pixels
float s00 = tex2D(_MainTex, IN.uv_MainTex + float2(-off, -off));
float s01 = tex2D(_MainTex, IN.uv_MainTex + float2( 0, -off));
float s02 = tex2D(_MainTex, IN.uv_MainTex + float2( off, -off));
float s10 = tex2D(_MainTex, IN.uv_MainTex + float2(-off, 0));
float s12 = tex2D(_MainTex, IN.uv_MainTex + float2( off, 0));
float s20 = tex2D(_MainTex, IN.uv_MainTex + float2(-off, off));
float s21 = tex2D(_MainTex, IN.uv_MainTex + float2( 0, off));
float s22 = tex2D(_MainTex, IN.uv_MainTex + float2( off, off));
// Sobel filter in X and Y direction
float sobelX = s00 + 2 * s10 + s20 - s02 - 2 * s12 - s22;
float sobelY = s00 + 2 * s01 + s02 - s20 - 2 * s21 - s22;
// Find edge using a threshold of 0.07 which works generally
// well for general edge detection.
float edgeSqr = (sobelX * sobelX + sobelY * sobelY);
float threshold = 0.0049;//0.07*0.07;
half3 tmp = half3(0,0,0);
half3 one = half3(1,1,1);
if(edgeSqr > threshold)
{
tmp = one;
}
o.Albedo = one-tmp;
half4 color = tex2D(_MainTex, IN.uv_MainTex);
if(o.Albedo.r > 0.2)
{
o.Albedo = color;
}
}
ENDCG
}
Fallback "Diffuse"
}