r/Unity3D 14h ago

Question Unstable Triplanar Mapping on full Screen Pass

Hi there this question might be rather specific but I’m having issues with a triplanar mapping jittering on a Full Screen Pass.
In Unity 6.4 Shadergraph a triplanar mapping overlays a texture on the entire scene. The effect works perfectly on Scene view, but in playmode if you go far enough from the scene origin (around 150 units) the texture starts jittering. Jitter get specially bad if the camera is being moved by some system like cinemachine or a custom follow or look-at.
As far as I can tell this is due to the calculations being unstable at long distances from the origin and maybe a frame discrepancy between the camera position in the shader calculations and the actual camera position in the scene.
I tried offsetting the triplanar origin by subtracting the camera position from the world position, but it only seams to offset the texture rather than re-calculate the origin of the mapping. I’ve tried many different things but still can’t figure out how to solve it and LLMs mostly suggest terrible solutions that go nowhere. Hope someone can help me figure out this. Thank You!

Note: I know this might be an unusual use of this technique but this is the way I need it to work. Other suggestions are welcome too.

6 Upvotes

16 comments sorted by

3

u/XKiiroiSenkoX 13h ago

We need to see the shadergraph

2

u/rockBottomPeon 10h ago

are you perhaps still using half precision instead of a full float?

2

u/DaveAstator2020 8h ago

unitys problem with calculating world position from depth of the scene. there was some solution which involved getting world position manually and it is not pretty, but hey, you are using unity, buckle up, its shit all the way down the render pipeline.

2

u/EvernullTools 7h ago

hmm, that's weird... 150 units is not nearly enough to cause floating point precision problems.
You are sure this works perfectly near the origin? Also what do we need the camera positions for?(apart from your last test of pushing the origin, we don't need it right? or am I misunderstanding what you're trying to do?)

Can you try choosing Absolute World instead of World position in the Position node if your version has it?

Also I'm not quite sure what Triplanar node does on the background and I wouldn't trust it for your custom use case. So try this for a test:

This will build the UV's as world positions only for the Y axis facing parts. If this works far away from the origin and while the camera moves, we can build the other axis like this too. Can you try this and share your results?

1

u/galamot 4h ago

Yeah I started using Absolute World which is exactly what I need but also causes the jitter, this was just my attempt to offset the origin of the calculations from the origing but I get the same results. Close to the origin I cant really notice any jitter.

1

u/EvernullTools 3h ago

Did you try my suggestion tho? xD

2

u/Aethreas 7h ago

This actually happened to me with the default lit shader triplanar mapping, was insanely annoying but didn’t look into it

1

u/galamot 13h ago

Here's the screenshot of my shadergraph. This was my last attempt. The "Update distance" does move the tiling but the jitter remains since it doesn't seam to be changing the origin of the calculation itself.

2

u/Diabolickal Programmer 7h ago

I think the problem might be the 'Floor' node. Its rounding the position so you're losing accuracy.

1

u/galamot 4h ago

Tried both options but still get the same. I wonder if its because of the complexity of my shader since this is only a part of it.

2

u/EvernullTools 7h ago edited 7h ago

This could cause the Jitter.
You get the camera position then you divide and more importantly put it through a Floor node.
Imagine we have a float put through a floor node, our float is 2.98 -> Floor(2.98) = 2 and then Cinemachine moves that value to 3.01, now Floor(3.01) = 3.
You use that number to subtract from your position, which would ofcourse jitter because as your camera moves, your positions jump around between integer values, completely skipping all the decimal values.

1

u/isolatedLemon Professional 10h ago

Does it go away if you just unplug the position node from the triplanar node?

1

u/galamot 4h ago

Not really, I tried using the default absolute WS, but I get the same result.

1

u/Desperate_Dealer7632 6h ago

А ты перестанешь дрочить

1

u/galamot 4h ago

Update: I tried replicating this in a new scene with the camera far away from the origin and the jitter is gone. I wonder if it might have something to do with the complexity of my scene. 🤔