Shader with adjustable render queue

Hi,

I’m trying to build a shader that has a text field for a custom render queue tag. I’d like this to be a number I can specify so that I don’t have to create a new copy of my shader every time I want to adjust the queue.

I’ve got the text field working, and I know where the number needs to go. I’m just not sure how to tell the shader to use the number, and now I’m wondering if this is a limitation of this in Unity.

I guess my question is, can I use a variable in my shader to define the render queue, and if so, how would I get that to work?

Shader "Render Queue" {
	Properties {
		_Color ("Color Tint", Color) = (1,1,1,1)	
		_MainTex ("Base (RGB) Alpha (A)", 2D) = "white"
		_Depth ("Render Depth", Float) = 0  //This is what I'd like to add
	}

	Category {
		Lighting Off
		ZWrite Off
		Cull back
		Blend SrcAlpha OneMinusSrcAlpha

		SubShader {
			
			Tags {"Queue" = [_Depth]}  //This line doesn't work, but it gives an idea of what I'm trying to do
			
			Pass {
				SetTexture [_MainTex] {
					ConstantColor [_Color]
					Combine Texture * constant
				}
			}
		}
	}
}

Just modify the material’s “renderQueue” field instead, it directly overrides the one defined in the shader.

However, my guess is you want to store this with the asset, and not apply it at runtime via script? In that case it should be possible to write a short Editor script for that.
Take a look at StandardShaderGUI.cs which is part of the builtin-shader download, as a starting point.

Be warned, though, that this will permanently override that material’s renderQueue; even switching shaders afterwards will no longer modify the actual queue value! To restore the default behaviour, you need to reset the material’s renderQueue to -1 using your Editor script.