Geometry Shaders in URP - Plus how to create code shaders from shader graph

preview_player
Показать описание
Geometry shaders are shader functions you can run after your vertex shader, and before the fragment shader. Today I’ll go over how to set one up in the Universal Render Pipeline, or URP. As a bonus, I’ll also be covering a trick for creating code shaders in URP that bypasses a lot of the effort and understanding generally required

I used Unity 2020.1 and Shader Graph 8.2

Chapters…
0:00 overview
2:33 shader graph setup
6:40 generated code file
9:48 geometry shader coding

**** Update for Shader Graph 10.x
This video was made with Shader Graph 8.2
If you are using Shader Graph 10.x there are a couple key differences:

The create shader options have moved within a sub-menu called "Universal Render Pipeline, and some are renamed. So "Create--Shader--PBR graph" becomes "Create--Shader--Universal Render Pipeline--Lit Shader Graph"
The per-input settings that were in the blackboard are now in the "Graph Inspector" within the "Node Settings". You must have the input selected to see its settings in that window.
Some other settings that were on-node are now also in that Graph Inspector, though you can generally ignore these.
If you want to generate a code shader from the graph (as I do in this video), you do so on the graph asset inspector (not on the master node as you did in 8.2). Now select the graph asset, and hit "View Generated Shader" button in its inspector.
****

Since shader graph doesn’t support geometry shaders, we need a code shader. Once enough of the graph is filled out to give you the functionality you need, right click on the master node, and select “Show Generated Code”. This will create a file in Project/Temp/ that you can copy into /Assets/ and use as a normal code shader.

A geometry shader is a shader that runs on, well, geometry. More specifically, it’s run on every triangle. So for a quad, your vertex shader would be run 4 times, and a geometry shader would be run twice. It’s worth noting that in the quad example, the shared vertices are considered unique at this stage. So you technically have six vertices by the time the geometry shader is executing.

#ShaderGraph #Unity #GeometryShader
Рекомендации по теме
Комментарии
Автор

Fantastic tutorial!! Would love to see more complex tutorials using geometry shaders!

jeffking
Автор

These videos are really high quality content. This is the stuff i've been searching for. Good ole reddit.

deusxyz
Автор

I'm glad you found your glasses! Those are important

travisotwell
Автор

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.

GameDevBill
Автор

Really great tutorial, you really deserve more views! Would love an example of using geometry shaders for grass that you mentioned :)

jakkos-net
Автор

Amazing tutorial, simple and direct. Thanks for shared.

peterparkerr
Автор

THANK YOU VERY MUCH!!! <3 I learned a lot.

nyandash
Автор

Ah yes, top shelf stuff! This was great. Thank you!

MortalVildhjart
Автор

This is great, thank you for making it

ThomasChen-urgt
Автор

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

ChronoWrinkle
Автор

What an epic and sooo sooo good tutorial im gonna watch all a big like to you

eslamzaki
Автор

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?

MadsMadsen
Автор

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)

deusxyz
Автор

thanks for the info ! and I have a Q : is the zombie being sad for loosing his hand or his balloon ?

soundrraj
Автор

Fantastic tutorial, thanks for your work!

iamarugin
Автор

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.

mikhailhumphries
Автор

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.

JeckleMunopker
Автор

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_

GameDevBill
Автор

Could you do the same for the HDRP pipeline. I cant pass the part where you fill the GeoData, cant find those variables.

joaofonseca
Автор

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.

davidhuang
visit shbcf.ru