- Home /
Standard shader - fade mode renders texture in wrong order
I have a nice looking tree cartoonish tree.
The camera is a 3. person topdown view (think diablo-ish). The character should be able to walk under trees, and the trees should become transparent.
My tree looks like this (Opaque) Where the black parts should be transparent. When I change the mode to fade it looks like this
The tree is one big mesh, but the texture order is wrong, it draws the texture in the back, ontop of the texture in the front.
How can I fix this?
I have been looking into setting the _ZWrite to 1 and tried this shader
Which gives me this result: http://i.imgur.com/pZletcf.png which is not acceptable either.
Answer by Mr-JWolf809 · Feb 18, 2016 at 12:41 PM
I found a possible solution to the problems.
Giving this result!
It is not perfect, but it works well enough for the fade effect.
The shader is based on the Unity Shader: Legacy Shaders/Transparent/Cutout/VertexLit which I have modified to fit my needs. I have removed a lot effects which I didn't need (Shininess, Spec Color, Emissive Color) and made it possible to make the tree transparent even if the texture is baked.
Shader "Custom/Transparent and Cutout Shader"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 200
// Non-lightmapped
Pass
{
Tags { "LightMode" = "Vertex" }
Alphatest Greater [_Cutoff]
AlphaToMask True
ColorMask RGB
Material {
Diffuse [_Color]
Ambient [_Color]
}
Lighting On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
// Lightmapped, encoded as dLDR
Pass {
Tags { "LightMode" = "VertexLM" }
Alphatest Greater [_Cutoff]
AlphaToMask True
ColorMask RGB
Material {
Diffuse [_Color]
Ambient [_Color]
}
Lighting On
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture * texture alpha DOUBLE
}
SetTexture [_MainTex] {
combine texture * previous DOUBLE, texture * primary
}
}
// Lightmapped, encoded as RGBM
Pass
{
Tags { "LightMode" = "VertexLMRGBM" }
Alphatest Greater [_Cutoff]
AlphaToMask True
ColorMask RGB
Material {
Diffuse [_Color]
Ambient [_Color]
}
Lighting On
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture * texture alpha DOUBLE
}
SetTexture [_MainTex] {
combine texture * previous DOUBLE, texture * primary
}
}
// Pass to render object as a shadow caster
Pass
{
Name "Caster"
Tags { "LightMode" = "ShadowCaster" }
}
}
}
The original problem can't be fixed, even AAA games have this problem. You could use the standard shader but set it's rendering mode to cutout ins$$anonymous$$d of transparent or fade. You could also make the inner and outer meshes seperate gameObjects which would also eli$$anonymous$$ate the error since they are both convex.
The problem is I need to make it fade. The other solution you talk about seems more likely, that I make it different gameobjects.
$$anonymous$$r-JWolf809
Is there a way to become this shader into just transparent?
Your answer
Follow this Question
Related Questions
Transparency / depth problem 0 Answers
Make transparency ignore meshes inside? 1 Answer
[ problem ] transparent shader !!! 1 Answer
make object to appear from bottom up 2 Answers
shader Transparency 1 Answer