What does UNITY_INITIALIZE_OUTPUT() do?

Hey there,

What does UNITY_INITIALIZE_OUTPUT() do? I need the exact source for it. Thanks. :smile:

-Steve

From HLSLSupport.cginc (found in [Unity Install Folder]/Data/CGIncludes) :

#if defined(UNITY_COMPILER_HLSL)
#define UNITY_INITIALIZE_OUTPUT(type,name) name = (type)0;
#else
#define UNITY_INITIALIZE_OUTPUT(type,name)
#endif

So, it does nothing unless the HLSL compiler is compiling.
In that case it sets its value to a typecasted zero. That way the compiler wonโ€™t complain about uninitialized output values.

4 Likes

Ah, thanks. :smile: Now I know, hopefully this will be useful to someone else too.

The general resource is the built-in shaders, which are available at the top of the forum. Since 4.1 or so, the CGIncludes are in there as well, so you donโ€™t have to fish them out of your Unity install.