multi compile underscores

documents say:

Looking at the standard shader source:

            #pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
            #pragma shader_feature _EMISSION
            #pragma shader_feature _METALLICGLOSSMAP
            #pragma shader_feature ___ _DETAIL_MULX2

Question is; why Alphatest has 1 underscore and detailmulx2 has 3 underscores? Does it make any difference?

No, it doesn’t make a difference.

so, why 3 underscores? to confuse people?

It’s an unknown, but my guess is at some point they had a bug that was being worked around.

he could just write no underscores like the emission and metallic features though, but he preferred to put not 1 but 3 underscores there. Such a mystery.

Not true. Having a single element has some magic behind it that expands it to two keywords, where two or more keywords are left alone.

So for example:
#pragma shader_feature _ONE
gets automatically expanded to:
#pragma shader_feature _ _ONE
So both create two variants: a variant with no added keyword and a variant with _ONE defined.

#pragma shader_feature _ONE _TWO
This is left as is and just creates two variants: a variant with _ONE defined and a variant with _TWO defined.

#pragma shader_feature _ _ONE _TWO
This creates three variants: a variant with _ONE defined, a variant with _TWO defined, and a variant with neither keyword.

That is true.
But then, isnt the no-keyword variant and the _ variant same anyways because both has no keywords to enable/disable?

Yes, which is why I think it was originally trying to overcome a bug they had, or at some point there was another option there like _DETAIL_MUL1X that got deleted. I seem to remember seeing something like #pragma multi_compile _ ___ _SOMETHING in another official shader at some point too. It just strikes me as the kind of thing I would do or see someone else do if there was a bug like the variant system incorrectly culling extra _ variants from different shader_feature lines, but using a different number of underscores got around the bug. Later the shader_features were changed around as the shader progressed and the one that used two underscores was removed or renamed but the _DETAIL_MUL2X line never got touched.

i spent all day modifying a custom standard shader and i ended up with 22043 variants instead of the original 35232 with all features just by removing the underscores.

Aaanyways, never had a chance to check all those messed up include files before. But this helped solve some mysteries. They used tiny hacks all over to overcome problems, certainly they were in a hurry.

That possibly means some valid variants are now missing. For example if you remove the _ from:
#pragma shader_feature _ _ALPHATEST_ON _ALPHABLEND_ON _ALPHAPREMULTIPLY_ON
that means there’s no proper variant for opaque.

Offcourse i didnt remove the opaque variant or any other necessary variants.