- Home /
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.
https://roystan.net/articles/grass-shader.html Source: https://github.com/IronWarrior/UnityGrassGeometryShader
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.
@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.
Yep, I did: https://www.youtube.com/watch?v=8_xCX9mGM5c&ab_channel=niuage Look in the description for a link to the shader. Although these days, there are better solutions i think. BruteForce grass shader is pretty good.
Answer by Namey5 · Mar 23, 2020 at 01:55 AM
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" }
//Alternatively
//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.
Thanks :)
Adding the tags "helped": https://i.imgur.com/hd6Hx4G.png No lighting as expected, but I see the grass.
So your advice would be to look at a urp shader with lighting and then update the current shader based on that?
An idea I had was to use this template as a base, and then move over the different pieces of the original shader to it: https://gist.github.com/phi-lira/225cd7c5e8545be602dca4eb5ed111ba Do you think that's a valid approach as well?
I'm a noob when it comes to HLSL and if you could help me for one little thing:
void geo(triangle vertexOutput IN[3], inout TriangleStream<geometryOutput> triStream)
What's vertexOutput
doing here? In the shader, vertexOutput is a function. I dont understand this method declaration, so I'm having trouble moving it over to the new shader template (I'm getting "unrecognized identifier 'vertexOutput'".)
What you're saying about the documentation of shaders under URP is a bit scary. Why do you think they dont write docs? The code's changing too fast and they're lazy about keeping the doc up to date? You think that's gonna change?
Thanks for your help.
I actually found that shader later today - definitely a good place to start as it does exactly what I suggested doing for you. As for the error, 'vertexOutput' isn't a function; it's a struct that is defined in the tessellation include that comes with that grass shader;
The thing that's confusing is that they have also named a vertex function 'VertexOutput' (note the difference in capitalisation). You'll need to include "CustomTessellation.cginc" if you want the struct to be defined.
In regards to the documentation, I don't blame the Unity $$anonymous$$m. SRP is currently very volatile (especially URP) and they change core aspects with almost every release. The problem is that they are simultaneously trying to give devs lower level access to make more complex systems, whilst also trying to abstract all that away so that less knowledgable devs don't even have to think about it. You end up with a mess that is somehow both very complex design and capability, but so simplistic at a surface level that it's difficult to understand from the outside. That said, the Unity docs were never great for rendering - most things didn't (and still don't) have any explanation or examples, making it hard to do more advanced engine-level things.
Thank you both for sharing all this info! I've been looking for a way to do grass like this in URP, did you manage to add unlit colors to the grass in the end?
I'm working on a tri-planar terrain shader using a shader graph and wondered if this grass could somehow be applied as a custom function node to have connected to the grass part on the top projection. https://i.gyazo.com/53168e02644226c498eb9c6bcdb1ac53.png
Your answer
Follow this Question
Related Questions
Edit Offset Values in Unity URP Lit Shader via Script 0 Answers
Universal render pipeline point light shadows? 2 Answers
How to do texture bombing in shader graph 0 Answers
Water Shader in URP? 0 Answers
Hybrid Renderer Visual Bug (FPS Drop?) 0 Answers