- Home /
Custom shader renders back objects only in certain angles
Hello everyone,
I have this custom transparent shader (source: http://wiki.unity3d.com/index.php/AlphaVertexLitZ):
Shader "Custom/NewShader" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"RenderType"="Transparent" "Queue"="Transparent"}
// Render into depth buffer only
Pass {
ColorMask 0
}
// Render normally
Pass {
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Material {
Diffuse [_Color]
Ambient [_Color]
}
Lighting On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
// Fallback to Alpha Vertex Lit
Fallback "Transparent/VertexLit", 2
}
The problem is that the shader renders the back-wall (the wall behind the first wall) only when the camera is looking from certain angles. In other cases it doesn't renders the back wall. See attached image.
Does any one have an idea of how to make the shader render the back-wall all the time? (not depending on the angle)
Thanks for the help.
Sebastián
Answer by Bunny83 · Feb 11, 2013 at 04:41 PM
Well the shader you're using is doing something which doesn't work well with transparent geometry. Transparent objects are depth sorted from back to front so they are rendered correctly. However in some cases an object center is closer to the camera than another but is actually behind the other. With normal transparent shaders that's not a big problem since they are transparent. Writing to the z buffer prevents any drawing behind this area. In your case, due to depth sorting, the wall in front is rendered first because it's pivot is farer aways than the pivot of your object in the background. Since the shader writes to the z-buffer the other object can't be drawn over the wall in front.
There'S almost nothing you can do about that except breaking the objects into smaller parts, however that's no guarantee that it will work in all cases.
Normal transparent shaders don't write to the z buffer, so they don't block objects behind which are drawn later. So either use the normal transparent shader or try to split your geometry into smaller (convex) objects. Concave objects are more likely to produce this issue.
Your answer
Follow this Question
Related Questions
Using Color.Lerp with Lightweight Render Pipeline 1 Answer
How can i get my quad to only render my texture without stretching it? 1 Answer
Transparency shader that also writes to Camera Depth Texture 0 Answers
Semitransparent shader not visible in front of objects 1 Answer
How can I make a transparent ground, that hides other objects beneath it? 1 Answer