Hi, I have recently decided to finally update my project to the newer playcanvas version, 2.7.4 (used 1.77 before) and I got problems with shader chunks, varyings specifically. It looks like the it no longer recognises the varyings as before.
...
material.chunks.startVS = `
uniform float uInstanceCount;
varying float vHeight;
void main(void) {
gl_Position = getPosition();
vHeight = float(gl_InstanceID) / uInstanceCount;
`;
material.chunks.diffusePS = `
uniform vec3 material_diffuse;
varying float vHeight;
void getAlbedo() {
dAlbedo = material_diffuse + vec3(
cnoise(vPositionW + vHeight * 4.0 + uTime) * 1.0,
cnoise(vPositionW + vHeight * 16.0 + uTime) * 1.0,
cnoise(vPositionW + vHeight * 64.0 + uTime) * 1.0
);
}
And I get the error
Failed to link shader program. Error: FRAGMENT varying vHeight does not match any VERTEX varying
I could not find any info about that in v2 release notes unfortunately.
Hi! In version 2 startVS was removed.
Use litMainVS chunk
1 Like
try running it using a debug engine, it should log some issues in the console log of the browser.
1 Like
Ok, I looked at github, and see very comfortable new chunks there: varyingsVS , varyingsPS , and litUserMainEndVS
it does not work in real life
material.chunks.varyingsVS = `
varying float vHeight;
`;
material.chunks.varyingsPS = `
varying float vHeight;
`;
material.chunks.litUserMainEndVS = `
vHeight = float(gl_InstanceID) / uInstanceCount;
`
Shader chunk 'litUserMainEndVS' is not supported.
Shader chunk 'varyingsPS' is not supported.
Shader chunk 'varyingsVS' is not supported.
I run the game in “Force V2” mode
(You are currently using engine version: 2.7.4)
I assume those are dev and not in production yet?
Yes, at the moment chunks are changing a lot, this made me stop supporting early versions 2.
See release-2.7
1 Like
Dmytro_Khudiiash:
varyingsVS
as the comment says:
// empty chunk, supplied by the shader generator
those are generated by the shader generator. Not something you can override.
I added these new chunks for each way to customize shaders:
playcanvas:main
← playcanvas:mv-lit-user-chunks
opened 12:01PM - 30 Apr 25 UTC
- removed private and non-functional `StandardMaterial.customFragmentShader`
- … added custom empty chunks allowing vertex and fragment shader of `StandardMaterial` and `LitMaterial` to be customized:
```
litUserDeclarationPS: '', // empty chunk allowing user to add custom code
litUserDeclarationVS: '', // empty chunk allowing user to add custom code
litUserCodePS: '', // empty chunk allowing user to add custom code
litUserCodeVS: '', // empty chunk allowing user to add custom code
litUserMainStartPS: '', // empty chunk allowing user to add custom code
litUserMainStartVS: '', // empty chunk allowing user to add custom code
litUserMainEndPS: '', // empty chunk allowing user to add custom code
litUserMainEndVS: '', // empty chunk allowing user to add custom code
```
These are included into existing shader chunks, either at the very start of the shader, just before the main function, and also at the start and end of the main function, which should cover most common places to inject code (apart from replacing existing chunks)
- also created new chunk `litMainPS` (similar to existing `litMainVS`) which is the single entry point to fragment shader for all passes, removing any hardcoded parts. As long as the user knows this is the entry point, they can follow the rest of the shader from there:
<img width="395" alt="Screenshot 2025-04-30 at 13 05 49" src="https://github.com/user-attachments/assets/57de8181-b893-4035-88de-d657f6fa376b" />
But this is not out yet, and will be released with the next engine release (2.8).
In the meantime, you need to find other chunks to override / add to.
1 Like