Create a surface shader in the Built-In Render Pipeline
Create a Surface Shader using pragma directives.
Read time 1 minuteLast updated 19 days ago
Follow these steps:
- Add a block to the
CGPROGRAMblock in your shader code, not theSubShaderblock. Unity automatically creates multiple passes when it compiles the surface shader.Pass - Add a directive.
#pragma surface [surfaceFunction] [lightModel]
Surface shaders aren't compatible with blocks, but you can use HLSL inside a block. For more information, refer to Shader code blocks in ShaderLab reference.
HLSLPROGRAMCGPROGRAMExample
Shader "Example/Diffuse Simple" { SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Lambert struct Input { float4 color : COLOR; }; void surf (Input IN, inout SurfaceOutput o) { o.Albedo = 1; } ENDCG } Fallback "Diffuse"}
Here's how it looks like on a model with two Lights set up:

Basic surface shader example.