Cocos Creator 3.1 Material Upgrade Guide
The standard shader header from v3.0 has become standard-surface-entry
from v3.1, making the effect compatible with both the forward render pipeline and the deferred render pipeline.
The cc-fog
header file from v3.0 is now cc-fog-vs/fs
from v3.1, split into vertex shader and fragment shader versions.
gl_Position
The main function name of
VS
in v3.1 has been changed fromvert
tomain
, and a new macrogl_Position
has been added to assign a value to the return value.
-
Load the standard shader header file
standard-surface-entry
and use the v3.1 standard shader output functionCC_STANDARD_SURFACE_ENTRY()
to replace the original v3.0 shader output functionfrag()
.CCProgram standard-fs %{
// Include your headfile
// Fill in your data here
void surf (out StandardSurface s) {
// Fill in your data here
}
CC_STANDARD_SURFACE_ENTRY() // Standard shader output function
}%
The biggest difference between v3.1 and v3.0 is that v3.1 supports the deferred render pipeline. The engine comes with a standard standard-surface-entry
header file that supports both the forward render pipeline and the deferred render pipeline, which is used as follows:
The header file standard-surface-entry
determines which render pipeline is selected, and the lighting calculation is in the file shading-standard-additive
.
If it is a deferred render pipeline, the deferred-lighting
effect file is called first, followed by the light calculation file shading-standard-additive
.
#define CC_STANDARD_SURFACE_ENTRY()
#if CC_FORWARD_ADD
// Fill in your data here
#elif CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD // Determine if it is the forward render pipeline
// Fill in your data here
#elif CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED // Determine if it is the deferred render pipeline
// Fill in your data here
#endif
The v3.1 vertex shader transfers FOG
parameters to the fragment shader, using the CC_TRANSFER_FOG
macro directly.
Version comparison:
v3.0
v3.1
CC_TRANSFER_FOG(pos);