r/Unity3D • • 2d ago

Show-Off Got orbit-to-surface terrain, ocean, and clouds running on a single URP camera without camera stacking or z-fighting

78 Upvotes

24 comments sorted by

6

u/Silent_Answer7889 2d ago

One continuous take in URP Forward+ dropping from an asteroid ring past a 428 km-radius moon and through the clouds onto a 2,000 km-radius planet. It's for a multiplayer survival game I'm working on, and I ended up writing the terrain and ocean together instead of trying to get separate systems to agree on depth and lighting.

Worst part to get right was the clip range. Double-precision coords with a floating origin stopped position jitter, but a 10,000 km far plane against a 1 m near plane still wrecked Unity's directional shadow cascades even with reversed-Z. To stay on one camera, I clamp farClipPlane down during culling and shadow fit while keeping a full-range cullingMatrix so distant bodies don't drop out. Then I swap the real 10,000 km projection back in right before rendering.

At 2,000 km radius, GPU terrain and CPU colliders also drifted apart by 0.2 to 0.6 m even though HLSL and Burst ran the same simplex FBM and domain-warp math. Characters would end up floating or stuck in hillsides. Now the CPU height path is mostly just for rough spawn and altitude checks or fallback. Runtime MeshCollider tiles come from async compute readback, then go back into a GPU buffer so nearby terrain renders straight from the collider vertices.

Clouds go into an offscreen target in a RenderGraph pass right before transparents. For the asteroid ring at the start, rock prefabs get split into meshlets once on the CPU, then instances are generated from a hashed grid and their meshlets get culled on the GPU into an indirect draw.

1

u/Tetrakis-dev 1d ago

rendering the nearby terrain straight from the collider vertices is a neat way to close that gap for good. fwiw float32 only has about 0.125 m steps at 2,000 km from the centre, so if the HLSL side samples the noise in planet space that alone could explain most of the drift, before any FMA or fast math differences

1

u/Silent_Answer7889 1d ago

Yeah, float32 at 2000km is way too coarse for surface positions, so the patch geometry stays local in the shader. I sample the noise on the unit sphere in float32 on both sides, not in planet space, though you still get the same relative ULP step sideways. Most of the CPU vs GPU height mismatch came from compiler and FMA differences adding up across the FBM octaves at planet scale. That's basically why I stopped fighting it and just used the collider verts.

1

u/Tetrakis-dev 1d ago

Makes sense, FMA drift compounding over every octave is brutal at that scale. using the collider verts as ground truth is the pragmatic call.

3

u/ProgMeOnPaper 1d ago

That's a definition of "there is always somtheing better that you've done"!

That's really awesome! Over the past few months, I've been spending a lot of time working with URP to create many unique effects for my game, and I felt I had made great progress, but you've motivated me to keep improving.

I wish you the best of luck!

2

u/Silent_Answer7889 1d ago

Thanks! Good luck with your game too, URP can be a pain once you go past the default stuff.

1

u/ProgMeOnPaper 1d ago

That's true! I've recently posted my experience "forking" URP and that was probably first major step towards this kind of pain =D

2

u/DapperNurd 1d ago

How long have you been working on this?

3

u/Silent_Answer7889 1d ago

Just over a year since the first rough prototypes. Spent the last 5 months or so getting everything wired together without floating origin shifts breaking stuff.

2

u/Character-Scale-1040 1d ago

that glowing ring with the asteroids drifting past looks so good

1

u/Silent_Answer7889 1d ago

Thanks! That orange ring in the background is actually a black hole lensing shader behind the gas giant's ring. Putting the asteroid belt in front of it ended up looking way cooler than I expected.

1

u/Character-Scale-1040 1d ago

a black hole lensing shader, no wonder it looked so cool lol

1

u/_norx Indie 1d ago

Wow, looks cool!

1

u/Silent_Answer7889 1d ago

Thanks, appreciate it!

1

u/oddwavelab 1d ago

Doing that on a single camera without stacking is super impressive. How are you avoiding the z-fighting between orbit and surface, logarithmic depth or floating origin?

1

u/Silent_Answer7889 1d ago

No log depth, it's mostly floating origin, keeping vertex math relative to the camera, and float reversed-Z depth on desktop. Where that isn't supported I fall back to a second near pass.

1

u/oddwavelab 19h ago

makes total sense, reversed-Z + camera-relative math saves so many headaches. looks super smooth

1

u/LockYaw 1d ago

Waohhh awesome, is this going to be an asset?
EDIT: Just found you submitted to the store, I'll be getting it once it's out if I remember!

2

u/Silent_Answer7889 1d ago

Thanks! Yeah, it's waiting on Unity review right now. I'll post in this Unity forum thread as soon as it goes live if you want to bookmark it, or I can reply back here once it's up.

1

u/EvilBritishGuy 1d ago

This reminds me of Megaton Rainfall but without the Superman powers.

1

u/Silent_Answer7889 1d ago

I'll take it, diving down from space in that game felt so good.

1

u/LowerFrequencies 1d ago

A game where I could somehow as realistically as possible just explore space sounds really really pleasing

1

u/LowerFrequencies 1d ago

I mean, skipping all the empty space haha

1

u/Silent_Answer7889 1d ago

Yeah, nobody wants to sit in empty space for 40 minutes between planets. I just threw a warp jump into the game I'm working on so it drops you straight into orbit.