unity-game-enginehlslantialiasing

How to remove anti-aliasing artifacts inside the object's material HLSL shader (Unity)


I am trying to create a shader that would blend a background's texture with the 3d object's texture. The background texture is a render texture from another camera. I pass it to the shader of the foreground object.
The idea is to achieve an effect of various blendings on the 3d object "in the front". The fragment shder looks like this:

fixed4 frag(v2f i) : SV_Target
{
    float4 color_from_background = tex2D(_BackTex, float2(i.pos.x / _ScreenParams.x,  i.pos.y / _ScreenParams.y)); //A 
    fixed4 surfcol = tex2D(_MainTex, i.uv);
    fixed4 c = BlendMode_Multiply(color_from_background,fixed4(surfcol.rgb,surfcol.a * _Transparency));
    return c;
}

It kind of works... Unfortunately due to imprecisions in the division in the line marked with "//A" - I get visible artifacts along the object's edges. In this line I sample the background texture for the blending's input, How to solve that? First thing that comes to my mind is anti-aliasing. But I dont know how to implement it here. I tried to change sampling levels and filtering of the textures but it does not solve the problem. I attach image that shows the problem. At the top part you can see the artifacts when using the shader. At the bottom the actual object with non-opaque material.

enter image description here


Solution

  • The solution to this is disabling the anti-aliasing in the project settings globally OR in the target render texture settings and camera settings. I only had it off in the target render texture which was not enough