Santarh / MToon

Toon Shader with Unity Global Illumination

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Rendering types Transparent/Cutout not working on Unity 2019.1

andreiagmu opened this issue · comments

After updating my project to Unity 2019.1.0f2, rendering types Transparent/Cutout aren't working correctly.
Black/colored areas appear where should be transparent areas.

In the screenshot below, notice the black areas around the model's eyes and cat ears. There's also the yellow area at the model's forehead (part of the base hair texture that should be transparent).

MToon transparency errors

Workaround for this issue (by @fms-cat)
https://twitter.com/FMS_Cat/status/1119769262292267008

Commenting out the UsePass "Standard/SHADOWCASTER" line in MToon.shader seems to fix the Transparency and Cutout rendering modes.

In my case, after commenting out the line, I recompiled the shader and restarted Unity for the workaround to work.
In some textures, I needed to change the Rendering Mode to Opaque and then back again to Cutout/Transparent to make the black areas disappear.

commented

I'm so sorry I forgot to share the workaround here @andreiagmu 🙇
Currently my colleague is working on it so we'll send you a PR later

Referred from vrm-c/UniVRM#237

After a deeper dig, I found out the problem is caused by the line below.
UsePass "Standard/SHADOWCASTER"
The problem is introduced by the new modification on Standard.shader. It uses shader_feature_local instead of shader_feature.
The shader_feature_local will just make the keywords for multi_compile and shader_feature not working anymore.
And also, the problem can't be reverted. Once you compiled the shader with shader_feature_local. Even you remove the lines.
The keyword will still not work.

The temp workaround is to delete the shader. And use the code below for a temp fix. I'll still wait for the replies from official and give more updates here.

			Pass {
				Name "ShadowCaster"
				Tags { "LightMode" = "ShadowCaster" }

				ZWrite On ZTest LEqual

				CGPROGRAM
				#pragma target 3.0

				// -------------------------------------


				#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
				#pragma shader_feature _METALLICGLOSSMAP
				#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
				#pragma shader_feature _PARALLAXMAP
				#pragma multi_compile_shadowcaster
				#pragma multi_compile_instancing
				// Uncomment the following line to enable dithering LOD crossfade. Note: there are more in the file to uncomment for other passes.
				//#pragma multi_compile _ LOD_FADE_CROSSFADE

				#pragma vertex vertShadowCaster
				#pragma fragment fragShadowCaster

				#include "UnityStandardShadow.cginc"

				ENDCG
			}

Thanks for your reporting.

This issue was solved by #45 and #46 .

Hello,

This case was marked as By Design. The reason for this:
"Local keywords are prioritized over global ones. This means that if a shader defines a keyword both as local and global, only the local one will work as expected.

The user shader, in this case, is defining _ALPHABLEND_ON as global keywords but the UsePass source defines it as a local keyword. When enabling _ALPHABLEND_ON from the script, it will affect only the local keyword. This can be easily worked around by modifying the shader to not have conflicting keyword types. In this particular case modifying the _ALPHABLEND_ON to use multi_compile_local is the correct fix.

We acknowledge that the current situation is not optimal as the local keywords feature can break existing content in some cases and those can't be resolved with automatic shader upgrader. To make these cases easier to spot and fix, we'll be adding new warnings when having conflicting keyword definitions in the shaders."

Because of this, I will be closing this case now.
But if you have any further questions, feel free to reply to this email and this case will reopen, or submit a new bug report.

Regards,
Aurimas A
Customer QA Team

Here's the final feedback from official about the local keywords.