Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
randomrabbit

Baking Cube Maps of Distant Objects

Question

Hello,

 

I'm trying to use Unity for very large scenes without much success.

 

I have to use culling to prevent all objects in the distance being rendered to save on performance. But this means if there are big objects like mountains in the distance, they are culled.

Increasing the amount of fog helps hide this but ideally I'd like to be able to see these mountains and other distant gameObjects.

 

My idea is this:
Take a point in the scene which the camera could potentially reach during gameplay. At this point bake a Cube Map (maybe using a reflection probe) of all the gameObjects beyond the range the camera can render. The cube map should be transparent where there are no gameObjects. This is done in the Editor so doesn't effect runtime performance.
Do this a large number of times for lots of different points in the scene. At runtime blend between these Cube Maps to get an image that looks like its from the camera's position and overlay them on top of the skybox.
Then the camera only needs to render close objects as it is blending between images of the distant ones.

 

I understand the shadows at the boundary wouldn't match up well and the lighting couldn't change (day/night cycles wouldn't work as the distant objects have only been baked for specific light conditions). But, apart from this I don't see why it wouldn't work well. Seems odd that I haven't heard of people using this method before.

 

I'm wondering if this is worth trying? Do you think it would save on performance? Would the blending between cube maps make it look good or bad?

 

Thanks.

Share this post


Link to post
Share on other sites

8 answers to this question

Recommended Posts

  • 1
Please login or register to see this quote.

 

There's quite an easy solution for rendering objects that are far away without increasing the far plane.

Essentially, you use a second camera and scale everything down, say by 10x or 100x depending on your needs. That camera will render your large distance objects AND the skybox, your other camera is an overlay.

Now the essential part:

You copy the rotation of your normal camera every frame, like that:

largeDistanceCamera.transform.rotation = mainCamera.transform.rotation;

And here the magic happens:

You copy the position but multiply it by 1 / your scaling factor:

largeDistanceCamera.transform.position = mainCamera.transform.position * 0.01f;

 

I've used this in the past and this technique is also used in other engines (Source for example).

 

I saw a video using it in the past (someone built something with halo in unity), but I can't find it now, if I find it, I'll post it here.

 

Edit:

I found it. Check it out:

 

Share this post


Link to post
Share on other sites
  • 0

Maybe this isn't such a good idea after all.

 

Google maps street view does some kind of cube map blending when you move from one location to another and it looks awful. I think using that as a skybox would look quite bad.

It would only work if there was a good method for blending the cube maps.

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)

Ahm sorry what? If you want to optimize and actually be able to run a large scene, the most important things are occlusion culling and LODs.

You can mess around with the shadow casters so not all objects cast shadows like props for example, SSAO is enough for them.

Bake lightmap, but keep in mind that it's the same thing as the shadow casters. You can leave out small props or trees from the lightmap, setup a light-probe group instead for them.

Edited by UnityGamesRoland

Share this post


Link to post
Share on other sites
  • 0
Posted (edited)
Please login or register to see this quote.

I agree. I am using Occlusion Culling and LODs and they are very important for optimization.

 

I think you might be misunderstanding the point. The problem is the camera's far clipping plane causes far away objects to be culled. So if you want to render some far away mountains you need a very large value for the Far Clipping Plane. And this will cause a big fps drop.

My idea was to cull the mountain (and all distant objects) but add them to the skybox. This can be done by baking them into a cubemap and overlaying that onto the skybox. But this causes another problem: when the player moves to a point far from the mountain but on the other side of it, the mountain on the skybox is the wrong way around. So the idea was to bake lots of cubemaps for different locations in the scene and blend between them depending on where the player is.

Edited by randomrabbit

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

I'm sorry to ask, but can't you just exclude the mountains from the OC bake? (only if they are seperate objects from idk a terrain or something) So that the mountains are always visible? I did that with some low poly mountain assets that I put in the background of my scenes.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Thanks for the help but the mountains are part of one big terrain so I'd have to exclude the whole thing from OC.

 

I think I might try making billboards of the mountains excluded from culling and have the terrain culled.

It's not ideal though as I also have forests which i'd like to look down on from a distance and billboarding the whole forest wouldn't be easy.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Thanks! Thats quite a clever idea.

 

I might try it. My only concerns are having two cameras might mess up image effects and maybe fog.

Share this post


Link to post
Share on other sites
  • 0
Please login or register to see this quote.

Image effects should be applied to the last camera. In the past, it caused issues, but I am using a two-camera setup in a test project of mine, even with mixed deferred/forward (deferred main and a forward overlay), which was impossible in the past, but it seems to work flawlessly today.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×