Custom default texture for shader: other than white, black, grey, or bump?

Hello! Using Unity 5.3.5p2 here,

In the Parameters block inside the .shader file:
I see there is only the possibility of 4 default textures for a shader slot, which are used when no texture is set on the slot in the material.
The problem is I need one more!
black (0,0,0,1) isn’t good enough!
I need: **zeroRGBA** (0,0,0,0)

So, I created a 1x1 32bit TGA called zeroRGBA which has its one pixel set to (0,0,0,0).
And I set my texture up inside Properties{} like so, to have this **zeroRGBA** as default:

_DamageMap("DamageMap", 2D) = "zeroRGBA" {}

But!, when I clear out the texture to “None” in the material Inspector, my default texture is not chosen!

It appears that you can only use one of the 4 sacred values: black, white, grey, and bump.
http://docs.unity3d.com/432/Documentation/Components/SL-Properties.html
For texture (2D, Rect, Cube) the default value is either an empty string, or one of built-in default textures: “white”, “black”, “gray” or “bump”.

For texture (2D, Cube) the default value is either an empty string, or one of built-in default textures: “white”, “black”, “gray” or “bump”.

Any possibility to use a custom Texture there? If not, then any possibility to get this into a future Unity?? I can think of cases that would be very valid, and ability to set your own custom Texture from your project would cover all cases… An additional nice-to-have would be the ability to set any custom color there like float4(0,0.5,1,0), which would auto-gen a texture into the output app (and would also satisfy my own current need as well)…

1 Like

You can assign any texture in the project as so called “default map” to a shader. I recorded a video that shows how it is done.

https://www.youtube.com/watch?v=0rVey6AJmgA

PS: Deleting that default texture from the material texture slot also removes it. So it might not be exactly what you’re looking for.

4 Likes

All I wanted was add a debug map to a shader, turns out I have to manually add the damn texture to every material that uses it because setting the shader’s default map merely defines which texture a new material will use. Existing materials will use “none”.

This is terrible.

The best you can do is write a custom material editor which enforces a default. It’s unfortunate, because even all the types of textures you can have are not supported, so Unity will throw errors when “black” is assigned to a texture array, for instance, because it’s a Texture2D instead fo a Texture2DArray type.

Having a way to path to a default would be nice, but I personally think a syntax where you can do:

_DamageMap(“DamageMap”, 2DArray) = “(0,0,0,0)” {}

And basically it looks up in a table to see if a texture of value 0,0,0,0 has been created for that type, and if not creates it.

3 Likes

another possible way you can do it during testing, is to comment out the Property definition in the shader. Then write to a global shader property via code… this will replace the property in all materials at once that use that shader, at run-time.
see SetGlobalXXXX(). here… https://docs.unity3d.com/ScriptReference/Shader.html

If anybody is interested, even through the manual says that “black” is (0,0,0,1). I think in practice its actually defined as (0,0,0,0). Unity - Manual: ShaderLab: defining material properties. May be a bug, not sure.