- Home /
Question by
DeliriumTremens · May 14, 2015 at 11:59 AM ·
shaderimage effectspost-processing
Turning a found material shader into a post-processing effect?
I am working on a project involving selectively masking one camera overlaid on another based on alpha values. I found a shader that works well for this purpose when applied to a material on a quad placed directly over one camera. By rendering out both a 2nd camera and an 'alpha' camera to RenderTextures, I am able to achieve the effect I want with this shader on the quad.
Here is the shader in question:
Shader "Custom/CustomFadeShader" {
Properties {
_Cutoff ("Cutoff", Range (0,1)) = 0.5
_CutoffRange ("Cutoff Range", Range (0,1)) = 0.1
_MainTex ("Base (RGB)", 2D) = "white" {} // "Light" camera RenderTexture
_AlphaTex ("Mask", 2D) = "white" {} // "Alpha" camera RenderTexture
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
LOD 200
Lighting OFF
CGPROGRAM
#pragma surface surf Unlit alpha noambient novertexlights nodirlightmap nolightmap noforwardadd
half4 LightingUnlit (SurfaceOutput s, half3 dir, half atten) {
fixed4 c;
c.rgb = s.Albedo;
c.a = s.Alpha;
return c;
}
sampler2D _MainTex;
sampler2D _AlphaTex;
half _Cutoff;
half _CutoffRange;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
half d = tex2D (_AlphaTex, IN.uv_MainTex).r;
o.Albedo = c.rgb;
half r = _Cutoff * (1 + _CutoffRange * 2) - _CutoffRange;
o.Alpha = (d - r) * (1 / (_CutoffRange));
}
ENDCG
}
Fallback "Diffuse"
}
What I'm trying to figure out is if there is a better way to implement this effect as a post-processing effect on a camera rather than combining RenderTextures over a quad? I am a total novice when it comes to shaders; any direction about how to translate this material shader would be appreciated!
Comment