Update for Shader Graph version 10.x (and URP version 10.x) - from Unity 2020.2+ 1. You no longer right-clicking on the master node to view the source. You instead select the shader graph, and inside its inspector hit the button "View Generated Shader" 2. If you take a code shader from SG 8.x, it will not run in SG 10.x. But, if you follow all the steps in this video again, it will work. There are just some differences in the parts of the generated file we don't touch that will need to be updated by URP itself.
Great tutorial, was hoping to get the file for this custom shader to do a diff with a "blank" shader to see where the code goes as it's real easy to misplace the code insertions, a problem exacerbated by the poor support for HLSL in any given IDE inc. Rider.
Awesome! also(if im not mistaken) you can just feed vertices to triangle strip and it will produce triangle for each new vertex after 3rd, hance triangle strip
This Random But Related Quote of the Week comes from Schoolhouse Rocks: _Every triangle has three corners_ _Every triangle has three sides_ _No more, no less, you don't have to guess_ _When it's three, you can see_ _Its a magic number_
I'm trying to make geometry shader that shows quads when editing for a 3d modeling software I'm developing. I tried multiple shaders from github but they revert to tris when editing mesh.
Awesome stuff! If I wanted to do a dissolve effect for a low poly game where the object is "turned inside out" by gradually rotating every single triangle 180 degrees around some vector orthogonal to the (original) normal, would a geometry shader be the way to do that? Apart from the normals, what would I need to change in the vertex outputs? The world space coordinates?
I have been using this for grass in hdrp but with latest versions it has stopped working and it may have to do with how packed varyings are different in code shader now. The first 2 passes seem to require different geomdata and geom than the rest but I can't quite figure it out.
Hey! As for specific things I want to do with shaders, I would like to know if its possible to do a voxel model with geometry shaders, or for general shaders, I would like to pass in bone transforms so I can calculate that in the shader. Atm I'm doing all this on the CPU. Particularly the bone calculations and mesh updating every frame is too heavy! (As unity ECS did not have animations a year ago so I implemented my own)
Voxels & Geometry - It can be done, but I'm not sure about the efficiency. My main concern would be the cost of feeding all that data in. hmm. I don't have a good answer here. Bones - this should be a lot easier with some caveats... maneuvering the verts is something a vertex shader should be good at, but then you have to deal with normals. I don't have a video yet (soon?), but I do have a written post on re-calculating normals inside a shader graph gamedevbill.com/shader-graph-normal-calculation/. Or you can use a geometry shader as described in this video to recalculate them. The other caveat is that data transfer. It can be costly to transfer TONS of extra data into a shader each frame, so that's just something to keep in mind. All in all, there's a good chance that this will have better performance in a shader than in C#, but it's not an obvious winner (to me). It could go either way depending on implementation details.
@@GameDevBill Ahh I recall the cost can be pretty high for thousands of vertexes being uploaded per frame so for voxels itll be pretty high too! But If i restricted it to just characters I think.. least i could make a cool boss fight haha Hmm I might try to write a shader then for bone animations! It's just a transform matrix multiplied by original vertex, while I reupload the bone transforms every frame to the shader! :) Thank you again looking forward to more of your videos!
fur in VR! that would be awesome. I'll add it to my investigation list, but generally to do fur on mobile VR you'll want something super stylized, so it can be non-realistic and thus cheaper to render. If I can come up with something I'll make a vid on it!
thanks a lot for this tutorial, its so hard to find doc or examples on to customize UDR or HDRPm in my case i would like to see this on HDRP also how can we use Structured buffers from compute shaders to affect geometry or even just particles, the tricck of generating the shader code is really a game changing, always felt so limited with HDPR because i cant customize anything . Anyway would love to see more stuff like this
i do the same work in geofromgraph shader,but it unwork and show tips(Shader warning in 'GeoFromGraph': Program uses geometry shaders, treating as if '#pragma require geometry' was present at line 72),is it the problem about verson(2019.4.1f1)?
I'm not sure I understand the issue. You can add details here, or if it's easier to use an actual forum, reply to this thread on the Unity forum here: forum.unity.com/threads/gamedevbill-tutorial-comment-thread.945515/ With some more details, I can see how I can help. Perhaps attach the entire shader file to that forum thread.
I do want to remove some mesh from a model, can we have it using geometry shader, say I am generating a avatar character based on image, it is generating till shoulder, but i do want till neck portion, since i am attaching it with my headless avatar.
That's possible, but remember that geometry shaders are going to be run every render frame. So if this is a relatively static thing, having it in a pre-baked mesh is more efficient than generating it every frame. Geometry shaders are most useful for dynamic things. Now, if you are using the shader to make a seamless neck connecting two objects that are moving (body and head), then perhaps it would make sense to use this technique.
So with this method could I extend my shader graph shader to use tessalation if I implement hull and domain? I was always affraid of coding shaders that's why I always used shader graphs and avoided coding shaders.
@@GameDevBill I will, but it could take sometime as it's not top on my todo list. This video was really eye opening for me, it opened up bunch of possibilities, thank you!
I honestly don't know, though I'm mostly sure the answer is "no". I'd guess you could do something similar to the above technique, but I also don't know if Amplify lets you generate a code shader off of a node graph.
Well, I'm not 100% sure. I did a quick test, and HDRP does seem to generate a very similar shader file. That being said, HDRP doesn't quite have the same platform compatibility that URP has, so I'm not sure what gotcha's you'd run into if trying this more in depth. In short, "probably the same in HDRP, but I'm not sure".
I think it is bad idea to teach basics of Geometry shader beginning with code generated from Shader Graph. Why don't you just use simple HLSL code (vertex + fragment), and add geom function to it ?🤔
Fantastic tutorial!! Would love to see more complex tutorials using geometry shaders!
Thanks! I'll see what i can come up with 🙂
Update for Shader Graph version 10.x (and URP version 10.x) - from Unity 2020.2+
1. You no longer right-clicking on the master node to view the source. You instead select the shader graph, and inside its inspector hit the button "View Generated Shader"
2. If you take a code shader from SG 8.x, it will not run in SG 10.x. But, if you follow all the steps in this video again, it will work. There are just some differences in the parts of the generated file we don't touch that will need to be updated by URP itself.
Great tutorial, was hoping to get the file for this custom shader to do a diff with a "blank" shader to see where the code goes as it's real easy to misplace the code insertions, a problem exacerbated by the poor support for HLSL in any given IDE inc. Rider.
These videos are really high quality content. This is the stuff i've been searching for. Good ole reddit.
thanks for the kind words :)
Awesome! also(if im not mistaken) you can just feed vertices to triangle strip and it will produce triangle for each new vertex after 3rd, hance triangle strip
I'm glad you found your glasses! Those are important
Haha, I know!!
You make it sound so easy. Subscribed
thanks :)
@@GameDevBill Something I really want to know is: can you make a mesh node? That would totally make life easier
@@daslolo That would be awesome! I haven't thought of a way to do that yet, but if I do I'll be sure to post about it :)
Really great tutorial, you really deserve more views! Would love an example of using geometry shaders for grass that you mentioned :)
Thank you for the kind words! Yes, grass would be good. I'll put it on the list. :)
Amazing tutorial, simple and direct. Thanks for shared.
Glad you liked it!
Ah yes, top shelf stuff! This was great. Thank you!
Glad it was useful :)
This Random But Related Quote of the Week comes from Schoolhouse Rocks:
_Every triangle has three corners_
_Every triangle has three sides_
_No more, no less, you don't have to guess_
_When it's three, you can see_
_Its a magic number_
THANK YOU VERY MUCH!!!
This is great, thank you for making it
Glad you liked it!
I'm trying to make geometry shader that shows quads when editing for a 3d modeling software I'm developing. I tried multiple shaders from github but they revert to tris when editing mesh.
Awesome stuff!
If I wanted to do a dissolve effect for a low poly game where the object is "turned inside out" by gradually rotating every single triangle 180 degrees around some vector orthogonal to the (original) normal, would a geometry shader be the way to do that? Apart from the normals, what would I need to change in the vertex outputs? The world space coordinates?
Amazing tutorial!!
I have been using this for grass in hdrp but with latest versions it has stopped working and it may have to do with how packed varyings are different in code shader now. The first 2 passes seem to require different geomdata and geom than the rest but I can't quite figure it out.
Fantastic tutorial, thanks for your work!
Glad you liked it!
thanks for the info ! and I have a Q : is the zombie being sad for loosing his hand or his balloon ?
Ha! You know, I assumed it was the balloon, but it's hard to say for sure :)
Hey! As for specific things I want to do with shaders, I would like to know if its possible to do a voxel model with geometry shaders, or for general shaders, I would like to pass in bone transforms so I can calculate that in the shader. Atm I'm doing all this on the CPU. Particularly the bone calculations and mesh updating every frame is too heavy! (As unity ECS did not have animations a year ago so I implemented my own)
Voxels & Geometry - It can be done, but I'm not sure about the efficiency. My main concern would be the cost of feeding all that data in. hmm. I don't have a good answer here.
Bones - this should be a lot easier with some caveats... maneuvering the verts is something a vertex shader should be good at, but then you have to deal with normals. I don't have a video yet (soon?), but I do have a written post on re-calculating normals inside a shader graph gamedevbill.com/shader-graph-normal-calculation/. Or you can use a geometry shader as described in this video to recalculate them. The other caveat is that data transfer. It can be costly to transfer TONS of extra data into a shader each frame, so that's just something to keep in mind. All in all, there's a good chance that this will have better performance in a shader than in C#, but it's not an obvious winner (to me). It could go either way depending on implementation details.
@@GameDevBill Ahh I recall the cost can be pretty high for thousands of vertexes being uploaded per frame so for voxels itll be pretty high too! But If i restricted it to just characters I think.. least i could make a cool boss fight haha
Hmm I might try to write a shader then for bone animations! It's just a transform matrix multiplied by original vertex, while I reupload the bone transforms every frame to the shader! :)
Thank you again looking forward to more of your videos!
hi~ great tutorial! How would you do a fur shader on the URP for mobile / VR application? something really performant that can run on mobile.
fur in VR! that would be awesome. I'll add it to my investigation list, but generally to do fur on mobile VR you'll want something super stylized, so it can be non-realistic and thus cheaper to render. If I can come up with something I'll make a vid on it!
Could you do the same for the HDRP pipeline. I cant pass the part where you fill the GeoData, cant find those variables.
thanks a lot for this tutorial, its so hard to find doc or examples on to customize UDR or HDRPm in my case i would like to see this on HDRP also how can we use Structured buffers from compute shaders to affect geometry or even just particles, the tricck of generating the shader code is really a game changing, always felt so limited with HDPR because i cant customize anything . Anyway would love to see more stuff like this
I would really like to see a tutorial on making a low poly water shader.
Good idea. Thanks for the suggestion!
What an epic and sooo sooo good tutorial im gonna watch all a big like to you
Thanks for the kind words :)
i do the same work in geofromgraph shader,but it unwork and show tips(Shader warning in 'GeoFromGraph': Program uses geometry shaders, treating as if '#pragma require geometry' was present at line 72),is it the problem about verson(2019.4.1f1)?
I'm not sure I understand the issue. You can add details here, or if it's easier to use an actual forum, reply to this thread on the Unity forum here: forum.unity.com/threads/gamedevbill-tutorial-comment-thread.945515/
With some more details, I can see how I can help. Perhaps attach the entire shader file to that forum thread.
I do want to remove some mesh from a model, can we have it using geometry shader, say I am generating a avatar character based on image, it is generating till shoulder, but i do want till neck portion, since i am attaching it with my headless avatar.
That's possible, but remember that geometry shaders are going to be run every render frame. So if this is a relatively static thing, having it in a pre-baked mesh is more efficient than generating it every frame. Geometry shaders are most useful for dynamic things. Now, if you are using the shader to make a seamless neck connecting two objects that are moving (body and head), then perhaps it would make sense to use this technique.
So with this method could I extend my shader graph shader to use tessalation if I implement hull and domain?
I was always affraid of coding shaders that's why I always used shader graphs and avoided coding shaders.
I'm like 82% sure that will work. Very curious to hear results if you try it out!
@@GameDevBill I will, but it could take sometime as it's not top on my todo list.
This video was really eye opening for me, it opened up bunch of possibilities, thank you!
Does Amplify Shader Editor have Geometry shader support in its node system?
I honestly don't know, though I'm mostly sure the answer is "no". I'd guess you could do something similar to the above technique, but I also don't know if Amplify lets you generate a code shader off of a node graph.
What would be different for HDRP? I'm assuming that may be a long winded answer..
Well, I'm not 100% sure. I did a quick test, and HDRP does seem to generate a very similar shader file. That being said, HDRP doesn't quite have the same platform compatibility that URP has, so I'm not sure what gotcha's you'd run into if trying this more in depth.
In short, "probably the same in HDRP, but I'm not sure".
@@GameDevBill Interesting! I'll have to give it a shot. The practice of taking idea to.. shader.. is a challenging concept thus far
Yes ther one thing i want to how to create i real time refletion on urp sheder and how to create billboard
Good suggestions. I'll put those on the list of future tutorial ideas!
@@GameDevBill ok thenx
That's good content :D thanks.
Welcome!
I have too many passes. Generated shader has 8252 lines
Ha! Very cool.
thanks!
I think it is bad idea to teach basics of Geometry shader beginning with code generated from Shader Graph. Why don't you just use simple HLSL code (vertex + fragment), and add geom function to it ?🤔