What are the rules for manually writing shaders that render in the new Render Pipe-lines.
The update shaders option just replaces them all… so all existing custom functionality is lost…
but…they still compile ok, they just render magenta? so are they broken or not ?
How do we manually write a custom shader that renders properly in URP ?
What are the requirements/spec please? I cant find anything in the official documentation.
thanks
1 Answer
1Here is a good template you can use as a basis for writing shaders for URP;
You’ll need a few things to get a shader to draw in the new render pipelines. The main thing to note is that the new pipelines now work exclusively with single pass shaders, hence why the old multi-pass lit shaders are disabled.
To start, you’ll need to specify what RP you are working with in the subshader tags;
Tags {"RenderType"="Opaque" "RenderPipeline"="UniversalRenderPipeline" "IgnoreProjector"="True"}
You will also need to specify what each pass does through a LightMode tag;
//For the main URP lit pass
Tags { "LightMode"="UniversalForward" }
From there, the only main difference aside from lighting is that shaders are now written in HLSL instead of CG. The syntax is the same, but it won’t have the old includes that CGPROGRAM used to use automatically, meaning you may have to rewrite some functions yourself (‘LinearEyeDepth’, etc). For the above reasons, surface shaders are also no longer compatible.
awesome! thanks, this is perfect, it should be in the unity docs, in the same section as upgrading shaders.
– JonPQ
also, can you see the performance of the shader that shaderGraph is building ? It would be nice if there was some kind of stats window for the shader.... showing number of texture reads, interpolators, and instructions per pixel and per vertex. Does that exist ?
– JonPQ