needle-tools / shadergraph-markdown

Markdown-like syntax for ShaderGraph properties, to make better material inspectors
239 stars 17 forks source link

Ability to set GI Flags #3

Closed orels1 closed 2 years ago

orels1 commented 2 years ago

I've been using shader markdown in combination with BetterShaders for a bit at this point, and im absolutely loving it.

One thing I've been missing so far though is an ability to show the GI flags dropdown, which makes it so I can't have baked Emission on the materials without going into the debug mode and modifying the flags directly.

Is there a chance we might get like a special attribute or even better - just a dropdown in the "Additional Options" section that would provide that option?

hybridherbst commented 2 years ago

Hey there, thanks for the report. Would you mind sharing an example shader that reproduces the issue? This should in general be working.

orels1 commented 2 years ago

Just any custom shader

The unity's built in pipeline standard shader editor does this Which is what marks emissives to actually emit light during bakes. Without it just setting the _EMISSION keyword doesnt do enough. If i open the debug inspector and manually edit the GI flags from 4 (MaterialGlobalIlluminationFlags.EmissionIsBlack) to 2 (MaterialGlobalIlluminationFlags.BakedEmissive) - it instantly fixes the issue. So it would be nice to have that functionality of the standard material editor replicated in this one too, so we don't need to go into debug mode every time

Here's the minimal repro shader

Shader "Test/ShaderGITest"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        [Toggle(_EMISSION)]_Emission("Emission", Int) = 0
        [HDR]_EmissionColor("EmissionColor [_EMISSION]", Color) = (0,0,0,1)
        _EmissionMap("EmissionMap [_EMISSION]", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog
            #pragma shader_deature_local _EMISSION

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float4 _EmissionColor;
            sampler2D _EmissionMap;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col = tex2D(_MainTex, i.uv);
                fixed4 em = tex2D(_EmissionMap, i.uv);
                col += em * _EmissionColor;
                // apply fog
                UNITY_APPLY_FOG(i.fogCoord, col);
                return col;
            }
            ENDCG
        }

        Pass
        {
            Name "META"
            Tags {"LightMode"="Meta"}
            Cull Off
            CGPROGRAM

            #include"UnityStandardMeta.cginc"

            #pragma vertex vert_meta
            #pragma fragment frag_meta
            #pragma shader_feature_local _EMISSION
            ENDCG
        }

    }
    CustomEditor "Needle.MarkdownShaderGUI"
}

If you make a material as is and just bake it - it will not light up the env around it. If you go into the debug inspector and set GI Flags to 2 directly, like this image it will bake the emissives as you would expect.

You can also force those flags by switching the material to the standard shader, setting the emission parameters and then back (as their inspector will set those flags as per the code i linked above)

See the video for the full repro

https://user-images.githubusercontent.com/3798928/143402998-f1385516-610c-4d46-b893-e0b8befbda5a.mp4

hybridherbst commented 2 years ago

OK, I get it now - so this is more of a feature request than a bug report, as the same shader without Needle.MarkdownShaderGUI as Editor exhibits the same behaviour.

I'll add this!

Random note: love the code that RP Core has internally for this ✨ image

hybridherbst commented 2 years ago

image

Supported in the next release, 1.3.0!

orels1 commented 2 years ago

Yes, its a weird thing that unity decided to just not have in the default material inspector and thus leave everyone without a working emissive bake. Its like this weird thing along with a meta pass that seems to be very obscured for no particular reason.

Thank you!

hybridherbst commented 2 years ago

Let me know if you find any edge cases that won't work. I didn't just copy over what Unity does there because its different for built-in, URP, and HDRP 🙃 - instead trying to do the "right thing" for any combination of "_EMISSION" keyword and color/map properties. E.g. when your shader doesn't have an _EMISSION or _Emission toggle, I'll draw the toggle and dropdown, but if your shader has it then this overrides the behaviour (meaning you can now have emissive=bright on but no GI, unlike Unity's shaders)