Version: Unity 6 Preview (6000.0)
Language : English
Surface Shaders and rendering paths in the Built-In Render Pipeline
Set the lighting model in a Surface Shader in the Built-In Render Pipeline

Create a surface shader in the Built-In Render Pipeline

Surface shaderA program that runs on the GPU. More info
See in Glossary
is placed inside CGPROGRAM..ENDCG block, just like any other shader. The differences are:

  • It must be placed inside SubShader block, not inside Pass. Surface shaderA streamlined way of writing shaders for the Built-in Render Pipeline. More info
    See in Glossary
    will compile into multiple passes itself.
  • It uses #pragma surface ... directive to indicate it’s a surface shader.

The #pragma surface directive is:

#pragma surface surfaceFunction lightModel [optionalparams]

Example

  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:

Surface Shaders and rendering paths in the Built-In Render Pipeline
Set the lighting model in a Surface Shader in the Built-In Render Pipeline