- Home /
Unlit Transparent Shader causing strange issues
Here's a screenshot of my situation:
On the left, the transparent glass causes the person inside to disappear. I'm using this shader I cobbled together from a couple others I found:
Shader "Unlit/UnlitTintTransparent" {
Properties {
_Color ("Main Color (A=Opacity)", Color) = (1,1,1,1)
_AddColor("Color Tint Add", Color) = (0,0,0,0)
_MainTex ("Base (A=Opacity)", 2D) = ""
}
Category {
Tags {"Queue"="Transparent" "IgnoreProjector"="True"}
//ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
SubShader {Pass {
GLSLPROGRAM
varying mediump vec2 uv;
#ifdef VERTEX
uniform mediump vec4 _MainTex_ST;
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
}
#endif
#ifdef FRAGMENT
uniform lowp sampler2D _MainTex;
uniform lowp vec4 _Color;
void main() {
gl_FragColor = texture2D(_MainTex, uv) * _Color;
}
#endif
ENDGLSL
}}
SubShader
{
Pass
{
SetTexture [_MainTex]
{
ConstantColor [_AddColor]
Combine Texture + constant
}
SetTexture[_MainTex]
{
Combine texture * constant ConstantColor[_Color]
}
}
}
}
}
I don't really know anything about writing shaders :/, so I'm kinda desperate
Answer by _Gkxd · Apr 12, 2015 at 04:55 AM
Here is the Unity Unlit-Alpha shader, modified to multiply-blend a color with the texture. You can set a transparent color for transparency. Lines marked with comments at the end are lines that I added/modified.
Shader "Unlit/Transparent (Multiply Colorable)" {
Properties {
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1) // Lets you set a color in addition to the texture
}
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)
};
fixed4 _Color; // This is the color that you set
sampler2D _MainTex;
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);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord) * _Color; // Just multiply the color with the texture
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}
Your answer
Follow this Question
Related Questions
Making a shader for an inside out sphere unlit? 3 Answers
Transparent shader that doesnt render in front of skybox but does in other 0 Answers
How To Replicate the Untitled Goose Game Art Style? 0 Answers
How to use unlit texture on UI panel with scripting 1 Answer
unity renders all my points in white 0 Answers