Layer Mask for Fog Shader

Hi, I’ve been working on adding fog to my game and found a shader in Youtuber by Acerolla. It’s doing a good job, but there’s a problem. the fog ends up covering the entire skybox and I don’t know much about shaders so I couldn’t fix it. It would be awesome if I could get some help in adding a layer mask or something similar. This way, I could add multiple fog layers and adjust the fog density for the skybox or other objects separately.

I did try the built in fog system but it just not giving me the level of density I’m looking for. if there are other shaders you could suggest it would be nice too.
Thanks for your help.

Here’s the shader I got:

Shader "Hidden/SSFog" {
    Properties {
        _MainTex ("Texture", 2D) = "white" {}

    SubShader {

        Pass {
            #pragma vertex vp
            #pragma fragment fp

            #include "UnityCG.cginc"

            struct VertexData {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;

            struct v2f {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;

            v2f vp(VertexData v) {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;

            sampler2D _MainTex, _CameraDepthTexture;
            float4 _FogColor;
            float _FogDensity, _FogOffset;

            float4 fp(v2f i) : SV_Target {
                int x, y;
                float4 col = tex2D(_MainTex, i.uv);
                float depth = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.uv);
                depth = Linear01Depth(depth);

                float viewDistance = depth * _ProjectionParams.z;

                float fogFactor = (_FogDensity / sqrt(log(2))) * max(0.0f, viewDistance - _FogOffset);
                fogFactor = exp2(-fogFactor * fogFactor);

                float4 fogOutput = lerp(_FogColor, col, saturate(fogFactor));

                return fogOutput;

And here’s the other part of it:

using UnityEngine;

public class Fog : MonoBehaviour {
    public Shader fogShader;
    public Color fogColor;
    [Range(0.0f, 1.0f)]
    public float fogDensity;
    [Range(0.0f, 100.0f)]
    public float fogOffset;
    private Material fogMat;

    void Start() {
        if (fogMat == null) {
            fogMat = new Material(fogShader);
            fogMat.hideFlags = HideFlags.HideAndDontSave;

        Camera cam = GetComponent<Camera>();
        cam.depthTextureMode = cam.depthTextureMode | DepthTextureMode.Depth;

    void OnRenderImage(RenderTexture source, RenderTexture destination) {
        fogMat.SetVector("_FogColor", fogColor);
        fogMat.SetFloat("_FogDensity", fogDensity);
        fogMat.SetFloat("_FogOffset", fogOffset);
        Graphics.Blit(source, destination, fogMat);