Painting shader problems when using linear space

Hello all,
I am making a painting system, where you are able to use a brush and paint onto a render texture. I’ve made a shader that handles that and overall, it is quite a simple system. Everything works great when the color space is set to Gamma. However, if color space is Linear instead, there are a bunch of issues.

This snake looking thing is actually me painting with a normal brush. With gamma space, this whole thing would be all white, but with color space set to linear, there are some weird issues that create such a weird result.

I know that I might need to convert from linear to gamma or vice versa, but I am not sure where this conversion needs to happen.

This is pretty much how I am handling painting:

When I am painting, I am firstly creating an area map, like so:

fixed4 col = tex2D(_MainTex /* <-- Brush Mask */, i.uv);
col *= _OpacityJitter;

return saturate(col);

And then I tint this area map in another shader, like so:

fixed4 col = tex2D(_Source, i.uv);
               
col.rgb /= col.a;
col.rgb *= _Color.rgb;
col.rgb *= col.a;

col *= _Opacity;

return saturate(col);

I am also always using premultiplied alpha Blend One OneMinusSrcAlpha
What is the cause of this issue and what steps should I take to solve this problem?

Any help would be appreciated! Thank you!

What is the divide by the alpha for? Is the texture asset you’re using already using pre-multiplied color? That won’t work unless it was pre-multiplied with knowledge of color space you’re rendering with and if that asset is sRGB or not. An easy fix for now might be to disable sRGB for this texture, assuming it’s otherwise a solid white.

However there’s no need to do the / alpha and * alpha. Just multiply the col.rgb by the _Color and you’re good to go.