- Home /
The question is answered, right answer was accepted
Multiple transparency shaders yields a massive Unity glitch.
Well the title just about says it. I have a material for the roof and another for the walls. When i switch it from Transparent/Diffuse to Diffuse, the issue goes away but i need to be able to edit the transparency through a script so the Transparency diffuse is necessary.
Is there any way to fix this?
Viewing from underneath the fixes the roof. The issue appears to only happen when 2 transparent/diffuses overlap.
It's hard to see from your pictures what exactly the problem is, but the fact that you said "viewing from underneath fixes the problem" makes me think this might be related to the normals of your surfaces - is the roof a plane?
may be you are using single plane for walls and roof right
No it has multiple faces. I recalculated the normals in blender, and if I change the shader to a regular diffuse the problem goes away. The pictures are trying to show how the object seems to dissapear only when you view one over the other.
Hmm thats strange cause the shader are independent of each other they only consider inco$$anonymous$$g light and texture
Could you upload the 3d model once so that we could have a closer lOok at the problem
and you said two diffuse layers overlap right does the smae happen with other shaders as well
and which render mode are you running
Answer by tanoshimi · Jul 01, 2014 at 06:02 PM
The built-in transparent shaders do not write to the depth buffer. Since the transparent queue is not sorted, the draw order of overlapping transparent objects is therefore somewhat arbitrary, as any objects sent to the GPU later will be rendered over the top of previous objects, even if they actually lie behind them.
If you really need to use transparent shaders (it's a bit unclear why) and want to maintain depth, you can add ZWrite On
to the shader - although note that this will cause your apparently "transparent" objects to occlude objects that lie behind them (which is why it's generally turned off).
Try creating a new shader as follows and assigning it to the material on your objects:
Shader "Transparent/Diffuse ZWrite" {
Properties {
_Color ("Main Colour", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
// Initial pass renders to depth buffer only
Pass {
ZWrite On
ColorMask 0
}
// Now use regular forward rendering passes from Transparent/Diffuse
UsePass "Transparent/Diffuse/FORWARD"
}
Fallback "Transparent/VertexLit"
}
Ill test this out, because if it works it is far better than what I have now! Ill edit when im done
Follow this Question
Related Questions
Semitransparent shader issue. How can I fix it? 0 Answers
Shader - Transparent Shows Through 1 Answer
Blender to Unity glitch? 3 Answers
Transparent Diffuse issues 1 Answer
A node in a childnode? 1 Answer