How to adapt this shader to URP?

I’d like pointers to help me understand what I would need to learn and do to make this shader work with URP.

Source: GitHub - IronWarrior/UnityGrassGeometryShader: Source code for Grass Shader tutorial for Unity. Generates blades with a geometry shader, tessellates input mesh to control density.

  • What are the main differences between shaders written for the default render pipeline and URP. Are they completely different?

  • Am I correct to say that I cannot create geometry shaders with the shader graph?

I tried the shader with the default render pipeline, it works nicely. With URP, I get this:

You can tell it’s doing something, as the shadow is actually the shadow of the grass, but the grass itself doesn’t render.

ps: if anyone managed to adapt it to URP, pretty sure this would be very popular, as it’s one of the best and simplest shader I found.

Nothing has necessarily changed about the shaders themselves (Unity has switched focus from CG to HLSL, although the syntax and functionality is basically identical), but shaders made for the built-in pipeline are automatically disabled by the newer render pipelines. This is because the internal lighting process is completely different, and as such shaders themselves need to handle lighting differently. The main thing to note is that whilst the built-in pipeline uses separate shader passes for every light that touches an object, the URP does all lighting and shading in a single pass using arrays. As such, different variables are used to hold light data, so if the old shaders were supported they wouldn’t receive any lighting. On top of that, because most of the shading libraries have been rewritten, a lot of conventions (particularly in regards to naming) Unity used to use have changed.

It’s definitely possible to write custom shaders for the URP, but it takes a lot of patience and will to learn how the new systems work as there isn’t any documentation so far. I would suggest de-abstracting the main Lit shader by going through its include files, mainly “Lighting.hlsl” and “LitForwardPass.hlsl”. If you just want a basic shader to compile and not worry about lighting, you can add the subshader tag;

Tags { "RenderPipeline" = "UniversalPipeline" }

as well as the pass tag;

Tags { "LightMode" = "UniversalForward" }
//Tags { "LightMode" = "SRPDefaultUnlit" }

You need these because SRPs render objects on a per-pass basis, and as such they only support passes that have specific tags. As far as geometry shaders and shader graph go, I doubt that Unity will ever support them considering surface shaders still don’t.

@niuage Hey! Did you manage to convert this shader? Can you share? I also ran into problems yesterday while trying to convert this shader.,@niuage Hey! Did you manage to convert this shader? Can you share it? I also ran into problems yesterday while trying to convert this shader to urp.