x


Alpha blending with more than one pass

I'm trying to create a shader which renders different parts of an object with different alpha depending on object coordinates. The following shader works, as long as I have only one pass (result not very good) but fails (no blending with background) when I have 2 passes:

This works:

Shader "Custom/Bugtest" {
    Properties {
    }
    SubShader {
       Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue" = "Transparent" }
       LOD 200
       ZWrite Off
       Blend SrcAlpha OneMinusSrcAlpha      

       Cull off

       CGPROGRAM
       #pragma surface surf Lambert
       #pragma target 3.0
       #include "UnityCG.cginc"

       struct Input {
         float3 worldPos;
       };
       void surf (Input IN,inout SurfaceOutput o) {
         float4 objpos = mul( _World2Object, float4(IN.worldPos,1.0) );
         o.Albedo=float3(1,0.5,0.5);
         if (objpos.x>0)
             o.Alpha=0.25;
           else
             o.Alpha=1.0;
       }
       ENDCG
    } 
    FallBack "Transparent/VertexLit"
}

But this not:

Shader "Custom/Bugtest" {
    Properties {
    }
    SubShader {
       Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue" = "Transparent" }
       LOD 200
       ZWrite Off
       Blend SrcAlpha OneMinusSrcAlpha      

       Pass {
         Cull front   
       }
       Pass {
         Cull back
       }

       CGPROGRAM
       #pragma surface surf Lambert
       #pragma target 3.0
       #include "UnityCG.cginc"

       struct Input {
         float3 worldPos;
       };
       void surf (Input IN,inout SurfaceOutput o) {
         float4 objpos = mul( _World2Object, float4(IN.worldPos,1.0) );
         o.Albedo=float3(1,0.5,0.5);
         if (objpos.x>0)
             o.Alpha=0.25;
           else
             o.Alpha=1.0;
       }
       ENDCG
    } 
    FallBack "Transparent/VertexLit"
}
more ▼

asked Sep 07 '12 at 01:57 PM

bluedog gravatar image

bluedog
1 1 1

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1668
x330
x95
x38

asked: Sep 07 '12 at 01:57 PM

Seen: 485 times

Last Updated: Sep 07 '12 at 01:57 PM