I am trying to create an Uber-Fog post-processing effect. I can’t get the fog’s 2D texture to display in the shader yet my RECT’s (main, depth texture, blur) are perfectly fine.
Am I missing something??
Shader "UberFogComposite"
{
Properties
{
_MainTex ("Orig (RGB)", RECT) = "white" {}
_BlurTex ("Blur (RGB)", RECT) = "white" {}
_DepthTex ("Depth (RGB)", RECT) = "white" {}
_FogTex ("Fog (RGBA)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
Lighting Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _FogTex;
uniform samplerRECT _MainTex;
uniform samplerRECT _BlurTex;
uniform samplerRECT _DepthTex;
struct vIn
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct vOut
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float2 fogUv : TEXCOORD1;
};
vOut vert( vIn v )
{
vOut o;
o.pos = mul (glstate.matrix.mvp, v.vertex);
o.uv = MultiplyUV( glstate.matrix.texture[0], v.texcoord );
o.fogUv = TRANSFORM_UV(0);
//o.fogUv.x += _Time[3];
return o;
}
half4 frag (vOut i) : COLOR
{
half4 original = texRECT(_MainTex, i.uv);
half4 blur = texRECT(_BlurTex, i.uv);
half4 depth = texRECT(_DepthTex, i.uv);
half4 fog = tex2D(_FogTex, i.fogUv);
depth = depth * 2.0;
depth = clamp(depth, 0, 1);
return fog;
//return lerp(original, blur, depth);
}
ENDCG
}
}
Fallback off
}
Bits from the C# side
TOP of CLASS : public Texture2D fogTexture;
>>> Texture is set in inspector <<<
OnRenderImage : compositeMaterial.SetTexture ("_FogTex", fogTexture);