[SOLVED] Character damage demo broken in Engine v1.55

Certain shader demos such as the Character Damage Demo no longer work under the new version.

Could it be explained how to fix the shaders in this demo? It might help me and some others transition our projects over to the new version.

Thank you for your time!

Hi @devinhell,

I’d start by checking this migration guide:

https://developer.playcanvas.com/en/user-manual/graphics/shader-chunk-migrations/

And then I’d follow the errors thrown on launch window and take it from there. For example this error:

ERROR: 0:717: 'getMetalness' : no matching overloaded function found

Points to the metalnessPS shader chunk which has changes (e.g. processMetalness() method has been removed). You should start by comparing prev/current chunk versions to see what needs to be changed. Github commit history is super helpful on that:

Thank you for your reply! It was very helpful!
I resolved a few of the errors by comparing the prev/current chunk versions until this function:

ERROR: 0:750: 'mix' : no matching overloaded function found

where might I find how this function has been changed or what function to use instead?

Thanks again for your time

Mix function is a built in function of the shader, and has not been changed.
What is likely the problem are the parameters to it … the function can mix for example vec3 and vec3, but not vec3 and vec4. Please check your parameters are matching.

1 Like

I uploaded the fixed demo to my user page for everyone to check out: https://playcanvas.com/project/967840/overview/character-damage-demoshaderfix

I think it’s important to keep these demos working as the engine updates. If they no longer work after each update it might cause some confusion and push some devs away.

Here is the change log:
@Leonidas thanks for your help here!

DamageMetalnessPS - file
simply changed the name of the “void getSpecularity()”
function to “void getMetalness()”

DamageFresnelSchlickPS - file
changed this:

void getFresnel() {
    applyDamage2();
    
    float fresnel = 1.0 - max(dot(dNormalW, dViewDirW), 0.0);
    float fresnel2 = fresnel * fresnel;
    fresnel *= fresnel2 * fresnel2;
    fresnel *= dGlossiness * dGlossiness;
    dSpecularity = dSpecularity + (1.0 - dSpecularity) * fresnel;
    #ifdef CLEARCOAT
        fresnel = 1.0 - max(dot(ccNormalW, dViewDirW), 0.0);
        fresnel2 = fresnel * fresnel;
        fresnel *= fresnel2 * fresnel2;
        fresnel *= ccGlossiness * ccGlossiness;
        ccSpecularity = ccSpecularity + (1.0 - ccSpecularity) * fresnel;
    #endif

   }

to this

vec3 getFresnel(float cosTheta, vec3 f0) {
        applyDamage2();

    float fresnel = 1.0 - max(dot(dNormalW, dViewDirW), 0.0);
    float fresnel2 = fresnel * fresnel;
    fresnel *= fresnel2 * fresnel2;
    fresnel *= dGlossiness * dGlossiness;
    dSpecularity = dSpecularity + (1.0 - dSpecularity) * fresnel;
    #ifdef CLEARCOAT
        fresnel = 1.0 - max(dot(ccNormalW, dViewDirW), 0.0);
        fresnel2 = fresnel * fresnel;
        fresnel *= fresnel2 * fresnel2;
        fresnel *= ccGlossiness * ccGlossiness;
        ccSpecularity = ccSpecularity + (1.0 - ccSpecularity) * fresnel;
    #endif

    float glossSq = dGlossiness * dGlossiness;
    return f0 + (max(vec3(glossSq), f0) - f0) * fresnel;
}

@mvaligursky Thanks for the tip. I realized the “getEmission()” function needed to be changed to “dEmission”.

DamageEndPS - file
simply changed “getEmission()” to “dEmission”

2 Likes

I’ve updated the shaders to work with the recent engine release. I removed some shader chunks, as they no longer need to be overriden, like TBN term, and moved uniforms to the base chunk so they are available during shader backend calculation.

https://playcanvas.com/project/1103264/overview/character-damage

3 Likes

Amazing you doing this @LeXXik ! Thanks!

1 Like