Screen Space Scaling for UI in World Space #244
najak3d
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've used this technique for years, successfully, and love it. However, Unity doesn't seem to make it easy with URP (I'm not even sure how to do it with URP, as the graph doesn't seem to allow it, yet). So I'm guessing this requires custom (non-graph) URP code.
In short, for UI in world space, I create billboards where all 4 vertices have the SAME world position, but then they also have an XY relative offset (in screen space) from that center point. Then based upon the 'Z' (depth/distance) value for the world position, we can then scale the billboard in SCREEN SPACE.
We do this because we do NOT want labels to shrink in size as fast as the other 3D content. So if you have a 3D model, it's far less important to see Model Detail from 1 mile away, but you might want to read it's "label" (indicating name/type, alliance) -- but as it nears, you want to grow this label some but not by much.
I typically decimate size using a "Power" function, similar to "square-root" along with a min/max size cap. This is all done in the vertex shader with very simple linear math and clamping. For example, we may set the following parameters:
So something 1000 meters away will be Half-sized, compared to something 10 meters away. As it gets closer than 10 meters, it no longer grows. As it gets further that 1000 meters, it no longer shrinks.
You can set ALL of these parameters one-time and the shader "just works".
Now you have complete/meaningful control of "UI text/button/etc" size in screen space, as a function of "distance from Camera" which is NOT linear (Power = 1), which is usually NOT desired/good.
Without this feature-- what I'll have to do is make our C# constantly evaluate Distance-from-camera for each object, and manually set the Transform's scale -- per frame, per UI element. This is work load that I'd like to offload to the GPU, where it's done 100x+ faster.
Beta Was this translation helpful? Give feedback.
All reactions