If you're anything like me you will have started writing GLSL shaders where everything is clear, then gone into Unity's ShaderLab and struggled with semantics and all the other confusing, but probably necessary stuff. Now the struggle returns with SRP (HDRP in particular). I found myself not being able to create a simple triangle or a simple lithing shader once again! I bet there are at least several hundred people like me who want to write some interesting shaders but are unable to because of lack of documentation and examples. Please send leave some links to simple shaders that work on HDRP here. Preferably help us get started by sending an example for generating 1 triangle with a geometry shader in HDRP. Reading different vertex buffers.
We're all waiting for that. The HDRP is still in flux, so no one outside of Unity really knows how to write shaders for the HDRP unless you dig through the source code. Unity's official stance is "use Shader Graph". Writing shaders that work with the HDRP is enormously complex, like an order of magnitude more complex than the built in rendering paths.
Is this still the case (no official examples)? I'm trying to find some. And this thread came up first. Best I could find is keijiro's repo, might be of use for someone as well. https://github.com/keijiro/TestbedHDRP Nodes are fine as long its not something as complex as porting terrain, or speedtree shaders, or any other custom vfx done prior to the HDRP update. So any extra examples would be nice. Edit: Also, this is probably the gold https://catlikecoding.com/unity/tutorials/scriptable-render-pipeline/
As someone who is new to learning shaders, the lack of documentation and overwhelming amount of options is frustrating. I'm halfway through an online course where I'm learning how to write shader code for unity, and I just came to find out that I won't be able to apply what I'm learning to my SRP project. At least not directly. Thanks to @bgolus, at least I know now that unity wants me to lean into shader graph. But it would have been nicer to not have to seek a thread like this out to find this out. Ugh
In HDRP 7.X, if you right-click on the master-node in a shader graph, you get an option in the context menu that lets you generate a shader based on the shader you created with shader graph. It will be a real monster of a shader, but you can study it along with other variations of the shader, in order to figure out how to write a shader for HDRP. I've seen the occasional post from people that claim to have learned how to hand write shaders for HDRP this way, but they also said there was a lot of trial and error before they figured out which parts make up the minimum requirements for an HDRP. It's no replacement for proper documentation, which is something that HDRP has always lacked.
Can be a little bit easier to just look in the HDRP package's shader folder and see how the existing shaders are written. Then you're privy to all the handy macros they've written to make things simpler. And you can always find out what the macro is doing by doing a text search of the hlsl and include files in the HDRP and Core packages.
Oh, I've done that when it comes to custom passes. And, if they do the thing that I suggested, then they're going to have to do that also, because they're going to have to look up what the macros get translated to. A person can spend days digging through all the shader files, drawing diagrams, and writing their own documentation.
I write some tutorials for a simple pixel and geometry shader. If you don't want to use their lighting models it looks actually very similar to the standard surface approach. pixel shader: source code: https://github.com/Paltoquet/HDRPCustomShader example: Code (CSharp): HLSLPROGRAM // List all the attributes needed in your shader (will be passed to the vertex shader) // you can see the complete list of these attributes in VaryingMesh.hlsl #define ATTRIBUTES_NEED_TEXCOORD0 #define ATTRIBUTES_NEED_NORMAL #define ATTRIBUTES_NEED_TANGENT // List all the varyings needed in your fragment shader #define VARYINGS_NEED_TEXCOORD0 #define VARYINGS_NEED_TANGENT_TO_WORLD #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassRenderers.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/VertMesh.hlsl" float4 _ColorMap_ST; float4 _Color; PackedVaryingsType Vert(AttributesMesh inputMesh) { VaryingsType varyingsType; varyingsType.vmesh = VertMesh(inputMesh); return PackVaryingsType(varyingsType); } float4 Frag(PackedVaryingsToPS packedInput) : SV_Target { float4 outColor = float4(0.0, 0.2, 0.8, 1.0); return outColor; } #pragma vertex Vert #pragma fragment Frag ENDHLSL
jajajajajajajajajajajajaja If you had posted this 3 or 4 days sooner, I would have saved quite a few hours of work. This isn't too far off from how I pulled the VertexID data.
Never tried, you could add a folder reference, but that change might get overwritten when code recompiled in editor. Just use search text in files. Keep open the files that have the content you're interested in using. If you look at HDRP shaders you can see how their #includr lines written the path to reference those files.