Share calculation between Procedural textures?

Hi,

Now that I am done with the material plugin, which works great, I am back with the procedural texture system.

It works, no issue, but I want to add a procedural normal map.

I would like to do my calculation once, and reuse the common results in both the procedural texture and the bumpTexture.
I will store my shaders in a ShaderStore.

Right now, it seems separated. This is the logic I follow:

var albedotexture = new BABYLON.CustomProceduralTexture("atexture", "shaderstore_name", 1024, scene);
var bumptexture = new BABYLON.CustomProceduralTexture("btexture", "shaderstore_name2", 1024, scene);

Ideally something like
var precalctextures = new BABYLON.CustomProceduralTexture("precalctextures", "shaderstore_name3", 1024, scene);

It is not just about importing the code, but importing the cached result for the current fragment to avoid recalculation when the parts at the beginning are the same.
I don’t know… it would enable to benchmark the impact of “shared code then parallelism” vs “full parallized” pipeline…

Since the GPU is so good at parallel calculations, I am not that confident it is a good path to follow…

I am really wondering now.

Anyway, maybe you already have something to tackle this situation.

Thanks,

cc @sebavan

1 Like

This is always a tradeoff.

If the compute is really simple, adding the extra cost of going through an extra draw call + texture sample per pixel it is probably better to keep it inline in your shader.

That said if it is a compute intensive process there is a point (depending on the device as well) where perf will flip from inline vs caching.

In general the compute will really need to be A LOT to be more expensive than another draw call + another texture fetch knowing JS is most of the time the bottleneck, not the shaders.

Ok, I will keep it that way then :wink: