vrm-c / UniVRM

UniVRM is a gltf-based VRM format implementation for Unity. English is here https://vrm.dev/en/ . 日本語 はこちら https://vrm.dev/

Home Page:https://vrm.dev/en

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MToonで発生するNaNを条件演算子でシンプルに回避出来そう

FujiSunflower opened this issue · comments

該当箇所

EPS_COLは値のソフトニング目的らしい

const half3 parametricRimFactor = pow(saturate(1.0 - dot(input.normalWS, input.viewDirWS) + _RimLift), max(_RimFresnelPower, EPS_COL)) * _RimColor.rgb;

提案

条件演算子で1度の計算がやや長くなるが、シェーダモデル3以上なら動きそう
const half3 parametricRimFactor = _RimFresnelPower == 0.0 ? _RimColor.rgb : pow(saturate(1.0 - dot(input.normalWS, input.viewDirWS) + _RimLift), _RimFresnelPower) * _RimColor.rgb;

補足

シェーダのif節は有名な通り処理がその分増えますが、条件演算子は結構シンプルでどっちの値を選ぶかという処理になったはずです。
参考ページ https://light11.hatenadiary.com/entry/2018/07/08/134440