[SOLVED] StandardMaterial.getUniform() error


Recently I forked a project of my own that was running in a previuos version of the engine, and now I am getting the error “_uniforms[name] is not a function” when I call the StandardMaterial.getUniform() method

let mat = this.entity.model.meshInstances[0].material;
this.override = mat.getUniform("normalMapOffset", this._offset);

Then the error points me to the engine code:

_proto.getUniform = function getUniform(name, device, scene) {
			return _uniforms[name](this, device, scene);

So I compared it to a previous version of the engine:

getUniform: function (varName, value, changeMat) {
            var func = _prop2Uniform[varName];
            if (func) {
                return func(this, value, changeMat);
            return null;

How can I do the same thing as before with the new changes in the engine source code?

Thanks in advance

@slimbuck did some changes here recently.

Hi @Francisco_Bozzo,

Do you mind giving more context on what you’re trying to do here? StandardMaterial.getUniform() function is not public API and we changed its implementation recently.


Yes, thank you!

Here is a sample scene: https://playcanvas.com/editor/scene/1236282

I am applying a shader chunk to a water material. And I want to update some of the parameters (i.e the normal map offset) in the shader chunk on every frame.

I am having problems trying to get a hold of those parameters in the chunk

Thanks for the help!

Thanks @Francisco_Bozzo.

This example appears to simply be setting the material’s normalMapOffset value. You can accomplish this much more simply by using the material’s API directly.

In the example you provided, remove all the override code and add this to the update function:

    const offset = this.mat.normalMapOffset;
    offset.x += dt * this.speed;
    offset.y += dt * this.speed * -0.25;

That will accomplish the same thing, but using the material’s standard interface.


That would work almost fine, but I was after a little bit more variation on the bumpiness of the material… I wanted to “mix” the normals in two different scales, and then do the offset.

Maybe this could have been achieved by using normalDetailMap and normalMap within the standardMaterial API, but I wanted to start getting my hands dirty with shaders and chunks from the basics.

In the end I found that material.normalMapFloatPS doesn’t exist anymore…

So I tapped into normalMapPS and that was all! Now I can get and set parameters from the chunk :smiley:


1 Like