Shader chunks varyings not working in v2

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

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:

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