When I tried the vignette effect, it gave me the hard edges you can see in the picture below. I gave a shot at doing my own shader for it, and even if I’m able to make them more sublte, it isn’t quite as smooth as I’d like. I know it’s due to the gap between the 256 levels of grayscale, but i’d like to know if there’s any workaround for this.
The screenshot below is the camera facing a gray plane. I included my shader code below.
Shader "test/VignettingShader" {
Properties {
_MainTex ("Base", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
ENDCG
Subshader {
Pass {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
CGPROGRAM
#pragma fragmentoption ARB_precision_hint_fastest
#pragma vertex vert
#pragma fragment frag
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
v2f vert( appdata_img v ) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord.xy;
return o;
}
half4 frag(v2f i) : COLOR {
float2 texCoord=i.uv;
// Take texture color
half4 color = tex2D (_MainTex, i.uv);
//vignette effect
texCoord -= 0.5;
float vignette = 1.0 - pow(dot(texCoord, texCoord),1);
vignette = pow(vignette,5);//determine vignette amount
color*=vignette;
return color;
}
ENDCG
}
}
Fallback off
}