Why are texture properties declared with the value "white"?

I’ve seen some variation on _MainTex ("Main Texture", 2D) = "white" {} in any number of shader properties, but I don’t actually know why textures are assigned a value there, what that value means, or what the alternatives are. Is there any documentation for this? Is this a Unity thing or an HLSL thing? And is it necessary or just a convention?

this mentions some of those values in Texture2D:

1 Like

The above documentation explains what “white” is, and what the other options are, but not why.

In shaders, any texture object that’s used needs to have something assigned to it, or the GPU will fail to render the shader, or may even crash outright. If nothing is assigned, Unity will automatically assign a default texture, which comes in the form of a 1x1 pixel texture. The material property definition gives you the option of using one of a few different 1x1 default textures in the case that a middle grey texture isn’t a good option.

Now what you didn’t ask about, and what the documentation doesn’t even mention at all, is the {} after that. That’s a legacy thing that does absolutely nothing today, but is still required for unknown reasons (i.e.: they’ve never bothered to remove the requirement for it, even though it does nothing). It used to be how you chose different UVs or texture projections in the very early days of fixed function shaders, but hasn’t been used for literally over a decade.

2 Likes

Fantastic thank you that’s extremely helpful. I figured that the curly braces were some arbitrary piece of syntax like that, but it’s good to know for sure that they are truly vestigial.

Sad they don’t have a default Transparent (0,0,0,0) texture