Triplanar shader strange behavior when meshs are translated (possible bug)

Hi friends,

i’m working with triplanar mapping (Tri-Planar Mapping Material | Babylon.js Documentation). I just found the material does not work correctly when meshes are translated (any position different from 0,0,0).

I made an example here: https://playground.babylonjs.com/#E6OZX#495

When you add any position to the ground the textures are not correctly mixed.

I think worldNormal calculation, in vertex shader, is not right. Ignoring “world” seems to solve, but i’m not sure if this is a good solution. Any help?

//triplanar vertex shader
...
#ifdef NORMAL
...
  //vec3 worldNormal=(world*vec4(normalize(normal),1.0)).xyz;
  vec3 worldNormal=(vec4(normalize(normal),1.0)).xyz; 
...
#endif

I think this is the right fix:

…and welcome aboard (and thanks for the reporting)!

thanks! perfect.

Hi there and excuse me for bumping this old thread, but I have a related question (if new thread is needed, please tell me).

My question is: Does that fix mean triplanar textures can be in local space instead of world?

In DCCs like MAYA, projections have “local” mode, so with a unique projection (triplanar in this case) you get local transformations of it, like object translation, rotation and scale, so in the end the texture, even when it is a projection, sticks to each object perfectly, which is a must when there is animation involved.

Thanks!

cc @Evgeni_Popov

The TriPlanar material does not allow this.

You can do it with a node material with the new TriPlanar block, though. However, it does not (yet) allow 3 textures as inputs, so here’s a PR that fixes that:

2 Likes

Thank you @Evgeni_Popov for the info, I’ll check that.
For some reason I didn’t got any notification and didn’t noticed you answered, excuse me for my late answer.
Cheers.

Hi there @Evgeni_Popov
You say I can do this with NME, but I can’t figure it out (I’m not a coding guy by no means).
I did this, though.
What do I need to connect in order to make Triplanar work in local space?

Your material is ok :slight_smile:

You connected the mesh.position output to the TriPlanar position input, so you are using the local mesh position already. To use the world position you would need to connect the WorldPos output instead.

Note that you should remove the second unused FragmentOutput block.

2 Likes

Thank you for your help.
And now, how I connect PBR textures?
Should I use three triplanar nodes or is there a way to use ONE triplanar for that?
I ask that because having three nodes to do the same is kind of prone to human error, unless I can connect all three somehow and be able to have them synced

You can plug 3 textures to the triplanar block:

I have also used an additional triplanar block for the bump mapping. This way, it has the same functionalities than the regular triplanar material (but with the additional possibility to use local space).

You can change the textures programmatically using mat.getBlockByName():

2 Likes

Yes, you can plug up to three textures to the triplanar block for each axis, BUT I was referring to the textures needed for PBR shading, that is baseColor, ORM and normal textures.
So basically in the end you indeed need THREE triplanar blocks, one for each.
I hope triplanar material get an update and will be able to do PBR shading too.
Cheers.

Indeed, you need another triplanar block for the ORM texture, there’s no way around that.

I’m not sure what you expect from a triplanar PBR material that a node material couldn’t do?

In any case, there’s ~0 chance that the existing triplanar material will be updated to support PBR, it would be way too much work. Currently, it is not even up to the standard material, it uses its own shader that only does triplanar + shadows (so, no emissive, opacity, fresnel, refraction, etc that the standard material can do).

Note that the node material also has a BiPlanar block which uses only two textures instead of three. You may get some artifacts, depending on your geometry, but it may be worth a try.

See Inigo Quilez :: computer graphics, mathematics, shaders, fractals, demoscene and more for more information about biplanar mapping.

3 Likes

Two wishes for my wishlist…

  • Support for PBR triplanar
  • Triplanat material supported by AR engines

That’s all

We will need to use three triplanar nodes, ones for each PBR texture, then.

Merry Christmas to all.