unity: 2021.3.16f1c1
First, here is the error log:
Error building Player: Shader error in ‘Shader Graphs/glTF-pbrMetallicRoughness’: ‘PBRDeferredFragment’: cannot convert from ‘struct v2f_surf’ to ‘struct SurfaceDescription’ at /XXX/Library/PackageCache/com.unity.shadergraph@12.1.8/Editor/Generation/Targets/BuiltIn/Editor/ShaderGraph/Includes/PBRDeferredPass.hlsl(145) (on gles3)
Compiling Subshader: 2, Pass: BuiltIn Deferred, Vertex program with DIRLIGHTMAP_COMBINED LIGHTMAP_ON LIGHTMAP_SHADOW_MIXING SHADOWS_SHADOWMASK UNITY_HDR_ON _MAIN_LIGHT_SHADOWS_CASCADE _MIXED_LIGHTING_SUBTRACTIVE _SHADOWS_SOFT
Platform defines: SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_RGBM_ENCODING UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PASS_DEFERRED UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: DYNAMICLIGHTMAP_ON EMISSION INSTANCING_ON LIGHTPROBE_SH OCCLUSION SHADER_API_GLES30 TRANSMISSION UNITY_ASTC_NORMALMAP_ENCODING UNITY_ENABLE_NATIVE_SHADOW_LOOKUPS UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_FULL_HDR UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING _GBUFFER_NORMALS_OCT _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_SCREEN _UV_ROTATION
Then let me explain the process of the problem:
-
We have a urp unity application that needs to be built to webgl using Unity’s Graphics.DrawMeshInstanced and Graphics.DrawMesh, as well as gltfast (which is used to load some gltf resources and render them with the Graphics API).
-
First, we tested building to webgl1 and the DrawMeshes worked fine, but DrawMeshInstanced showed a “Instancing is not supported” error, so we immediately thought that maybe Unity had not imported “ANGLE_instanced_arrays”. However, we couldn’t find a way for Unity to import this extension.
-
Then we tested building to webgl2, but during the build process, it seems that the gltfast shader’s deferred pass was enabled in webgl2, which caused some deferred-related shader code to be included in the compilation process, and then the above error was reported.
We looked at the code in PBRDeferredPass.hlsl(145) and found that the error was similar to a overload problem. PBRDeferredFragment(vertexSurf, …)
seemed not calling the correct method.
Any hints would be helpful, thank you.
3 Likes
I finally found another way. The direct cause of this problem is that I put gltfast’s “glTF-pbrMetallicRoughness.shadergraph” into the Resource directory, and I want to bundle this shader into the build result in this way, which leads to the problem. The another way is to create a material and then reference the shadergraph, and the problem magically disappears.
1 Like
I’ve looked at this a bit. PBRDeferredPass.hlsl definitely has an issue.
There are two versions of the PBRDeferredFragment function, one of takes a v2f_surf as the first parameter and one of which takes a SurfaceDescription. The compiler seems to be choosing the wrong one and then complaining about the mismatch.
I notice that the version that takes a v2_surf takes either 6 or 7 parameters, depending on whether SHADOWS_SHADOWMASK is true and UNITY_ALLOWED_MRT_COUNT > 4. However, the call to that function passes either 6 or 7 parameters based on whether OUTPUT_SHADOWMASK is true.
My guess at this point is that (for example) OUTPUT_SHADOWMASK is true but SHADOWS_SHADOWMASKS is false, so no version of the function definition matches the call and it gets reported by the compiler as a parameter type mismatch.
However, I don’t know enough about how Unity’s shader system works under the hood to know where things like SHADOWS_SHADOWMASK and OUTPUT_SHADOWMASK are being set.
2 Likes
It’s also worth noting that we’re using URP, but the error is in the built-in deferred shader pass. I have no idea why that pass is even being compiled.
3 Likes
I’m having the same issue with built in renderer, tried with Unity 2021.3 and 2022.3
Would we see any replies from Unity? We’re considering to backporting our project to built-in renderer due to performance issues with URP, but its a shame that the shader graphs can not be ported easily (or even re-created) because of this error. I wonder why the given pass is compiled at all on the first place, because we’re using Forward rendering and nothing should be compiled for Deferred.
I will appreciate any hints on how to disable Deferred shader variants compilation in 2021.3 or above.
2 Likes
This issue just happened to me too unity 2022.3.18f built-in.
EDIT: I might have tried a dozen different things to fix it, all but restarting unity. For some reason if the issue happens, after a restart of the editor, it compiles again. Still clueless
2 Likes
I’m encountering this issue too when trying Build and Run to WebGL platform, Unity 2022.3.14f1.
It seems like when I try to build the first time, the error get triggered, then if I simply relaunch the build, it proceeds further without throwing the compile error, and the build finishes… To me it makes no sense :o
3 Likes
still having issues with this… very annoying… anyone able to solve it? ussing URP
2 Likes
I had the exact same issue with a project that I was working on. I was able to solve it by going into the shadergraph settings under project settings and changing the Warning Threshold from 16 to 8. This worked for me in Unity version 2022.3.18f1 using the default render pipeline.
4 Likes
2 years of this bug and fix = just 1 line…
I can’t use lightmaps, because in this case I have deffered error with any lit shader.
Pls unity devs, just replace line 146
#if OUTPUT_SHADOWMASK
to
#if defined(SHADOWS_SHADOWMASK) && (UNITY_ALLOWED_MRT_COUNT > 4)
compiller uses different keywords in the PBRDefferedFragment
8 Likes
Thanks @kripto289
That worked.
It is so unbelievable how unity team still have not fixed this major issue. Latest release 2022.3.41 still has the problem, but fortunately your solution worked.
Huge thanks
2 Likes
I tried to edit like @kripto289 showed in here, but it keeps reverting back to the original version. Does anyone know how to make sure it persists?
1 Like
changing the Warning Threshold from 16 to 8. This worked for me in Unity version 2022.3.18f1 using the default render pipeline this worked !!! !
but one week later it failed again 
but i found if i tried it twice in a row it worked the second time for some reason