pc.Scene.SkyBox Intensity memory issue

Hi, i am currently debugging my playCanvas application using Google chrome memory tools + the PlayCanvas Profiler. I found something quite strange : the Garbage collector allocates memory each time I am calling a function using pc.math.lerp or color.lerp but it never release it, increasing my VRAM buffer each time i’m calling the same function. If I disable the function below, I don’t have this problem.

1- Does pc.math.lerp or color.lerp allocates new memory when it’s used?
2- Is there a better solution for lerping colors and numbers ?
3- Am i simply using the function too much, which might be the cause of the issue.

Here is the function :

SkyShader.prototype.lerpSkyParameters = function(keys, alpha) {
    
   
    alpha = pc.math.clamp(alpha, 0.0, 1.0);
    
    this.hourParametersX = this.hourParameters[keys.x].script.scripts[0];
    this.hourParametersY = this.hourParameters[keys.y].script.scripts[0];
    this.commonParameters = this.commonShaderParameters.script.scripts[0];
    
    
    
    this.horizonColor.lerp(this.hourParametersX.horizonColor, this.hourParametersY.horizonColor, alpha);
    this.zenithColor.lerp(this.hourParametersX.zenithColor, this.hourParametersY.zenithColor, alpha);
    this.horizonPower = pc.math.lerp(this.hourParametersX.horizonPower, this.hourParametersY.horizonPower, alpha);
    this.postZenithColor.lerp(this.hourParametersX.postZenithColor, this.hourParametersY.postZenithColor, alpha);
    this.postHorizonPower = pc.math.lerp(this.hourParametersX.postHorizonPower, this.hourParametersY.postHorizonPower, alpha);
    this.backlitColor.lerp(this.hourParametersX.backlitColor, this.hourParametersY.backlitColor, alpha);
    this.backlitPower = pc.math.lerp(this.hourParametersX.backlitPower, this.hourParametersY.backlitPower, alpha);
    this.litColor.lerp(this.hourParametersX.litColor, this.hourParametersY.litColor, alpha);
    this.litPower = pc.math.lerp(this.hourParametersX.litPower, this.hourParametersY.litPower, alpha);
    this.fogColor.lerp(this.hourParametersX.fogColor, this.hourParametersY.fogColor, alpha);
    this.sunFogColor.lerp(this.hourParametersX.sunFogColor, this.hourParametersY.sunFogColor, alpha);
    this.sunFogPower = pc.math.lerp(this.hourParametersX.sunFogPower, this.hourParametersY.sunFogPower, alpha);
    this.fogStart = pc.math.lerp(this.hourParametersX.fogStart, this.hourParametersY.fogStart, alpha);
    this.fogEnd = pc.math.lerp(this.hourParametersX.fogEnd, this.hourParametersY.fogEnd, alpha);
    this.fogPower = pc.math.lerp(this.hourParametersX.fogPower, this.hourParametersY.fogPower, alpha);
    this.cloudColor.lerp(this.hourParametersX.cloudColor, this.hourParametersY.cloudColor, alpha);
    this.cloudStart = pc.math.lerp(this.hourParametersX.cloudStart, this.hourParametersY.cloudStart, alpha);
    this.cloudEnd = pc.math.lerp(this.hourParametersX.cloudEnd, this.hourParametersY.cloudEnd, alpha);
    this.sunRadius = pc.math.lerp(this.hourParametersX.sunRadius, this.hourParametersY.sunRadius, alpha);
    this.sunGlow = pc.math.lerp(this.hourParametersX.sunGlow, this.hourParametersY.sunGlow, alpha);
    this.sunColor.lerp(this.hourParametersX.sunColor, this.hourParametersY.sunColor, alpha);
    this.sunHaloColor.lerp(this.hourParametersX.sunHaloColor, this.hourParametersY.sunHaloColor, alpha);
    this.sunHaloPower = pc.math.lerp(this.hourParametersX.sunHaloPower, this.hourParametersY.sunHaloPower, alpha);
    this.cloudLightColor.lerp(this.hourParametersX.cloudLightColor, this.hourParametersY.cloudLightColor, alpha);
    this.cloudTopColor.lerp(this.hourParametersX.cloudTopColor, this.hourParametersY.cloudTopColor, alpha);
    this.cloudTopBacklitColor.lerp(this.hourParametersX.cloudTopBacklitColor, this.hourParametersY.cloudTopBacklitColor, alpha);
    this.cloudTopColorScale = pc.math.lerp(this.hourParametersX.cloudTopColorScale, this.hourParametersY.cloudTopColorScale, alpha);
    this.cloudSoftness = pc.math.lerp(this.hourParametersX.cloudSoftness, this.hourParametersY.cloudSoftness, alpha);
    this.cloudBacklitSoftness = pc.math.lerp(this.hourParametersX.cloudBacklitSoftness, this.hourParametersY.cloudBacklitSoftness, alpha);
    this.cloudScattering = pc.math.lerp(this.hourParametersX.cloudScattering, this.hourParametersY.cloudScattering, alpha);

    this.light.light.color.lerp(this.hourParametersX.sunlightColor, this.hourParametersY.sunlightColor, alpha);
    this.light.light.intensity = pc.math.lerp(this.hourParametersX.sunlightIntensity, this.hourParametersY.sunlightIntensity, alpha);
    this.app.scene.skyboxIntensity = pc.math.lerp(this.hourParametersX.skyboxIntensity, this.hourParametersY.skyboxIntensity, alpha);
    this.app.scene.fogColor.lerp(this.hourParametersX.fogColor, this.hourParametersY.fogColor, alpha);
    if (this.bloomEffect) {
        this.bloomEffect.intensity = pc.math.lerp(this.hourParametersX.bloomIntensity, this.hourParametersY.bloomIntensity, alpha);
    }
    
   
    this.commonParameters.horizonShadowMinHeight = pc.math.lerp(this.hourParametersX.horizonShadowMinHeight, this.hourParametersY.horizonShadowMinHeight, alpha);
    this.commonParameters.horizonShadowMaxHeight = pc.math.lerp(this.hourParametersX.horizonShadowMaxHeight, this.hourParametersY.horizonShadowMaxHeight, alpha);
    this.commonParameters.horizonShadowScale = pc.math.lerp(this.hourParametersX.horizonShadowScale, this.hourParametersY.horizonShadowScale, alpha);
    this.commonParameters.fogHaloColor.lerp(this.hourParametersX.fogHaloColor, this.hourParametersY.fogHaloColor, alpha);
    
    alpha = null;
    
   
};

Thank you,
Tristan

Lerp shouldn’t do any allocation. Especially in VRAM. https://github.com/playcanvas/engine/blob/f2a8c26cdec181f454598685c175c680bbe2f055/src/math/vec3.js#L221

Can you provide a small project that shows this issue please?

Hello, I have nailed down the issue to one line of code : this.app.scene.skyboxIntensity = pc.math.lerp(this.hourParametersX.skyboxIntensity, this.hourParametersY.skyboxIntensity, alpha);

This line is causing me the VRAM memory leak over time. if I disable this line or even use a fixed value (1 for instance), I believe because this is a function and not an actual attribute. I might be wrong

This is the code causing the VRAM Memory to increase over time

image

Issue logged here if you want to track it:

Nice ! Thank you for the quick response, If fixed, it will help our project a lot