Friday, May 30, 2014

The Quest for Building the Best Possible Earth in UDK

This weekend I have decided to tackle the Earth. After many hours of work this task has become an obsession to make the best possible Earth in UDK. I want something that feels real when you are floating above it and that is no small task.

I have it in my final board, and although it looks OK it could look a LOT better. When I crack open a beer and sit at the end of the game overlooking the earth I want that to look as great as possible. The Oculus Rift should make you feel you are in another place and a great Earth model would go a long way towards that goal in space.

There are 2 tutorials I have watched on the topic:

1. A blender tutorial:

2. A UDK tutorial:

3. An additional UDK tutorial

It is also good to have a few reality checks:

And finally blue marble:


That blender Earth is sooo sexy. I need me some of that in UDK if it humanly possible. Comparing a 3D render to UDK is an unfair comparison but I think we should be able to approximate it.

As usual, I learned a lot of stuff I didn't know by watching both videos. I am going to try the UDK tutorial first since I need the Earth working in UDK but I think there may some additional value to creating overlapping spheres for the clouds and atmosphere. This will require more rendering but I don't have a lot going on out in space so it should be fine.

I will post my results here.

Step 1: The first step is to find a level of detail that feels realistic. Something this big requires a lot of detail. The blender model used a texture that is rectangular. I resized it into two 4096 squares. I then mapped those 2 textures onto one sphere. That took a while.


hmmm. I'm not sure about that level of detail. I know it it will look a lot different when I'm done but I'm not sure that detail is going to cut it. Just those 2 images and the mesh = 52MB udk package. If I map the sphere onto 4 images that will push it up to 100MB. Double that for night time. 2 more images for bump maps and 2 more for clouds gets me to 300MB. Really pushing it but possible.


As I started working on this I saw this month's discover magazine cover. This is an interesting idea:

Anyway...

The blender video author said he had to reduce the quality of the image by half. This was an incorrect statement. It took a few hours to map a sphere into 3 segments. Here is the result:


So now I have a sphere broken into 2 segments and another sphere broken into 3 segments. This should allow me handle all the images.

Now to see what this looks like in UDK with the 3 night image segments:


It looks good at this distance but up close it has all kinds of compression artifacts. I will do some more detailed searching for better non-artifacted images later. The important thing is to design it with 3 part images to maximize quality.

Here is the bump map I am going to use:
http://www.blenderguru.com/wp-content/uploads/2011/06/Bump.jpg

I will break it into 3 segments of 4096 a piece. I have no idea if I will be able to use a multi-part bump map but we will find out.

Here is what the left-most segment looks like in crazy map. Per the UDK tutorial I have given more emphasis to the finer details:

After thinking about this for a while I believe breaking the sphere into 3 areas is the wrong approach. I need a perfect sphere mapping for 1 texture. I think do the 3 part break-out within the texture itself.

Here is the material segment for doing this trick:



Notice that the image has lines at the joining point between the 3 textures. I've gotta sort through that after lunch. I think I need to expand my masking area and maybe gradient transition a bit.

Here is the result in game:


Looking good. No clouds, lighting or atmosphere but I am able to build a giant 3-part texture for a sphere.

Stitching 3 images in a material is a total pain. I think I spent 4 hours getting 3 images to line up in 1 material. I may go for 4 images when I am done.

I found uber large images and rebuilt my night & day images from them. Here is what it looks like with day and night added together with a normal map:


Now lets add in the fresnel (feeding the normal into it) and enable smooth shading on the object in blender and reimport it:


Limitations so far:
As I seem to be apt to do, I have ran into several limitations:

1. The size of my earth-only UDK package is 354MB. This contains the earth images along with the mesh:

2. There is a limit to the number of texture samples you can have in one material. When I try to add in clouds or the specular mask I hit it. To get around this I am doing 2 things:
a. I chose make the specular mask a single image. This is a problem since my solution to linking the 3 earth images together was to slightly stretch them. this causes the specular mask to not perfectly align with the land masses. We'll see if I have to skull sweat through a solution to this.
b. clouds are going in a separate mesh. This is what the blender tutorial did. I'm not sure this is a doable solution. We'll see.

I am also have trouble with the light vector (it isn't working). I built a new map this morning to see if the problem would go away.

Update...
I gotta say I really hate the seam between multiple images. I can not make it go away. I was so desperate I tried to put everything into 1 image that was 16384x16384. That exceeded UDK's max size of 8192x8192. I think I am going to go for broke and make the earth images 16384x4096 broken into 2 parts of 8192x4096. By reducing the seams to an even number I may have a chance. The day, night, normal and specular should fit into one UDK package. The clouds will have to go into a separate package. The upshot of all this (if I can pull it off) is that I will be able to put more logic in my Material because each image is a composite of 2 texture, not 3.

Never give up. Never surrender.
I finally got a seamless earth at 16384x4096 for each image necessary (2 parts of 8192x4096 for each). I gave up doing the merge in a material. I went back to splitting a sphere in half for UV mapping and figured out my seam issue: the UV was mapping too close to the edges. I rescaled each side to 99.9% and that brought in the mapping just enough to lose the seam. Now I can finally play with making the earth with high resolution. Here is a snapshot (nothing fancy yet):


This image has a day, night and a normal fed into a fresnal. It does not adjust night to not show based on a lighting vector. I had trouble with that last night and expect a lot of effort to get that working.

Update: 6/3/2014: clouds
I've been so busy I haven't had time until late tonight to work on this. I built the cloud & normals textures. I then added just the clouds to the left half of the earth with a panner to cause the clouds to move across the earth.

As usual, this is not going to be as easy as I hoped. Even though I am mapping clouds onto half of the earth, each side needs the full amount of clouds to scroll across them. This means I am back to melding the clouds textures together. I am hoping seams in the clouds texture will not be as noticeable since they are B&W and pseudo random in appearance and distribution. We shall see...


Star Citizen Planet
I'm keeping my eye on what current games do for planets. Here is Star Citizen's earth-like planet:


A couple of observations:
1. They have chosen to have no lower planet detail letting the clouds be the focus.
2. Their fresnal is floating above the planet
3. I suspect the clouds are not moving and that you are only seeing one side of the planet. ie: the planet is not a sphere but just the front section of one.
4. Their fresnal blue is much lighter and closer to the color of the clouds

Clouds on their own sphere
I removed the clouds from the Earth texture to prevent having to meld the textures in a material. They are now in their own texture mapped onto a sphere slightly larger than the earth with a slightly faster rotation rate. I also adjusted the fresnal color to be lighter. That will need to go into its own sphere too.


UDK Can't Handle it
Well crap. I hadn't looked at in the rift. I'm getting a rendering issue with trails of images not clearing out as I move my head. I've seen this once before on an experimental board. I think I'm boned. I removed everything except the night image and the problem persists. Damn that is disappointing. Maybe UE4 does a better job.

Where I found the images for the earth:
1. day: http://visibleearth.nasa.gov/view.php?id=74518
2. night: http://earthobservatory.nasa.gov/NaturalHazards/view.php?id=79765
3. bump/normal: http://visibleearth.nasa.gov/view.php?id=73934
4. clouds: http://visibleearth.nasa.gov/view.php?id=57747
5. specular mask: http://www.blenderguru.com/wp-content/uploads/2011/06/Spec%20Mask.png

No comments:

Post a Comment