How to do fog planes like BioShock Infinite

I noticed in Bioshock Infinite they have these fog effects that are just flat planes (not billboards), with a scrolling transparent fog texture on them. They alpha fades to transparency as you get closer to them, and it looks like the alpha also fades out on either end of the plane. So you don’t have a hard edge that the texture is scrolling into/out of.

The scrolling and alpha fading as you get closer don’t seem too hard.
But I am wondering how to fade the alpha at either end of the rectangular plane.

Any ideas?

You could write a shader that takes an additional alpha mask texture that isn’t being scrolled and “guides” the edge fadeout.
Basically a texture like this:

alt text

along with something like:


This is the finalized shader code. It also handles the fading and scrolling for you:

Shader "Custom/BInfiniteFog" {
	Properties { 
		_MainTex ("Base (RGB)", 2D) = "white" {}
		_CutoffTex ("Alpha Guide", 2D) = "white" {}
		_ScrollDir("Scroll Direction",Vector)=(1,0,0,0.1)
		_FadeMul("Fading Multiplier",Range(0,3))=1
	SubShader {
		Tags { "RenderType"="Transparent" "RenderQueue"="Transparent"}
		LOD 200
	    #pragma surface surf WrapLambert alpha
	    half4 LightingWrapLambert (SurfaceOutput s, half3 lightDir, half atten) {
           //half NdotL = dot (s.Normal, lightDir);
           half4 c;
           c.rgb = s.Albedo * _LightColor0.rgb * (atten * 2);
           c.a = s.Alpha;
           return c;

		sampler2D _MainTex;
		sampler2D _CutoffTex;
		fixed4 _ScrollDir;
		fixed4 _MainColour;
		half _FadeMul;
		struct Input {
			float2 uv_MainTex;
			float2 uv_CutoffTex;
			float4 screenPos;

		void surf (Input IN, inout SurfaceOutput o) {
			half4 c = tex2D (_MainTex, IN.uv_MainTex+_ScrollDir.xy*_ScrollDir.w*_Time.y)*_MainColour;
			o.Emission = c.rgb;
	FallBack "Diffuse"

As for the shader properties:

alt text

Base is your fog’s texture. Main Colour is the tint you wish to apply to the fog texture. You can also adjust the alpha to make it more transparent. The alpha Guide is your mask; the darker it is, the less visible the fog is going to be. The shader uses the ScrollDirection x, y and w components. X and Y are a 2D vector of the direction of the scrolling and W is a magnitude multiplier. Having either X and Y both be zero, or W be zero would yield no scrolling. As for the fading multiplier, the lower it is, the more distance the object needs to start fading. If you want your fog to also be affected by lighting, change o.Emission to o.Albedo at line 29.

The effect looks like this, with the fading multiplier set to a rather low value.

alt text