Shader Chunk Migrations
Introduction
The PlayCanvas Engine's material shader chunk system is undergoing substantial changes in order to support a more flexible material system. Please see this page for more context.
In order to help users migrate their existing custom shader chunks, this page lists the changes made to chunks and organizes them by engine release (starting v1.51).
Chunk API Versions
The debug version of the Engine will report any API changes to the runtime console when it detects overridden chunks. For example:
Once an application's chunks have been updated to the latest API they must be flagged as such. For example, after updating a material's custom chunks to the latest engine release (say v1.55), specify this in the chunks object as follows:
material.chunks.diffusePS = '...';
material.chunks.APIVersion = pc.CHUNKAPI_1_55;
By doing this you will no longer see warning messages in the console.
Chunk changes
The following tables break down the chunk changes by Engine release.
Engine v1.60
Chunk | Changes |
---|---|
clearCoatGlossPS |
|
glossPS |
|
sheenGlossPS |
|
Engine v1.57
In 1.57, almost all front-end chunks have been changed to minimize the amount of samplers used by the shader. This is an optional feature, however it's recommended to follow the same coding style to reduce the amount of samplers used by the shader. The following chunks are affected by it:
Chunk |
---|
aoPS |
clearCoatPS |
clearCoatGlossPS |
clearCoatNormalPS |
diffusePS |
diffuseDetailMapPS |
emissivePS |
metalnessPS |
normalMapPS |
normalDetailMapPS |
opacityPS |
parallaxPS |
sheenPS |
sheenGlossPS |
specularPS |
specularityFactorPS |
thicknessPS |
transmissionPS |
This is also supported in custom front-end chunks, given that your chunk piggybacks on the pre-existing material samplers. To support this method in your chunks, what you'd need to do is:
- Remove the sampler uniform declaration from the chunk
- Replace the sampler name with the
$SAMPLER
macro
For example:
uniform sampler2D texture_aoMap;
void getAO() {
dAo = 1.0;
#ifdef MAPTEXTURE
dAo *= texture2DBias(texture_aoMap, $UV, textureBias).$CH;
#endif
#ifdef MAPVERTEX
dAo *= saturate(vVertexColor.$VC);
#endif
}
Would be converted to:
void getAO() {
dAo = 1.0;
#ifdef MAPTEXTURE
dAo *= texture2DBias($SAMPLER, $UV, textureBias).$CH;
#endif
#ifdef MAPVERTEX
dAo *= saturate(vVertexColor.$VC);
#endif
}
This allows the engine to automatically pick the sampler uniform to use, thus potentially reducing the total number of samplers. But note, this is only supported for front-end chunks.
Engine v1.56
Chunk | Changes |
---|---|
combineXXXX |
|
refractionPS |
|
refractionCubePS |
|
refractionDynamicPS |
|
sheenPS |
|
sheenGlossPS |
|
reflectionEnvHQPS |
|
thicknessPS |
|
bakeDirLmEndPs |
|
bakeLmEndPS |
|
Engine v1.55
Chunk | Changes |
---|---|
clearCoatNormalPS |
|
clusteredLightPS |
|
combinePS |
|
combineXXXX |
|
diffusePS |
|
diffuseDetailMapPS |
|
endPS |
|
emissivePS |
|
fresnelSchlickPS |
|
lightmapSingleVert.js |
|
lightmapDirPS , lightmapSinglePS |
|
lightmapAddPS , lightmapDirAddPS |
|
lightSpecularAnisoGGXPS |
|
lightSpecularBlinnPS , lightSpecularPhongPS |
|
ltcPS |
|
normalMapFastPS |
|
normalMapPS |
|
normalDetailMapPS |
|
normalVertexPS |
|
metalnessPS |
|
metalnessModulatePS |
|
reflectionCC |
|
specularAaNonePS , specularAaToksvigPS , specularAaToksvigFastPS |
|
startPS |
|
specularPS |
|
specularityFactorPS |
|