Unity Surface Shaders 表面着色器备忘

表面着色器不能写在pass中

输出结构

1.Standard

struct SurfaceOutput
{
    fixed3 Albedo;  // diffuse color
    fixed3 Normal;  // tangent space normal, if written
    fixed3 Emission;
    half Specular;  // specular power in 0..1 range
    fixed Gloss;    // specular intensity
    fixed Alpha;    // alpha for transparencies
};

2.physically based lighting models

Standard
struct SurfaceOutputStandard
{
    fixed3 Albedo;      // base (diffuse or specular) color
    fixed3 Normal;      // tangent space normal, if written
    half3 Emission;
    half Metallic;      // 0=non-metal, 1=metal
    half Smoothness;    // 0=rough, 1=smooth
    half Occlusion;     // occlusion (default 1)
    fixed Alpha;        // alpha for transparencies
};
StandardSpecular
struct SurfaceOutputStandardSpecular
{
    fixed3 Albedo;      // diffuse color
    fixed3 Specular;    // specular color
    fixed3 Normal;      // tangent space normal, if written
    half3 Emission;
    half Smoothness;    // 0=rough, 1=smooth
    half Occlusion;     // occlusion (default 1)
    fixed Alpha;        // alpha for transparencies
};

编译指令

#pragma surface surfaceFunction lightModel [optionalparams]

1.必要参数

  • surfacefunction 定义表面着色器函数名称。函数定义格式应为void surf (Input IN, inout SurfaceOutput o),Input为自定义输入结构,SurfaceOutput为输出结构,根据不同的lightModel做出变化。
  • lightModel 使用的光照模型
光照模型介绍
Standard对应SurfaceOutputStandard
StandardSpecular对应SurfaceOutputStandardSpecular
Lambert / BlinnPhong对应SurfaceOutput ,可用于低档硬件

2.可选参数

  • Transparency and alpha testing
alpha or alpha:auto
alpha:blend
alpha:fade
alpha:premul
alphatest:VariableName
keepalpha
decal:add
decal:blend
  • Custom modifier functions

  • Shadows and Tessellation

  • Code generation options

  • Miscellaneous options

3.输入结构

变量名称及类型注释
float3 viewDir
float4 with semantic
float4 screenPos
float3 worldPos
float3 worldRefl
float3 worldNormal
float3 worldRefl
float3 worldNormal
©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页