Zallist / unity.zallist.universal-simple-lit-shadergraph-target

This plugin simply adds a Simple Lit material (SubTarget) to the Universal target for Shader Graph for URP
Other
85 stars 14 forks source link

Enabling decals breaks shaders on URP 12.1.7 (Unity version 2021.3.13f1) #18

Closed grenappels closed 1 year ago

grenappels commented 1 year ago

Hello, love that this exists, it's wonderful so thank you. I'm encountering an issue where if I enable decal renderer feature, my shader stops compiling with this error:

Shader error in 'Shader Graphs/human': l-value specifies const object at /Users/grena/Documents/unity/star-door/Library/PackageCache/com.zallist.universal-shadergraph-extensions@1c0fc81fda/Editor/ShaderGraph/Includes/SimpleLitGBufferPass.hlsl(112) (on d3d11)

Compiling Subshader: 0, Pass: GBuffer, Fragment program with LIGHTMAP_SHADOW_MIXING _DBUFFER_MRT3 _GBUFFER_NORMALS_OCT _MAIN_LIGHT_SHADOWS _MIXED_LIGHTING_SUBTRACTIVE _REFLECTION_PROBE_BLENDING _REFLECTION_PROBE_BOX_PROJECTION Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS Disabled keywords: DEBUG_DISPLAY DIRLIGHTMAP_COMBINED DOTS_INSTANCING_ON DYNAMICLIGHTMAP_ON FOG_EXP FOG_EXP2 FOG_LINEAR INSTANCING_ON LIGHTMAP_ON SHADER_API_GLES30 UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA 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_RGBM_ENCODING 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 _DBUFFER_MRT1 _DBUFFER_MRT2 _LIGHT_LAYERS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN _RENDER_PASS_ENABLED _SHADOWS_SOFT

the code at line 112 is

#ifdef _DBUFFER
    ApplyDecal(unpacked.positionCS,
        surfaceDescription.BaseColor,
        specular,
        inputData.normalWS,
        /*metallic,*/
        0,
        /*surfaceDescription.Occlusion,*/
        1,
        surfaceDescription.Smoothness);
#endif

I will try upgrading to a newer version of unity since I'm not in production or anything, but I might be stuck on the current version and just wanted to flag that this specific thing was broken for me.

grenappels commented 1 year ago

I found a hacky workaround for now: it seems like the 0 for metallic and the 1 for occlusion were the const values that were trying to be modified. if i just make a throwaway var (since they are not used anyway) and feed it to the ApplyDecal function, it works fine.

    float throwaway = 0.0;

#ifdef _DBUFFER
    ApplyDecal(unpacked.positionCS,
        surfaceDescription.BaseColor,
        specular,
        inputData.normalWS,
        /*metallic,*/
        throwaway,
        /*surfaceDescription.Occlusion,*/
        throwaway,
        surfaceDescription.Smoothness);
#endif
Zallist commented 1 year ago

Looks like applydecal is marked as inout. https://github.com/Unity-Technologies/Graphics/blob/632f80e011f18ea537ee6e2f0be3ff4f4dea6a11/Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl#L120

If you want to make a pull request with your throwaway variable, I'll merge it through.