Unity - Hide the Edge Of The Level

Hi,

Currently I am building a level in Unity and I have run into a problem the player (Me) can see well past the edge of the level. I am looking for a way to say place a ton of fog in a circle around the edge of my level (Like this attached image where the fog hides the edge)

But I have no been able to find a guide on how to do this.

Things I have tried so please dont suggest

  • Lowering the view distance on the camera didn’t work just had things popping in and out very ugly
  • Placing objects in the distance still didnt work because the edge of the skybox is still seen

Does anyone know who to replicate the above image or have any other suggestions ??

Thank you

I think you could solve this writing a simple surface shader, look at this page where they got some examples:

You could try writing a shader that only renders your terrain within a certain distance from the camera, that should give you a nice circular edge and then the mesh just needs to be bigger than the range you define. Just as an example, you can refine this to match your skybox in many ways I think like decreasing the alpha over a certain range to let the terrain fade out (you can really do a lot with surface shaders).


EDIT: I think what you see in the image you uploaded is just a circular mesh though


EDIT2: Here is a very basic example so you can comprehend what I mean:

Shader "Custom/Horizon" {
	Properties {
		_MainTex ("Albedo (RGB)", 2D) = "white" {}
		_HorizonRange ("Horizon Range", Range(1,1000)) = 100
	}
	SubShader {
        Tags {"Queue"="Transparent" "RenderType"="Transparent" } // <- this is needed if you want transparency on your mesh
		LOD 200

        Blend SrcAlpha OneMinusSrcAlpha

		CGPROGRAM
		#pragma surface surf Standard fullforwardshadows alpha // <- added "alpha" here for transprency
		#pragma target 3.0

		sampler2D _MainTex;

		struct Input {
			float2 uv_MainTex;
            float3 worldPos; // Unity will fill this for you
		};

		half _HorizonRange;

		void surf (Input IN, inout SurfaceOutputStandard o) {
			float cameraDistance = length(IN.worldPos.xyz - _WorldSpaceCameraPos.xyz);

			if (cameraDistance < _HorizonRange) {
				// within the Horizon Range, render everything normal
				fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
				o.Albedo = c.rgb;
				o.Alpha = c.a;
			} else {
				// Outside of the Horizon Range, don't render the mesh.
				o.Albedo = float3(0, 0, 0);
				o.Alpha = 0;
			}
		}
		ENDCG
	}
	FallBack "Diffuse"
}
  • Go to Create->Shader->SurfaceShader (that will give you a skeleton for your surface shader that allready works)
  • Paste the content I posted above
  • Go to Create->Material
  • Select the Shader Custom/Horizon for the Material
  • Apply the Material to your Mesh

Now the problem is, if your terrain uses a custom shader, yours has to fit the terrain shaders functionality. Anyhow I think this can give you a good starting point to develop something like that, look at the code and try to adapt. :slight_smile: Hope this helps