Custom "Transparent Cutout" shader not showing on Camera.Render()?

My transparent cutout shader for ‘home doorsteps’ is showing just fine on the MainCamera…
8245464--1078656--looks_good.png

But when I call Camera.Render() on a secondary camera for generating item screenshots, it does not show up…
8245464--1078659--invisible.png

Shader code:

Shader "Custom/CutoutZAlways"
{
    Properties{
        _Color("Main Color", Color) = (1,1,1,1)
        _MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
        _Cutoff("Alpha cutoff", Range(0,1)) = 0.5
    }

    SubShader{
        Tags {"IgnoreProjector" = "True" "RenderType" = "TransparentCutout"}
        LOD 200
        ZTest Always

        CGPROGRAM
        #pragma surface surf Lambert alphatest:_Cutoff

        sampler2D _MainTex;
        fixed4 _Color;

        struct Input {
            float2 uv_MainTex;
        };

        void surf(Input IN, inout SurfaceOutput o) {
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Alpha = c.a;
        }
        ENDCG
    }
    Fallback "Diffuse"
}

Screenshot code:

item_screenshots_cam.backgroundColor = new Color(0, 0, 0, 0);

RenderTexture rt = new RenderTexture(128, 128, 32);
item_screenshots_cam.targetTexture = rt;
Texture2D screenShot = new Texture2D(128, 128, TextureFormat.ARGB32, false);
item_screenshots_cam.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, 128, 128), 0, 0);
//screenShot.Apply();
item_screenshots_cam.targetTexture = null;
RenderTexture.active = null; // JC: added to avoid errors
Destroy(rt);

An update: looks like it’s borrowing the ‘alpha level’ from the secondary Camera’s background fill, leading to partially/totally transparent ‘doorsteps’ depending on how transparent the background is. Is this an alpha blending / alpha channel issue? Hmmm… how to fix

When the Camera is set to ‘deferred’ rendering, it seems to work. Just not with ‘forward’ rendering…
8253312--1080195--deferred.png

[EDIT]
I could never figure this out. I ended up having to re-modeling all my ‘transparent’ objects as meshes. Quite the hassle - took several weeks to remodel them all. Sigh

1 Like