Error trying to update emissive shader chunk to new API

My custom shader is suddenly broken so I’m trying to update it to the new API per the documentation here: Shader Chunk Migrations | Learn PlayCanvas

Here is the shader code:

uniform float uOffset;

uniform vec3 material_emissive;

uniform float material_emissiveIntensity;

uniform sampler2D texture_emissiveMap;

vec3 getEmission() {
    dEmission = vec3(1.0);

    #ifdef MAPFLOAT
    dEmission *= material_emissiveIntensity;

    #ifdef MAPCOLOR
    dEmission *= material_emissive;

    #ifdef MAPTEXTURE
    dEmission *= $DECODE(texture2D(texture_emissiveMap, $UV + vec2(uOffset, 0.0), textureBias)).$CH;

    #ifdef MAPVERTEX
    dEmission *= gammaCorrectInput(saturate(vVertexColor.$VC));

This is the same code as listed in the chunk (here) except that I have a parameterised offset on the texture.
I have also added this second line to the code to flag that it is using the current API:

currentMaterial.chunks.emissivePS ='AnalyserScreenPS', 'shader').resource;
currentMaterial.chunks.APIVersion = pc.CHUNKAPI_1_55;

However, when I run I get the following errors in the console:

Shader chunk 'emissivePS' is API version 1.55, but the supplied chunk is version -. Please update to the latest API.
Failed to compile fragment shader:
ERROR: 0:283: 'getEmission' : function does not return a value:

What is happening here? Surely in the new API the expectation is the that getEmission modifies a global and does not return a value?

Hi @steve_wk ,

Is this an issue in published builds only? We have just noticed that published builds are using engine 1.54 instead of 1.55 and are busy investigating.


This is just in the editor actually, haven’t tried building this yet

Code actually works fine as long as I add this line to the end of the shader:

return dEmission;

But the help file (and code in GitHub) suggest that shouldn’t be necessary.

Your code sets a return type for the GLSL function as vec3, so it expects you to return a vec3. You should use void, if it does not need to return anything.

vec3 getEmission() {...}

Oooohhhhh facepalm
I just copied the content of the function from the latest code, totally forgot about that. Thanks!

1 Like