Macro Remapping

During internal calculations, Surface Shader will use some macro switches, which start with CC_SURFACES_.

Note: Macros start with the CC_SURFACES_ won’t appear on the material inspector panel.

The complete macro list is as follows.

Macro NamTypeMeaning
CC_SURFACES_USE_VERTEX_COLORBOOLUse vertex color
CC_SURFACES_USE_SECOND_UVBOOLUse second uv
CC_SURFACES_USE_TWO_SIDEDBOOLUse two-side normal for two-side lighting
CC_SURFACES_USE_TANGENT_SPACEBOOLUse tangent space - must be enabled when using normal map or anisotropy )
CC_SURFACES_TRANSFER_LOCAL_POSBOOLAccess model space position in FS
CC_SURFACES_LIGHTING_ANISOTROPICBOOLEnable anisotropic material
CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNTUINTSample count of anisotropic convolution, 0 means convolution is disabled, only valid when anisotropy is enabled
CC_SURFACES_LIGHTING_USE_FRESNELBOOLCalculate Fresnel coefficient through relative refractive index ior
CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSEBOOLEnable backside penetration diffuse (used for hair, leaves, ears, etc)
CC_SURFACES_LIGHTING_TRANSMIT_SPECULARBOOLEnable light specular (used for water surface, glass, etc.)
CC_SURFACES_LIGHTING_TRTBOOLEnable light reflected from the interior after transmission(used for hair)
CC_SURFACES_LIGHTING_TTBOOLEnable light diffused from the interior after transmission(used for hair)
CC_SURFACES_USE_REFLECTION_DENOISEBOOLEnable environmental reflection denoising, only valid under legacy compatibility mode
CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTINGBOOLEnable legacy compatible lighting mode, the rendering effect can be completely consistent with legacy/standard.effect, convenient for upgrade

Note: If these macros are not defined, the system will automatically define them as the default value 0.

Search for the CCProgram macro-remapping section, and you can see that the content consists of three parts.

macro-remapping

Display Macros on Panel

  1. // ui displayed macros not used in this effect file
  2. #pragma define-meta HAS_SECOND_UV
  3. #pragma define-meta USE_TWOSIDE
  4. #pragma define-meta USE_REFLECTION_DENOISE
  5. #pragma define-meta USE_COMPATIBLE_LIGHTING

By default, macros starting with CC_ will not be displayed on the material panel. When we want a macro to be displayed on the material panel, we can do the following.

  1. Use #pragma define-meta to define a panel macro, we take HAS_SECOND_UV as an example.
  1. #pragma define-meta HAS_SECOND_UV
  1. Remap the macro starting with CC_SURFACES_ to this macro, for example.
  1. #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV

In this way, on the material panel corresponding to this shader, you can control the value of the CC_SURFACES_USE_SECOND_UV macro by controlling HAS_SECOND_UV.

Macros Used in Surface Functions

If a macro is used in the shader code and does not start with CC_, it will automatically be displayed on the material panel. For example.

  1. // ui displayed macros used in this effect file
  2. #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
  3. #if IS_ANISOTROPY || USE_NORMAL_MAP
  4. #define CC_SURFACES_USE_TANGENT_SPACE 1
  5. #endif

In this case, IS_ANISOTROPY and USE_NORMAL_MAP will be displayed on the material panel, and can be switched on and off through the material panel.

Internal Functionality Macros

For some macros, we don’t want to control it on the panel, just define its value directly, for example.

  1. // functionality for each effect
  2. #define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 31

Hidden Macros

If you have written some macros in your shader but don’t want them to appear on the material panel, you can start them with CC_.

To differentiate from the internal system macros, user-defined internal macros are recommended to start with CC_USER_.

For more details about macros, please see Macros