Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity3D, round the edges of a box, cube?

What's the usual way to round the edges on a cube, a rectangular object as in the examples?

enter image description hereenter image description here

The ideal result would look pretty much exactly like these images.

(Naturally, you could literally use a mesh that has carefully rounded edges and corners, but it takes many tris to achieve that.)


Note, of course for a NON-shader approach...

enter image description here

Add two small flat boxes and simply make that new normal halfway, i.e., 45 degrees, between the two sides:

enter image description here

That would be drawn perfectly round ...

GDG below has provided an article where someone asserts that this is indeed the best way, if not using a shader approach.

I'm really wondering how to do this with a shader though.


Note - incredibly detailed tutorial on the non-shader approach

http://catlikecoding.com/unity/tutorials/rounded-cube/

like image 933
Fattie Avatar asked Aug 01 '14 10:08

Fattie


2 Answers

Using deferred shading you may access G-buffer to locate and round edges like it done in this paper. Though it is a post-processing technique so it is able to emulate roundness in a limits of some pixels.

enter image description here

Simple averaged normals (1 pixel width):

enter image description here

Simple averaged normals (2 pixel width):

enter image description here

Simple averaged normals (3 pixel width):

enter image description here

like image 108
game development germ Avatar answered Sep 21 '22 01:09

game development germ


I'd certainly defer to a shader-oriented answer, but especially if the necessary shaders aren't available on a given platform, I'd accomplish this with a few "level of detail" models aka LoD.

  • Give the GameObject for this object meshes for a 6-sided box, a slightly-curved box, and an up-close very-curved box. (http://www.wings3d.com/ is my go-to simple modeling tool)
  • Give the GameObject a behavior script that checks each frame for distance from camera.

  • Activate the appropriate mesh based on the distance, and deactivate the others, this should be done at a distance where the change isn't detectable at the highest resolution available to the player.

This technique is pretty widely used in 3d games, a good way to represent far-off swarms of things that can become much more detailed once the camera gets up close.

like image 40
peterg Avatar answered Sep 22 '22 01:09

peterg