r/Unity3D • • 5d ago

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

90 Upvotes

32 comments sorted by

7

u/Silent_Answer7889 5d 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 5d 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 4d 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 4d 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 4d 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 4d ago

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

2

u/ProgMeOnPaper 4d 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 5d ago

How long have you been working on this?

3

u/Silent_Answer7889 4d 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 5d ago

that glowing ring with the asteroids drifting past looks so good

1

u/Silent_Answer7889 4d 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 4d ago

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

1

u/_norx Indie 5d ago

Wow, looks cool!

1

u/Silent_Answer7889 5d ago

Thanks, appreciate it!

1

u/oddwavelab 5d 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?

2

u/Silent_Answer7889 4d 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 4d ago

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

1

u/LockYaw 4d 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 4d 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 4d ago

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

1

u/Silent_Answer7889 4d ago

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

1

u/JaeokPhysics 1d ago

You brought to life what I had only imagined. It's really wonderful.

1

u/Silent_Answer7889 1d ago

Thanks a lot! Getting that drop from space down to the ground is the whole reason I started building this.

1

u/SouthgateGames 18h ago

Did you start something like this from scratch, or are there papers or videos that you used to get started and then did the work of solving the problems that came up yourself?

This is incredible work, thanks for sharing! I'm going to have to tread some of this same territory for my own project eventually, and I'm always interested to see how other people are tackling it.

2

u/Silent_Answer7889 16h ago

Thanks! I started from papers and talks, wasn't about to derive all that math from scratch. Ocean uses Tessendorf's FFT paper (swapped Phillips for JONSWAP), atmosphere started from Bruneton/Hillaire, and I followed Andrew Schneider's Horizon Zero Dawn talks for the clouds. Terrain is just a cube-sphere quadtree.

Most of the time went into fighting Unity once I scaled it up to a 2000km radius. Stuff like a 0.01 near plane with a huge far clip wrecking URP's directional shadow cascades, or floating origin shifts smearing TAA and motion blur for a frame.

1

u/studiocari 3h ago

what's the end goal? kitten space agency?

1

u/Silent_Answer7889 2h ago

Not really a rocket sim, KSA looks cool though. Going more for a multiplayer space survival game where you fly between planets and get out on foot or in rovers.

1

u/studiocari 2h ago

love it. is it going to be with realistic physics for the space travel, or it's mostly focused on surface exploration?

•

u/Silent_Answer7889 5m ago edited 0m ago

Thanks! Mostly surface, yeah. Flying is pretty arcadey like No Man's Sky so there's no real orbital physics. I want driving and shooting to feel closer to GTA.

1

u/LowerFrequencies 4d ago

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

1

u/LowerFrequencies 4d ago

I mean, skipping all the empty space haha

1

u/Silent_Answer7889 4d 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.