Custom Triplanar with correct normals

Hi,

I want to make a custom triplanar uv projection in order to use it with the stochastic node from Jason Booth : Stochastic Height Sampling Node for Unity's Shader Graph | VFX Shaders | Unity Asset Store

My shader needs to be applied on meshes with tangents because I have “regular” UV sets of non-tileable textures (for cliffs and rocks) and want to vertex paint triplanar détails on it (moss).

I checked multiple tutorials and the best I found is for UE4 :

But even with the 6 planar projection he show, I have normal map issue.

The issue, apparently related to tangents, is well explained in this article made by Ben Golus aka bgolus :

Sadly, as a non-programmer, I can’t understand all of it and reproduce it in shader graph.

Maybe that someone wise and gentle enough could post here shader graph versions of the bgolus triplanar shaders.

Cheers

Sure you want triplanar and not just projecting uv from a plane (direction) ? for snow/moss it would be better performance to just generate a regular uv map in shader and use that uv set to blend the texture of choice…

If it’s top down world space it gets even easier!

Thanks for suggestion, but I definitively want it triplanar. Because I will have gravity mechanics and up will possibly be down or side. And I will also apply omni directional textures like mushrooms.

still not cut and dried though, you can project to any direction from a point or per material, but I get ya :slight_smile: I can’t help with triplanar although it is built into HDRP if you’re using that.

I posted an object space version of the built in Shader Graph triplanar node using nodes. That might be useful for you to build off of.

Ideally if you’re using Booth’s sampling node, you’d also want to be height blending between the sides of the triplanar projections rather than linearly blending. I don’t have any graph examples of that though.

Thank you so much !

This work perfectly.
I just have a couple of questions regarding performances.
I heard somewhere that object based triplanar is more costly than world based triplanar. Is that true ? If yes, by how much, approximatively ?

I dont understand the use of the maximum node at the bottom of your graph. Did you put some value in there ?

In order to save performance I lerped the 3 UVs before injecting them in the texture samplers, this make me use 3 stochastic texture samplers (diffuse-height, normal, smoothness-emissive-metallic-ambient occlusion) instead of 9, so I guess that this it is a fairly significant performance improve, since I think that stochastic samplers are almost 3 times more costly than regular texture samplers. However, this lead to very visible transition between the projections axis. It is ok for me because I dont have round shapes. Only facets, low poly style. I can reduce the seem with a power of 156 for the blend contrast and avoid the critical angle where the texture is streched.

Is there a “noob friendly” way to profile the performance for shader graphs in order to compare them?

Anyway, thanks again for spending your time sharing your knowledge.

As far as I understand it, it’s a bandwidth problem. Triplanar’s math is pretty simple, but how many times textures need to be sampled is quite heavy: consider if you sample normal + albedo + mask map 3 times instead of once?

So looking into having a packed map might help, to reduce bandwidth. I am an amateur compared to @bgolus however I think that mostly you will want to look at how much texture sampling goes on more than how much maths you do these days.

Object space triplanar isn’t inherently any more costly. That node graph is a 1:1 copy of what Unity’s built in Triplanar node does, just with all the nodes in Object space rather than World. For node graphs, that does mean some extra matrix multiplies to convert from world space to object space since almost all the data starts out in world space in Shader Graph, and if you do a world scale, object oriented triplanar mapping there is some additional and minorly expensive code for getting unscaled world space orientations out of the object to world matrix, but that example graph doesn’t do that. Modern GPUs are stupidly fast at math these days anyway.

It’s also specifically for triplanar normal mapping, so there’s additional nodes there to handle converting the normal maps from object space to tangent space, but everything before that is reusable.

Nope. It’s a straight up mistake on my part. :stuck_out_tongue: As I mentioned above, that was an attempt to reproduce the functionality of the built in triplanar node in graph form, but I don’t personally actually use it so I missed that it was broken. That should have a split node in front of it, and two maximum nodes comparing the 3 components of that vector.

Yeah, this is totally fine if you don’t need the blending between the axis. However instead of lerping & using a power, I would use comparison and branch nodes to pick the UV and remove any chance of there being a partial blend. And yes, those nodes are much more expensive than the basic Sample Texture 2D and 3x the sampling of each texture, so this is a good optimization. The usual blended triplanar setups do 3x samples per texture, so if you used that plus the stochastic sampler it would be 9x samples per texture, so that change does bring the sampling costs there down to parity with the same 3x sampling that triplanar normally costs.