Is that mean if I want to support interpolation for all texture fields(diffuseMap, emissiveMap, opacityMap etc.), I need to override all shader chunks of a material ?
I am looking a way to implement this globally, just like:
pc.StandardMaterial.prototype.updateProps = function (key, value) {
var oldValue = this[key];
this[key] = value;
this.setParameter(`material_${key}_old`, oldValue);
this.setParameter(`material_${key}_timer`, 0);
};
pc.shaderChunks.diffusePS = `...hack by me`;
pc.shaderChunks.emissivePS = `...hack by me`;
pc.shaderChunks.opacityPS = `...hack by me`;
// ...
This way is clearer than the wrapper script in the demo.
Yes you can’t get interpolation automatically working without custom GLSL, and yes you will have to override each material channel you are interested in applying this effect.
I think you got it right, that’s the way I would approach it:
pass the old map as a shader uniform using setParameter on the material
pass a timer the same way that controls the effect
My purpose is to support interpolation for all number/vector/color/texture fields. The main problem is lerp between two textures, other type of values are done.
I don’t think the onUpdateShader interface will help, because what I need is add timer and material_xxxMap_old into the original shader.
If the engine built in this feature, it will be great. @will
You will have to rebuilt a lot of things to support this, the standard material class is quite extensive.
No, number/vector/color fields can be updated in the update callback, it doesn’t matter. What I need to do is hack the texture related shader chunks. Such as diffusePS, emissivePS etc.
We’re busy implementing node graph shader system - when this is ready, it will be a lot easier to make customizations you ask for.
If you need this texture lerp only for small number of textures, you could consider writing a simple shader which just lerps two textures. And then you could use it to blend each set of two textures into render target, and attach the result to material.
That would use a lot of memory / performance for many textures though, but would be relatively simple to implement.
There is also a support for detail maps. It exists in engine (and so you can use it with script), but not in Editor yet. https://github.com/playcanvas/engine/pull/1968. I think it only handles diffuse / normal maps./
But it does not have lerp mode to blend textures, so that would have to be added (you could possibly overwrite detailModes.frag to replace existing mode by lerp.
I actually added this exact thing on my own project, took it the next level with a progressive transition using a “virtual sphere”. The code itself actually isn’t that complicated. I had a transition variable that updates in my update() and lerp the texture based on the transition float passed into the diffuse shader chunk. Very briefly this is what’s going on (don’t hold me to best practices)