Tuesday, 8 October 2013

Star rock 3D tutorial 3ds max Unity

"Well, hey, hey, I wanna be a rockstar
Hey, hey, I wanna be a rockstar"





 Rocks are cool. Can place a lot of them on terrain. Can do nice garden design. You can hit someone with it . But what about creating them in 3d. Yes all we know take a z brush or mudbox and everything you want from a sphere. All that tutorials about brush modeling is extremely easy you take 3 brushes and masturbate on this editor half of your life. No fucking way guys... If I take clay I can make such rock in five minutes, why should I spent neurons of my brain to convert my hand abilities to zbrush hi poly shit.

I have spent a lot of time looking on rocks. I want to make as realistic rock as I can. One day I even took one rock from my backyard and put it near computer. Custom 3D scanner is helped me a lot my task. So I have thought what is the problem with the rock. In real life any object can exist. Main problem is in lighting. Game development world going to changed one day when games will come to ray traced light. All designers will feel happy with it. A lot of unneeded stuff will be pushed away like faked light models and stuff like that.

 Lets create them in easiest and efficient way. We need
1. Cocaine
2. 3d max
3. Couple of textures that will be suitable for rocks.

  1. Take some cocaine and let's begin.
  2. Load 3d max and let's think about rocks.

What is rock? Rock is some noise. But as everything in nature - fractal. So not easy noise.  Every rock have it form or bounding box. We can start from sphere like zbrush guys doing it. But no. In fact we need UV box mapping on a sphere that allow us to make lightmaps and colormaps in game correctly. So create a box with some subdivision and apply Spherify modificator. What next? Of course we need to add some details to our rock. We can use displacement modify with hi res poly.To get this polygons on high add TurboSmooth. That allow us to control polygon count at all levels of editing in editor and rendering.  Next we going to create some noise map that we can apply  on our rock. Add displace  modificator and apply noise map on it. The hardest thing in all this process is to tune parameters correctly, so tune parameters of a noise we can see them in preview dynamically.
Next we add small details. If some problems with noise tuning you can download scene above.

And after all even smaller details....

Now we have 5 levels of noise on our rock.
And after everything we add free form modification to make out rock looks like we want. That's cool.

Final transformation stack looks like:

Oh god, hows I like new 3ds max preview with shadows and SSAO:

Such rock already looks cool to put it in cg. But if we put such rock into a game we will have some problems with polygons count and other boring things. So lets do tricks and tips for lowering resolution of this rock. We can bake hi res mesh into a normal map. That's will give cool looking of an object in half light and shadow. But if we look deeper with no light or all in light our rock will suck. Why???? Like in this Hollywood films nooooooooo......or......whyyyyyy. Because of lighting. Game lightning is really suck. It have no reflections. Real life have them. So our brain look at the picture and say. What the fuck.? Real time 3d is all of tricks and bad solutions like shaders. We can bake light into a texture and use it in a game.

Ambient occlusion my son.... Another tricky shit that was created by code designers to cheat our brain. Idea is simple we took two objects and place them near. What we can see in real life. Little shadowing. In real time light model we have nothing at all. So lets emulate such behavior before to use it in game.

We can store texture of ambient occlusion. Do it well and place in our rock shader later.

Now create two 2 rocks hi-poly and low poly. Apply Projection modification to low poly and pick high poly model. Keep in mind that they should stay at same positions for correct projection.With projection modicator it looks like this:

Render normal and diffuse map to texture. And export low-po model.

Tadam. job is done. Maps looks like:

Tweak it a little in a photoshop or anywhere else. Now combine all three textures. Main ambient occlusion and other. We have amazing stuff.
Rendered rock looks like:

I did small investigation. I tried different polygon count and here is result:

600 polygons 1024x1024 textures:

2400 polygons 1024x1024 textures:

2400 polygons 2048x2048 textures:

What's about rock formation. We can made them with a pro Boolean modify of 3ds max. Place lot of our rocks near to each other and combine then with pro Boolean modify. That's all. Looks amazing....everyone is happy...everyone is on high.

Scene done in Unity:

tutorial based on Sascha Henrichs rock generation script