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 from vert to main, and a new macro gl_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 function CC_STANDARD_SURFACE_ENTRY() to replace the original v3.0 shader output function frag().

      1. CCProgram standard-fs %{
      2. // Include your headfile
      3. // Fill in your data here
      4. void surf (out StandardSurface s) {
      5. // Fill in your data here
      6. }
      7. CC_STANDARD_SURFACE_ENTRY() // Standard shader output function
      8. }%

    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.

    1. #define CC_STANDARD_SURFACE_ENTRY()
    2. #if CC_FORWARD_ADD
    3. // Fill in your data here
    4. #elif CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_FORWARD // Determine if it is the forward render pipeline
    5. // Fill in your data here
    6. #elif CC_PIPELINE_TYPE == CC_PIPELINE_TYPE_DEFERRED // Determine if it is the deferred render pipeline
    7. // Fill in your data here
    8. #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

      1. CC_TRANSFER_FOG(pos);