UnityShader------Surface shader

本文详细介绍了Unity中Shader的光照模型,包括标准的输出结构、基于物理的光照模型及内置的标准高光输出模型。解析了SurfaceShader编译指令及其参数,如光照模型的选择、透明度控制、阴影和曲面细分等,并说明了输入结构的要求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

标准的输出结构:

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
};

基于物理的光照模型的内置标准输出:

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
};

内置的标准高光输出模型:

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
};

Surface Shader编译指令:

语法:

SubShader
{
  CGPROGRAM
      #pragma surface 方法名 光照模型 [可选参数]              
  ENDCG    
}

必要参数

  •  方法名
  • 光照模型:内置的有基于物理的标准光照模型和标准高光模型,或者是没有物理的Lambert光照模型或者是BlinnPhong(高光)模型.
    • Standard光照模型对应 SurfaceOutputStandard输出结构, 对应Unity中的 Standard (metallic workflow) shader
    • StandardSpecular光照模型使用 SurfaceOutputStandardSpecular输出结构,对应Standard (specular setup) shader
    • Lambert and BlinnPhong光照模型不是基于物理的,但是可以兼容老旧硬件并且渲染很快.

可选参数

Transparency and alpha testing 是通过alpha 和 alphatest 指令控制的.透明度有两种类型:传统的alpha混合以及更真实的"左乘混合".

  • alpha | alpha:auto
  • alpha:blend
  • alpha:fade
  • alpha:premul
  • alphatest:VariableName
  • keepalpha
  • decal:add
  • decal:blend

Custom modifier functions[自定义可变函数]

  • vertex:VertexFunction
  • finalcolor;ColorFunction
  • finalgbuffer:ColorFunction
  • finalprepass:ColorFunction

Shadows and Tessellation[曲面细分]

  • addshadow
  • fullforwardshadow
  • tessellate:TessFunction

Code generation options

  • exclude_path
  • noshadow
  • noambient
  • novertexlights
  • nolightmap
  • noynlightmap
  • nodirlightmap
  • nofog
  • nometa
  • noforwardadd
  • nolppv
  • noshadowmask

Miscellaneous 选项

  • softvegetation
  • interpolateview
  • halfasview
  • approxview
  • dualforward
  • dithercrossfade

输入结构

输入结构中的texture必须以 uv 开头 。

  • float3 viewDir
  • float4 COLOR
  • float4 screenPos
  • float3 worldPos
  • float3 worldRef1
  • float3 worldNormal
  • float3 worldRef1:INTERNAL_DATA
  • float3 worlNormal:INTERNAL_DATA

转载于:https://www.cnblogs.com/qiongge/p/10491295.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值