Vertex Shader Input

Parameters

The input values for the Vertex Shader are all in the SurfacesStandardVertexIntermediate structure and are passed in as function parameters.

Vertex Shader Input ValuesTypeNeeded MacrosMeaning
positionvec4N/ALocal position
normalvec3N/ALocal normal
tangentvec4CC_SURFACES_USE_TANGENT_SPACELocal tangent and mirror normal flag
colorvec4CC_SURFACES_USE_VERTEX_COLORVertex color
texCoordvec2N/AUV0
texCoord1vec2CC_SURFACES_USE_SECOND_UVUV1
clipPosvec4N/AProjected coordinates
worldPosvec3N/AWorld position
worldNormalvec4N/AWorld normal and double-sided material flag
worldTangentvec3CC_SURFACES_USE_TANGENT_SPACEWorld tangent
worldBinormalvec3CC_SURFACES_USE_TANGENT_SPACEWorld binormal

Macro Switch

When you need to use input parameters with a macro switch, you need to enable the corresponding macro in the macro-remapping code segment. The example code is as follows.

  1. CCProgram macro-remapping %{
  2. ...
  3. //Use the second set of UVs
  4. #define CC_SURFACES_USE_SECOND_UV 1
  5. //Use the world's binormal
  6. #define CC_SURFACES_USE_TANGENT_SPACE 1
  7. ...
  8. }

Usage Example

In any function with SurfacesStandardVertexIntermediate parameters, you can directly access the relevant parameters, taking the SurfacesVertexModifyWorldPos function as an example.

  1. #define CC_SURFACES_VERTEX_MODIFY_WORLD_POS
  2. vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In)
  3. {
  4. vec3 worldPos = In.worldPos;
  5. worldPos.x += sin(cc_time.x * worldPos.z);
  6. worldPos.y += cos(cc_time.x * worldPos.z);
  7. return worldPos;
  8. }