- Home /
Manual shaders in URP/HDRP
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
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 ?
Answer by Namey5 · May 19, 2020 at 01:55 AM
Here is a good template you can use as a basis for writing shaders for URP;
https://gist.github.com/phi-lira/225cd7c5e8545be602dca4eb5ed111ba
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.
do you know of a way to get performance stats of shaderGraph shaders? e.g. number of vert and frag instructions used, number of texture reads, etc... ?
Your answer
Follow this Question
Related Questions
[Deferred Decals] Add simple specular channel to deffered decals 0 Answers
Problems with Depth Normals and variable CullMode 0 Answers
Rendering volumetric objects and maintaining correct depth 1 Answer
Converting c# function to shader. 0 Answers
Scene Color Node in Shader Graph not working with Unity's 2D Renderer and URP 5 Answers