- Home /
Problem with semi-transparent shader in built-in render pipeline
So my goal is to have a shader that is transparent to all opaque objects while at the same time blocking all other transparencies that are behind it. Now, I'm not really a shader coder but I managed to get a solution...the only problem being that the shader is somehow working in the editor view but not in the game view. So it seems that I have reached a roadblock with my very limited knowledge about shaders and hope that someone here knows what is going on and can maybe point me to the right direction.
This is what the shader does in the editor view, so basically exactly what I need:
And this is what happens in the game view:
As the title says, it's a project made with the built-in render pipeline, using deferred rendering and Unity version 2020.3.4f1.
This is the shader I used to create the examples shown in the screenshots above:
Shader "SemiTransparentExample"
{
Properties
{
[NoScaleOffset] _MainTex ("Texture Image", 2D) = "white" {}
_ColorTint ("Tint", Color) = (1.0, 0.6, 0.6, 1.0)
_Alpha("Alpha", Range(0,1)) = 0.5
}
SubShader
{
Tags
{
"RenderType" = "Opaque"
"IgnoreProjector" = "True"
}
LOD 200
CGINCLUDE
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
fixed4 _ColorTint;
float _Alpha;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 c = tex2D(_MainTex, i.uv);
c *= _ColorTint;
c.a = _Alpha;
return c;
}
ENDCG
Pass
{
ZWrite On
Cull Front
ColorMask 0
}
Pass
{
ZWrite Off
Cull Back
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
ENDCG
}
}
FallBack "Diffuse"
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613055442im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to acheive wireframe effect with dots? 0 Answers
Cannot use unity_ObjectToWorld on the GPU Adreno 505? 0 Answers
Does Unity support atomic counter? if does, is there example? 0 Answers
custom shader error. copy of "Nature/Tree Soft Occlusion Leaves" 0 Answers
How do I do custom camera render between opaque and transparent objects? 0 Answers