How to get soft edge (e.g. of a planet)?

I’m rendering some planets that have a pretty darn thick atmosphere, such as Venus:

The problem is that the edge of the planet looks crisp and sharp, when in fact it should be a bit indistinct and fuzzy.

The planet is actually a hemisphere, carefully positioned relative to the background camera, as shown here:

How can I get a fuzzier, more indistinct border to my object? Is there a shader or some special effect I should be looking at?

Thanks,

  • Joe

Simplest solution would be to add a circle billboard to the center of the planet that extends beyond the radius of the planet.

You can go quite complex with that to make it more realistic as well.

1 Like

That’s a neat idea. I can even imagine a custom shader that lets you specify the fall-off and color of this fuzzy circle (EDIT: perhaps like this?) — and then you just slap that onto a billboard. Thanks for getting me unstuck!

Nuts — that doesn’t work as well as I’d hoped. It’s fine for things that are a decent distance away from the camera, and/or close to the center of the screen. But when the planet is very close to the camera, or further away but off near the edge of the viewing frustum, then the billboard doesn’t always line up properly with the visible edge of the hemisphere. It ends up drawing in front of the planet on one side or the other, and looks bad. (And yes, I’ve tried both pointing the billboard directly at the camera, and pointing it opposite the direction the camera is facing; both fail in different circumstances.)

I could probably work around this by introducing another camera, so that I can ensure the haze is always drawn behind the planet. But I’ve already got a foreground and a background camera; I’m loathe to introduce a third.

Any other approaches to this problem?

I’m thinking the ideal might be something I can apply to a spherical (or hemispherical) mesh, which I would position and size just slightly larger than the planet. This would need some sort of custom shader that draws alpha based on how far from the visible edge it is… though I have no idea how it would do that.

Or, maybe there’s something more clever than simply rotating a Quad to face the camera; some math I could do to figure out exactly where the edges of the sphere are, and adjust the quad mesh accordingly.

Or maybe I need an Image Effect?

I was going to suggest some kind of gaussian blur camera efffect - with another camera, though I have no clue how to incorporate this.
@imaginaryhuman_1 seems to have a handle on special camera effects and separating rendered paths.

@JoeStrout
Ah well. You should probably go the sphere method then, and make a shader that gradients based on normal vs view direction. It’d get complicated when you’re going inside of the atmosphere though. And you may need to use front-culling instead of back-culling, or fancy ztest options.

You could use the new command buffers with this sphere method, and then manually draw it over the planet as a sort of image effect, referencing what’s in the buffers.

1 Like

http://scrawkblog.com/2013/04/13/gpu-gems-to-unity-atmospheric-scattering/

2 Likes