Shader transparency problem
Hello all,
I have been searching for a some time for solution for my problem. But I am not sure if I am able to describe it correctly for effective searching as I am total shader noobie.
I am trying to implement following (and it may be completely wrong way):
I have plane with cube, which has set Layer A. Then I have second cube, which has set Layer B. And I want to render sort of fog of war, but instead of using black color use render texture of camera, which renders Layer B.
So I have created plane, which is perpendicular to camera and has material made of custom written shader (basically transparent cutoff shader with green mask). It is just working temporary code:
Shader "Fow" {
Properties {
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_MaskTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
//ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
};
sampler2D _MainTex;
sampler2D _MaskTex;
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord);
fixed4 col2 = tex2D(_MaskTex, i.texcoord);
col.a = 1 - col2.g;
return col;
}
ENDCG
}
}
}
This code sort of works, but it produces weird error. The color in the transparent hole is Clearing color of main camera. See the picture for more illustrative description. Please, notice that in the game view, the cube is slightly visible, but really just a bit.
![Problem with shader][1]
My question is - how to achieve to have the transparent part of the plane really transparent? :-) [1]: /storage/temp/63663-shaderproblem.png
Your answer
Follow this Question
Related Questions
Transparency of a specific area 0 Answers
How to correctly use transparent tiled blocks? 0 Answers
A problem with a shader to make a window transparent 0 Answers
Change surface type with LWRP 4 Answers