Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by niuage · Mar 22, 2020 at 02:01 PM · shaderrendergrasspipelineuniversal

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:

https://i.imgur.com/OULBjv8.png

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.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ifmname · Sep 13, 2021 at 07:23 AM 0
Share

@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.

avatar image niuage Ifmname · Sep 13, 2021 at 09:57 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
7
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image niuage · Mar 23, 2020 at 11:39 AM 1
Share

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.

avatar image Namey5 niuage · Mar 23, 2020 at 12:36 PM 0
Share

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;

https://github.com/IronWarrior/UnityGrassGeometryShader/blob/master/Assets/Shaders/CustomTessellation.cginc

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.

avatar image UnityUric niuage · Apr 29, 2021 at 01:42 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

196 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Universal render pipeline point light shadows? 2 Answers

How to do texture bombing in shader graph 0 Answers

Edit Offset Values in Unity URP Lit Shader via Script 0 Answers

NullReference : UniversalRenderPipelineCameraEditor.cs:207 2 Answers

How to use this tessellation cginc with URP? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges