Forward and Deferred passes in one shader?

I’m trying to write a shader that will utilise UsePass to run two passes, one Deferred and the other Forward. So far this does not seem to be working, only the deferred pass will display.

Eg.

SubShader {
	UsePass "Transparent/VertColour/Bumped SpecMap/FORWARD"
	UsePass "Transparent/Cutout/VertColour/Diffuse/PREPASS"
}

Results in the deferred (PREPASS) pass displaying, but not the forward. The result is the same if the UsePass order is swapped.

SubShader {
	UsePass "Transparent/VertColour/Bumped SpecMap/FORWARD"
	//UsePass "Transparent/Cutout/VertColour/Diffuse/PREPASS"
}

This results in the forward pass displaying, so it’s not that the forward shader code has an error.

Is there a way to get this working? Is it possible to have one material/shader that runs two passes, one forward and one deferred. I basically need to render the object twice so that the deferred pass can add depth information to fix a graphical error with the layered transparent objects in my environment.

AFAIK there’s no way to manually setup passes for surface shaders that interact with lighting. From the manual:

Manual Page on Surface Shaders: Unity - Manual: Writing Surface Shaders

Surface Shaders are merely a way to generate the actual passes for all versions of the shader (deferred, forward, lightmapped…).

put#pragma debugat the beginning of you CG code in any surface shader you have.
Now click on your shader file and in the inspector click on ‘Open compiled shader’.

In there you can see all the passes that have been generated for this particular surface shader.
The commented code is the one you’ll want to copy/paste.
If you copy/paste all these passes into a new shader, you don’t have a surface shader anymore but it’ll look the same as the original surface shader.

From there, you can fool around with Use Pass and whatnot like with any classic shader.

Nice tip Taoa, thanks.