Hello ! I'm working on a VR application that calls some async methods and, while awaiting for it, I'd like to have a "loading" effect that overdraws every object in the scene. For example, if I have some cubes and a skybox on the scene, I'd like this "loading" effect to overdraw everything (always draw in front of these cubes and skybox). I was trying by changing the Render Queue number but id didn't work. Do you know if there's a way to do it ? Thanks beforehand
You need to make sure the shader has ZTest off so that it doesn't get culled by the ZBuffer and have it in a late render queue after Transparency queue. Can also set the https://docs.unity3d.com/ScriptReference/Renderer-sortingOrder.html from code to a very high value for extra measure.
Hi Invertex. I'm checking the documentation you provided but I noticed that it refers specifically to sprites. Does "Render Sorting Order" work as well with non sprite objects (3D objects) ?
Yes, there is a render order value that can only be access from code on regular renderers as well. But regardless the important part here is using a shader that doesn't do ZTest. Here's an example: Code (CSharp): Shader "Unlit/RenderOnTop" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Tags { "RenderType"="Transparent" "Queue"="Overlay+50" } LOD 100 Pass { ZTest Off ZWrite Off Blend One OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; }; sampler2D _MainTex; float4 _MainTex_ST; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); return o; } fixed4 frag (v2f i) : SV_Target { return tex2D(_MainTex, i.uv); } ENDCG } } }
I see you quoted it before I added the Blend line, so just a heads up in case, don't want to forget that Blend One OneMinusSrcAlpha line if you want transparency since you mentioned it's an image you're displaying. (And if you're using an actual Text component, that will require a slightly different shader)
Thanks for the feedback again. This is how the shader looks at the end. Is very simple but it achieves the goal I needed : Code (CSharp): Shader "JazzBACH/OverdrawShader"{ Properties{ _Tex("Texture", 2D) = "white" {} } SubShader{ Ztest Always Blend SrcAlpha OneMinusSrcAlpha pass{ CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" struct input{ float4 vertex : POSITION; float4 texcoord : TEXCOORD0; }; struct output{ float4 vertex : SV_POSITION; float4 texcoord : TEXCOORD0; }; uniform sampler2D _Tex; // ------------------------------------------------------OWN METHODS fixed4 _GetTexture(output o){ return tex2D(_Tex, o.texcoord); } // ---------------------------------------------------SHADER METHODS output vert(input i){ output o; o.vertex = UnityObjectToClipPos(i.vertex); o.texcoord = i.texcoord; return o; } fixed4 frag(output o) : SV_TARGET{ //return _GetTexture(o); return _GetTexture(o); } ENDCG } } }