Hello,
I have written this very simple unlit shader because I think the default UniversealRenderPipeline/Unit is not fast enough (maybe I’m wrong and my shader is probably slower)
This is a fixed funtion shader, which currently will generate a Builtin shader rather than a URP shader (if you select the shader and look at the inspector for it, you can compile the ‘Fixed Function’ code, and you will see why it will not work with URP).
The reason it will render is because URP was designed so that it could render built in shaders that were unlit. But this is not the way to go forward, and you will need to write a shader using the new SRP shaderlibrary, unfortunately we are super slim when it comes to learning resources here.
If you want to make a custom URP shader take a good look at the provided ones in URP, they are more complicated than they need to be due to the ‘uber’ nature of them and also platform support, XR, instancing, etc.
Below you can see a very basic Unlit shader in URP, this is what I would say is probably the bare minimum.
Shader "Unlit/NewUnlitShader"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
// Will make life easier to have at least URP core.hlsl
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#pragma vertex vert
#pragma fragment frag
// For SRP Batcher to work you need to put things in the right Cbuffer
CBUFFER_START(UnityPerMaterial)
half4 _Color;
CBUFFER_END
float4 vert(float4 positionOS : POSITION) : SV_POSITION
{
// This struct contains commonly used transformations such as Clip, World, etc
VertexPositionInputs vertexInput = GetVertexPositionInputs(positionOS.xyz);
return vertexInput.positionCS;
}
half4 frag() : SV_Target
{
return _Color;
}
ENDHLSL
}
}
}
To that note, you will notice this is a vert/frag shader and these are the only shaders fully supoported under SRP, the other optiuon is shadergraph, these will also generate shader that have full platform support, XR, instancing etc.
This shader should work on all platforms but will not work with intancing or stereo rendering.
if i inlcude my own HLSL shader, should i also add CBUFFER_START(UnityPerMaterial) inside the included HLSL file properties?
Right now i have a hand made shader compatible with SRP Batcher, but my hlsl include property are not inside the CBUFFER_START. (only the properties inside the main shaders are)