2

I'm newbie in Shader Programing. I created a simple shader with a radial gradient, and when they intersect, I want increase transpency. I would like something like this effect: Image transperent two objects

SubShader {
    Tags { "Queue" = "Geometry+10" }
    Pass{
        ColorMask rgb   
        //ZWrite On
        Blend Zero OneMinusSrcAlpha 
        CGPROGRAM 
        #pragma vertex vert
        #pragma fragment frag
        float4 _Color;
        float4 _ColorDark;
        float _Radius;
        //float _Offset;
        float _Strength;
        struct vertexInput {
            float4 vertex : POSITION;
        };
        struct vertexOutput {
            float4 pos : SV_POSITION;
            float4 posInObjectCoords : TEXCOORD0;
        };
        vertexOutput vert(vertexInput input) 
        {
            vertexOutput output;
            output.pos =  mul(UNITY_MATRIX_MVP, input.vertex);
            output.posInObjectCoords = input.vertex; 
            return output;
        }
        float4 frag( vertexOutput  input) : COLOR 
        {
            float z = input.posInObjectCoords.z * input.posInObjectCoords.z ;
            float x = input.posInObjectCoords.x * input.posInObjectCoords.x ;
            float r = _Radius * _Radius;
            float alf = (x+z) / r;
            return float4 (_ColorDark.r , _ColorDark.g ,_ColorDark.b, alf * _Strength);
        }
        ENDCG
    }
}

Yeah, maybe code is not so beauty, but for tests it's useful. Thank you for any answer!

nipercop
  • 357
  • 1
  • 11

2 Answers2

1

Just use additive blending instead alpha blending.

Blend SrcAlpha One or Blend One One

Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
0

Try this

...
Tags { "Queue" = "Transparent" }
Pass{
    ColorMask rgb   
    //ZWrite On
    Blend SrcAlpha OneMinusSrcAlpha
    ... 
Stas BZ
  • 1,184
  • 1
  • 17
  • 36
  • Thank you, but it is work only with solid color. And not matter Queue is transparent or Geometry, shows one result. For me, must be Geometry, because I will carve on another subject these circles. (colormask) – nipercop May 20 '15 at 07:41