Unity运行时开关Shader Pass的一种方法

做个记录

SetShaderPassEnabled 这个函数作用与名称相当不符。。。

材质球调用开关LightMode的tag可以达到开关当前pass的作用,尤其是在需要多个pass都渲染的情况!

shader中的需要有LightMode的tag

Tags{ "LightMode" = "ForwardBase" }

c#代码调用 

material.SetShaderPassEnabled("ForwardBase", false);

 下面是官方文档中SetShaderPassEnabled 函数说明

Enables or disables a Shader pass on a per-Material level.

By default, all Shader passes are enabled. This function allows a Material to treat a specific Shader pass (as indicated by LightMode pass tag) as if it does not exist in the Shader. For example, if the Shader has a "refraction" pass but you only want to enable it on Materials that have a refraction Texture assigned, pass "refraction" as passName and false for enabled for Materials without a refraction Texture assigned.

下面是官方文档中LightMode tag

LightMode tag

LightMode tag defines Pass’ role in the lighting pipeline. See render pipeline for details. These tags are rarely used manually; most often shaders
 that need to interact with lighting are written as Surface Shaders
 and then all those details are taken care of.

Possible values for LightMode tag are:

  • Always: Always rendered; no lighting is applied.
  • ForwardBase: Used in Forward rendering
    , ambient, main directional light, vertex/SH lights and lightmaps
     are applied.
  • ForwardAdd: Used in Forward rendering; additive per-pixel lights are applied, one pass per light.
  • Deferred: Used in Deferred Shading
    ; renders g-buffer.
  • ShadowCaster: Renders object depth into the shadowmap or a depth texture.
  • MotionVectors: Used to calculate per-object motion vectors.
  • PrepassBase: Used in legacy Deferred Lighting, renders normals and specular exponent.
  • PrepassFinal: Used in legacy Deferred Lighting, renders final color by combining textures, lighting and emission.
  • Vertex: Used in legacy Vertex Lit rendering when object is not lightmapped; all vertex lights are applied.
  • VertexLMRGBM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is RGBM encoded (PC & console).
  • VertexLM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is double-LDR encoded (mobile platforms).

 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

化虚为实

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值