- Home /
How to use this tessellation cginc with URP?
Here's the code from Catlike Coding:
https://gist.github.com/niuage/ed730f36423f25b8e1f452a828c68808
I've been trying to look up how to use this for a grass shader for URP, without any luck.
First of all, can I include cginc files in HLSLPROGRAM
?
And I'm getting errors about UNITY_domain
and company not being defined, but I'm having a hard time finding what they should be replaced with for them to work in HLSLPROGRAM
.
Any help or just small pointers would be very appreciated!
ps: what I'm trying to do overall is add tessellation to this shader: https://twitter.com/Cyanilux/status/1255870774558232582
Answer by Namey5 · May 17, 2020 at 03:55 AM
Whilst you can include CG files in HLSL, that whole include script is already basically in HLSL, so you can just convert the file extension from '.cginc' to '.hlsl' and use that instead. As for the errors, 'UNITY_domain' etc. are macros that expand to the relative tessellation keywords on platforms that support it and are defined in the legacy "HLSLSupport.cginc" which used to be automatically included with any CGPROGRAM. All you need to do to get that to work here however is to just copy those defines into the beginning of the tessellation include;
// Tessellation programs based on this article by Catlike Coding:
// https://catlikecoding.com/unity/tutorials/advanced-rendering/tessellation/
#if defined(SHADER_API_D3D11) || defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE) || defined(SHADER_API_VULKAN) || defined(SHADER_API_METAL) || defined(SHADER_API_PSSL)
#define UNITY_CAN_COMPILE_TESSELLATION 1
# define UNITY_domain domain
# define UNITY_partitioning partitioning
# define UNITY_outputtopology outputtopology
# define UNITY_patchconstantfunc patchconstantfunc
# define UNITY_outputcontrolpoints outputcontrolpoints
#endif
struct vertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
};
...
Second time you helped me out Namey! thx ;) Funnily enough I had already tried the cginc -> hlsl change as well as trying to define UNITY_domain & co, but didnt go the whole way.
Now, it compiles fine, but... nothing shows up, regardless of the tessellation factor I enter... In case you want to take a look, here's a tiny repo containing a couple files. https://github.com/niuage/Grass-Shader-With-Tessellation - but that's another problem, so dont worry about it if you dont have free time :)
I'm not really familiar with URP, but at first glance you have multiple different functions named 'vert' that serve different purposes, so I would go through and make sure you are only using one vertex function and that it does what you need. Also, you will probably need to have a custom shadowcaster/depth pass otherwise it may not be drawn correctly (I'm assu$$anonymous$$g URP uses a depth prepass like the built-in renderer did).
https://www.youtube.com/watch?v=8_xCX9mG$$anonymous$$5c
I got it working \o/
Your answer
Follow this Question
Related Questions
I would like to know how to make a tessellation shader with LightWeightRenderPipline(Unity2018.2.13) 0 Answers
How to do texture bombing in shader graph 0 Answers
Is it possible to pass scene color to Sample Texture 2D LOD (URP, Shader Graph)? 0 Answers
Edit Offset Values in Unity URP Lit Shader via Script 0 Answers
How to adapt this shader to URP? 1 Answer