LoginSignup
1
1

More than 5 years have passed since last update.

[material dynamic branch] X4014 divergent gradient operation error

Last updated at Posted at 2018-12-02

アドベントカレンダー向けにちょっとマテリアルを調査してたら動的分岐にまつわるコンパイルエラーに遭遇したのでメモっておく

ブランチブロックと勾配加工

動的分岐を使った最適化をおこなうとX4014のdivergent gradient operationがなんとかなんとかというエラーが出ることがあります。

image.png

大雑把に言ってサンプラーに渡されるUVの値をブランチブロック内部で加工するとこのエラーが発生します。
加工するということはサンプラーがMIPMAPを選択するときに使う勾配が変化してしまうためです。

BiasでUVに加工なし > OK

float4  Local3 = ProcessMaterialColorTextureLookup(
    Texture2DSampleBias(Material_Texture2D_0,Material_Texture2D_0Sampler,Parameters.TexCoords[0].xy,View_MaterialTextureMipBias)
);

BiasでUVに加工あり > Compile error

float4  Local3 = ProcessMaterialColorTextureLookup(
    Texture2DSampleBias(Material_Texture2D_0,Material_Texture2D_0Sampler,Parameters.TexCoords[0].xy+float2(1.0f,0.5f),View_MaterialTextureMipBias)
);

レベルを直接指定するもの(SampleLevel) > OK

float4  Local7 = ProcessMaterialColorTextureLookup(
    Texture2DSampleLevel(Material_Texture2D_0,Material_Texture2D_0Sampler,Parameters.TexCoords[0].xy+float2(1.0f,0.5f), float (Local6))
);

まとめ

1.シェーダー内部で動的分岐を使う場合は、サーフェスに使う場合はブロック内部でUVを加工せずに使う
2.ポストプロセスなどのSampleLevelを使って直接指定するものは気にしないでOK

サーフェス用のマテリアルで動的分岐を使う場合はちょっと気を付けないといけない。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1