Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug deferred fragment compilation error when building to webgl2

Discussion in 'Shader Graph' started by fxxjdeddqq, Dec 28, 2022.

  1. fxxjdeddqq

    fxxjdeddqq

    Joined:
    Dec 28, 2022
    Posts:
    3
    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:

    1. 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).

    2. 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.

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

    upload_2022-12-28_18-0-48.png

    Any hints would be helpful, thank you.
     
    Aldeminor likes this.
  2. fxxjdeddqq

    fxxjdeddqq

    Joined:
    Dec 28, 2022
    Posts:
    3
    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.
     
    Gulzat2 likes this.
  3. CETechnology

    CETechnology

    Joined:
    Apr 14, 2022
    Posts:
    4
    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.
     
    Aldeminor likes this.
  4. CETechnology

    CETechnology

    Joined:
    Apr 14, 2022
    Posts:
    4
    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.
     
    Aldeminor likes this.
  5. Svartskogen

    Svartskogen

    Joined:
    Apr 17, 2017
    Posts:
    9
    I'm having the same issue with built in renderer, tried with Unity 2021.3 and 2022.3
     
  6. Aldeminor

    Aldeminor

    Joined:
    May 3, 2014
    Posts:
    18
    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.
     
    Svartskogen likes this.