-
Notifications
You must be signed in to change notification settings - Fork 62
Description
I was having two issues using MToon shader in an Unity Android project. I kind of fixed them in my case, and I want to share my findings.
I made some tests with MToonCore.cginc file from MToon's latest commit, and using UniVRM's latest commit.
- Firstly, line 146 throws an invalid subscript error, that doesn't let me build my game for Android.
UNITY_LIGHT_ATTENUATION(atten, i, i.posWorld.xyz);
Shader error in 'VRM/MToon': invalid subscript '_ShadowCoord' at Assets/VRM/MToon/MToon/Resources/Shaders/MToonCore.cginc(146) (on gles3)
I made some hacks (described below) to bypass this compilation error and build my game for Android.
First, I commented line 146 and added some variables:
//UNITY_LIGHT_ATTENUATION(atten, i, i.posWorld.xyz);
float atten = 1;
float3 worldPos = i.posWorld;
Then I added the lightCoord parameter to the #ifdefs from lines 159 to 164:
#ifdef POINT
unityShadowCoord3 lightCoord = mul(unity_WorldToLight, float4(worldPos, 1.0)).xyz;
lighting *= tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).r;
#endif
#ifdef SPOT
unityShadowCoord4 lightCoord = mul(unity_WorldToLight, float4(worldPos, 1.0));
lighting *= (lightCoord.z > 0) * UnitySpotCookie(lightCoord) * UnitySpotAttenuate(lightCoord.xyz);
#endif
At this point, I can finally build my game for Android, with the lights working nicely on the character model.
- After bypassing the shader compilation error mentioned above, Line 96 makes the game crash and restart my Android device (!)
Line 96 is currently like this. Makes the game crash and my device to restart.
float4 vertex = float4(0, 0, 2, 1);
In some previous versions of MToon, it was like this. Also makes my Android device restart.
float4 vertex = 0;
If I change it to this (equivalent to the MToon version included in UniVRM v0.44), the game doesn't crash anymore.
float4 vertex = UnityObjectToClipPos(v.vertex);