Optional Pass Parameters

The parameters in Pass are mainly divided into two parts: the developer-defined effect parameter and the PipelineStates parameter provided by the engine, this document mainly introduces the parameters related to PipelineStates, all the parameters are case-insensitive.

Parameter nameDescriptionDefault valueRemark
switchSpecifies a power switch for the current pass. Could be any valid macro name that’s not defined in the shader, the macro name shouldn’t collide with any existing macros inside the shaderundefinedThis property doesn’t exist by default, which means the pass is executed unconditionally
prioritySpecifies the rendering priority of the current pass, the bigger the number, the lower the priority128Could be any number between max(255) and min(0)
stageSpecifies which render stage the current pass belongs to. Could be the name of any registered stage in your runtime pipelinedefaultFor the built-in forward pipeline, the only available stage is default
phaseSpecifies which phase the current pass belongs to. Could be the name of any registered phase in your runtime pipelinedefaultFor the built-in forward pipeline, the available phases are default, forward-add and shadow-caster
propertyIndexSpecifies the index of the pass to copy runtime property data from. When two passes need to share the same set of properties, propertyIndex can be specified to avoid the need for developers to specify that same set of data multiple times (especially in the material inspector). This could be useful in some cases, e.g.: the forward add pass vs. the base passundefinedCould be any valid pass index. Once specified, all the properties for the current pass will not be visible in the material inspector
embeddedMacrosSpecifies additional macro definitions on top of the current shader, could be an object containing any macro key-value pair*undefinedThis parameter can be used to multiplex shader resources in multiple passes only if the macros are defined differently.
propertiesSpecifies the public interfaces exposed to material inspector and runtime APISee the Properties section below for details
migrationsMigrate old material dataSee the Migrations section below for details
primitiveCreate material vertex datatriangle_listOptions include: point_list, line_list, line_strip, line_loop,
triangle_list, triangle_strip, triangle_fan,
line_list_adjacency, line_strip_adjacency,
triangle_list_adjacency, triangle_strip_adjacency,
triangle_patch_adjacency, quad_patch_list, iso_line_list
dynamics补充说明[]An array containing any of the following:
viewport, scissor, line_width, depth_bias, blend_constants,
depth_bounds, stencil_write_mask, stencil_compare_mask
RasterizerState补充说明See the RasterizerState section below for details
DepthStencilState补充说明See the DepthStencilState section below for details
BlendStateMixed state of the materialfalseSee the BlendState section below for details

Properties

Specifies the public interfaces exposed to material inspector and runtime API.
It can be a direct mapping to shader uniforms, or specific channels of the uniform:

  1. albedo: { value: [1, 1, 1, 1] } # uniform vec4 albedo
  2. roughness: { value: 0.8, target: pbrParams.g } # uniform vec4 pbrParams
  3. offset: { value: [0, 0], target: tilingOffset.zw } # uniform vec4 tilingOffset
  4. # say there is another uniform, vec4 emissive, that doesn't appear here
  5. # so it will be assigned a default value of [0, 0, 0, 0] and will not appear in the inspector

Runtime reference is straightforward:

  1. // as long as it is a real uniform
  2. // it doesn't matter whether it is specified in the property list or not
  3. mat.setProperty('emissive', Color.GREY); // this works
  4. mat.setProperty('albedo', Color.RED); // directly set uniform
  5. mat.setProperty('roughness', 0.2); // set certain component
  6. const h = mat.passes[0].getHandle('offset'); // or just take the handle,
  7. mat.passes[0].setUniform(h, new Vec2(0.5, 0.5)); // and use Pass.setUniform interface instead

Shader uniforms that are not in the properties list will be given a default value.

For quick setup and experiment, the __metadata__ feature is provided, which will be the ‘base class’ for all other properties:

  1. properties:
  2. __metadata__: { editor: { visible: false } }
  3. a: { value: [1, 1, 0, 0] }
  4. b: { editor: { type: color } }
  5. c: { editor: { visible: true } }

Here a and b will no longer appear in the inspector, while c stays visible.

Property Parameter List

The configurable parameters in Property are shown in the table below, and any configurable field can be omitted if it is the same as the default value.

Parameter nameDefault valueOptionsRemark
targetundefinedundefinedAny valid uniform components, no random swizzle
valueSee the Default Values section below for details
sampler.
minFilter
linearnone, point, linear, anisotropic
sampler.
magFilter
linearnone, point, linear, anisotropic
sampler.
mipFilter
nonenone, point, linear, anisotropic
sampler.
addressU
wrapwrap, mirror, clamp, border
sampler.
addressV
wrapwrap, mirror, clamp, border
sampler.
addressW
wrapwrap, mirror, clamp, border
sampler.
maxAnisotropy
1616
sampler.
cmpFunc
nevernever, less, equal, less_equal, greater, not_equal, greater_equal, always
sampler.
borderColor
[0, 0, 0, 0][0, 0, 0, 0]
sampler.
minLOD
00
sampler.
maxLOD
00Remember to override this when enabling mip filter
sampler.
mipLODBias
0
editor.
displayName
property nameproperty nameAny string
editor.
type
vectorvector, color
editor.
visible
truetrue, false
editor.
tooltip
property nameproperty nameAny string
editor.
range
undefinedundefined, [ min, max, [step] ]
editor.
deprecated
falsetrue, falseFor any material using this effect, delete the existing data for this property after next saving

Migrations

Ideally the public interface of an effect should always be backward-compatible, but occasionally introducing breaking changes might become the only option as the project iterate. A smooth data transition would be much desired during the process, which leads to the migration system.

After an effect with migrations is successfully compiled, all the dependent material assets will be immediately updated, new property will be automatically migrated/generated from existing data using specified rules.

Note: please remember to backup your project before doing any migration attemps!

For a existing effect, declares the following migration rules:

  1. migrations:
  2. # macros: # macros follows the same rule as properties, without the component-wise features
  3. # USE_MIAN_TEXTURE: { formerlySerializedAs: USE_MAIN_TEXTURE }
  4. properties:
  5. newFloat: { formerlySerializedAs: oldVec4.w }

Say we have a dependent material, with the following data:

  1. {
  2. "oldVec4": {
  3. "__type__": "cc.Vec4",
  4. "x": 1,
  5. "y": 1,
  6. "z": 1,
  7. "w": 0.5
  8. }
  9. }

After the effect is compiled, the material will be automatically updated to:

  1. {
  2. "oldVec4": {
  3. "__type__": "cc.Vec4",
  4. "x": 1,
  5. "y": 1,
  6. "z": 1,
  7. "w": 0.5
  8. },
  9. "newFloat": 0.5
  10. }

And after the next save operation on this material: (say the content is actually not changed)

  1. {
  2. "newFloat": 0.5
  3. }

We are just using the w channel here, while in fact arbitrary shuffle is supported too:

  1. newColor: { formerlySerializedAs: someOldColor.yxx }

Or even based on a target macro:

  1. occlusion: { formerlySerializedAs: pbrParams.<OCCLUSION_CHANNEL|z> }

This means the new occlusion data will be extracted from pbrParams data, the specific channel depend on the OCCLUSION_CHANNEL macro of current pass, and default to channel z if macro data not present.
If newFloat property already exists before migration, nothing will happen, unless in force mode:

  1. newFloat: { formerlySerializedAs: oldVec4.w! }

Then the migration is guaranteed to execute, regardless of the existing data.

Note: migration in force mode will execute in every database event, which is basically every mouse click in editor. So use it as a quick-and-dirty test measure, and be sure not to submit effect files with force mode migrations into version control.

Again here are the bottomline rules about preventing potential data losses:

  • Property removal will happen if, and only if, you specify the removeImmediately entry explicitly.
  • Property override will happen if, and only if, you end the formerlySerializedAs entry with ! (force mode)

RasterizerState

Parameter nameDescriptionDefault valueOptions
cullMode补充说明backfront, back, none

DepthStencilState

Parameter nameDescriptionDefault valueOptions
depthTest补充说明truetrue, false
depthWrite补充说明truetrue, false
depthFunc补充说明lessnever, less, equal, less_equal, greater, not_equal, greater_equal, always
stencilTest补充说明falsetrue, false
stencilFunc补充说明alwaysnever, less, equal, less_equal, greater, not_equal, greater_equal, always
stencilReadMask补充说明0xffffffff0xffffffff, [1, 1, 1, 1]
stencilWriteMask补充说明0xffffffff0xffffffff, [1, 1, 1, 1]
stencilFailOp补充说明keepkeep, zero, replace, incr, incr_wrap, decr, decr_wrap, invert
stencilZFailOp补充说明keepkeep, zero, replace, incr, incr_wrap, decr, decr_wrap, invert
stencilPassOp补充说明keepkeep, zero, replace, incr, incr_wrap, decr, decr_wrap, invert
stencilRef补充说明11, [0, 0, 0, 1]
stencilFront/Back补充说明set above stencil properties for specific side

BlendState

Parameter nameDescriptionDefault valueOptions
BlendColor补充说明00, [0, 0, 0, 0]
Targets补充说明falsefalsetrue, false
targets[i].
blend
补充说明falsetrue, false
targets[i].
blendEq
补充说明addadd, sub, rev_sub
targets[i].
blendSrc
补充说明oneone, zero, src_alpha_saturate,
src_alpha, one_minus_src_alpha,
dst_alpha, one_minus_dst_alpha,
src_color, one_minus_src_color,
dst_color, one_minus_dst_color,
constant_color, one_minus_constant_color,
constant_alpha, one_minus_constant_alpha
targets[i].
blendDst
补充说明zeroone, zero, src_alpha_saturate,
src_alpha, one_minus_src_alpha,
dst_alpha, one_minus_dst_alpha,
src_color, one_minus_src_color,
dst_color, one_minus_dst_color,
constant_color, one_minus_constant_color,
constant_alpha, one_minus_constant_alpha
targets[i].
blendSrcAlpha
补充说明oneone, zero, src_alpha_saturate,
src_alpha, one_minus_src_alpha,
dst_alpha, one_minus_dst_alpha,
src_color, one_minus_src_color,
dst_color, one_minus_dst_color,
constant_color, one_minus_constant_color,
constant_alpha, one_minus_constant_alpha
targets[i].
blendDstAlpha
补充说明zeroone, zero, src_alpha_saturate,
src_alpha, one_minus_src_alpha,
dst_alpha, one_minus_dst_alpha,
src_color, one_minus_src_color,
dst_color, one_minus_dst_color,
constant_color, one_minus_constant_color,
constant_alpha, one_minus_constant_alpha
targets[i].
blendAlphaEq
补充说明addadd, sub, rev_sub
targets[i].
blendColorMask
补充说明allall, none, r, g, b, a, rg, rb, ra, gb, ga, ba, rgb, rga, rba, gba

Default Values

TypeDefault ValueOptions
int0
ivec2[0, 0]
ivec3[0, 0, 0]
ivec4[0, 0, 0, 0]
float0
vec2[0, 0]
vec3[0, 0, 0]
vec4[0, 0, 0, 0]
sampler2Ddefaultblack, grey, white, normal, default
samplerCubedefault-cubeblack-cube, white-cube, default-cube

For defines:

  • The default value for the boolean type is false.
  • The default value for the number type is 0, and the value range is [0, 3].
  • The default value for the string type is the first element of the options array.