Question by
lloydv · Dec 12, 2015 at 11:36 PM ·
shadertexturetransparencyshader programmingunlit transparent
Unlit semitransparent texture shader problem
I'm trying to make a 3d object semi-transparent, which would seem like a relatively simple task, but since I'm a total newbie to shaders I'm having a terrible time of it.
Here's what I have: When the alpha slider is dragged down, the object becomes transparent, but nothing is drawn behind it.
From what I've read, it seems like turning ZWrite off should be the solution, but when I do that the model disappears entirely, even at full alpha.
Here's my shader, which I've Frankenstein-ed together from various tutorials, google searches, etc.
Shader "Custom/Semitransparent"
{
Properties {
_MainTex ("Texture", 2D) = "white" {}
_Alpha ("Alpha", Range(0.0,1.0)) = 1.0
}
SubShader {
Pass {
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
//ZWrite Off //model disappears when this line is uncommented
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform float _Alpha;
struct vertexInput {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct vertexOutput {
float4 pos : SV_POSITION;
float4 tex : TEXCOORD0;
};
vertexOutput vert(vertexInput v){
vertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.tex = v.texcoord;
return o;
}
float4 frag(vertexOutput i) : COLOR {
float4 tex = tex2D(_MainTex, i.tex.xy * _MainTex_ST.xy + _MainTex_ST.zw);
//return float4(0.0, 1.0, 0.0, _Alpha); //for testing
return float4(tex.xyz, _Alpha);
}
ENDCG
}
}
//Fallback "Unlit"
}
semitransparent-problem.jpg
(79.2 kB)
Comment