- Home /
set gameobject in front of all others and don't have own faces appear in front of each other
Hello,
I am trying to create a shader that when I attach it to the object, the object will always appear in front of any other object. I copied the standard shader that unity has and modified it a bit so that ZWrite
and Cull
are OFF and ZTest
is set to Always. You can view the changes below and also the entire shader file here which is the entire standard shader Unity uses, plus my changes:
Shader "CustomShader"
{
Properties{...}
....
SubShader
{
Tags{....}
Cull Off
ZTest Always
ZWrite Off
}
....
SubShader
{
Tags{....}
Cull Off
ZTest Always
ZWrite Off
}
It works for the most part, however I am getting a weird issue where the faces are all appearing in front of each other. Here is an example where the camera is placed inside a sphere which has a texture attached to it. There is a gameobject in the scene that is a house which I've attached my shader to. The house appears to be in front of sphere all the time, however you notice that the faces of the houses are in front of each other. You can have a view of the issue through the link provided below.
I found a post on the answers forum here that has an answer that says to add the code below to avoid this issue:
SubShader {
Cull Off
Pass{
ZTest Greater
}
Pass{
ZTest Less
}
Pass{
ZTest Always
}
However adding this still did not resolve this issue. Any help would be greatly appreciated, and if there is anything else I can better explain please let me know!
Thanks.
Answer by · Aug 09, 2017 at 09:39 PM
Changing the render queue to a higher value in the material is not an option?
If not, this is a simple shader that i made in amplify that does what you want
Shader "New AmplifyShader"
{
Properties
{
[HideInInspector] __dirty( "", Int ) = 1
_Color("Color", Color) = (0,0,0,0)
_Smoothness("Smoothness", Range( 0 , 1)) = 0
_$$anonymous$$etalic("$$anonymous$$etalic", Range( 0 , 1)) = 0
}
SubShader
{
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" }
Cull Back
ZTest Always
CGPROGRA$$anonymous$$
#pragma target 3.0
#pragma surface surf Standard keepalpha addshadow fullforwardshadows
struct Input
{
fixed filler;
};
uniform float4 _Color;
uniform float _$$anonymous$$etalic;
uniform float _Smoothness;
void surf( Input i , inout SurfaceOutputStandard o )
{
o.Albedo = _Color.rgb;
o.$$anonymous$$etallic = _$$anonymous$$etalic;
o.Smoothness = _Smoothness;
o.Alpha = 1;
}
ENDCG
}
Fallback "Diffuse"
CustomEditor "ASE$$anonymous$$aterialInspector"
}
I tried using the shader you provided, and it looks like it occluded some things successfully, but it looks like you can still see some objects.
http://imgur.com/a/1$$anonymous$$R$$anonymous$$e
I just copied and pasted the shader into a new one and set that as the shader for the object. Is that all I would need to do?
Your answer
Follow this Question
Related Questions
Pixelart camera shader 2 Answers
Particles visible through everything! :( 1 Answer
Is particular object visible 1 Answer
How would I fix this DrawMeshInstancedIndirect and Translucent object problem? 0 Answers
Image effect shader not running 1 Answer