LoginSignup
10
3

More than 1 year has passed since last update.

[Unity] ユニティちゃんSunnySideUp(URP版)付属のシェーダーをUnity2020.2以上で動かす

Last updated at Posted at 2021-05-12

問題

ユニティちゃんSunnySideUp(URP版)をUnity2020.3.6f1で動かしてみようとしたところ、正常に表示されません。
image.png
コンソールを見ると、
Shader error in 'Universal Render Pipeline/Toon': 'InitializeStandardLitSurfaceDataUTS': output parameter 'outSurfaceData' not completely initialized at /Users/hogehoge/Documents/Unity/UnityChanSSU_URP/Packages/UnityChanToonShaderVer2_Project-release-urp-2.2/Runtime/Shaders/UniversalToonBody.hlsl(199) (on d3d11)
なるエラーが出ています。

調べてみると、どうやらUnity2020.2からURPの新機能が追加され、その影響で動かなくなっている模様。

エラーメッセージを読むと、outSuffaceDataがUniversalToonBody.hlslの
inline void InitializeStandardLitSurfaceDataUTS(float2 uv, out SurfaceData outSurfaceData)
で完全に初期化されていないようです。

SurfaceDataについて調べてみると、下記のような構造になっています。
https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceData.hlsl

struct SurfaceData
{
    half3 albedo;
    half3 specular;
    half  metallic;
    half  smoothness;
    half3 normalTS;
    half3 emission;
    half  occlusion;
    half  alpha;
    half  clearCoatMask;
    half  clearCoatSmoothness;
};

InitializeStandardLitSurfaceDataUTS()のコードを見ると、clearCoatMask、clearCoatSmoothnessに値がセットされていません。

解決方法

とりあえず、下記のコードをInitializeStandardLitSurfaceDataUTS()の最後に追加することで、正常に表示されるようになりました。

                outSurfaceData.clearCoatMask = 0.0h;
                outSurfaceData.clearCoatSmoothness = 0.0h;

image.png

補足

UnityChanToonShaderVer2_Projectは下記でリリースが続けられており、こちらで最新のUnityへの対応がされているようです。
https://github.com/unity3d-jp/UnityChanToonShaderVer2_Project/releases
こちらでは下記のコードをInitializeStandardLitSurfaceDataUTS()の先頭に追加する形で修正されていました。

                outSurfaceData = (SurfaceData)0;

imageLicenseLogo.png
この記事はユニティちゃんライセンス条項の元に提供されています。

10
3
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
10
3