Unity3D, round the edges of a box, cube?
Asked Answered
L

3

8

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

enter image description here enter 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/

Lebna answered 1/8, 2014 at 10:29 Comment(5)
That's not really work for a shader (well, it could be, but seems unnecessary). Any 3D modelling package will have something along the lines of a bevel modifier though.Drinking
Yes, I do. On a daily basis. And you're asking for "usually". That to the best of my knowledge is done by simply creating the mesh. I don't know if you have a particular reason not to want to do that?Drinking
No worries. Glad it helped somehow. ;)Drinking
Tutorial, Not 100% what you asked for, but a good option.Fortyfive
@Catwood, that is an insanely detailed and totally amazing tutorial. Totally epic!Lebna
A
3

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

Attic answered 4/8, 2014 at 7:33 Comment(3)
Yep, the technology (at least that real-time approach) is only 2 years old, so it will be pretty difficult - if not impossible - to make an applicable solution for mobile platforms. Though I think that some kind of simplified technique may be found. First of all, you may begin to experiment with shaders for G-buffer. Actually, I believe that just by averaging normals in surface normal G-Buffer you may get the picture that will be very similar to the one above. Of course if you want to use normal maps then to exclude false edges you will need another G-buffer without normal maps.Attic
Honestly, it is not a rocket science. You just need a time to experiment.Attic
Some time ago I have seen an excellet article about using extra geometry features to make rounded edges and corners (and a lots of other tricks). Unfortunately I forgot where I have seen it. But the core idea was the same as yours. Here is similar article.Attic
H
1

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.

Hekate answered 1/8, 2014 at 22:58 Comment(2)
Hi Peter, LOD is completely built-in to all modern 3D engines, and is totally automatic. It's really not relevant to the question at hand.Lebna
Well... kinda -- Unity3d specifically allows for the setting of multiple LOD meshes with the Pro-version's LOD feature: docs.unity3d.com/Manual/LevelOfDetail.html thought I'd see if I could save you some tris, or maybe someone without Unity Pro. I'm curious if there's a shader-based solution.Hekate
S
0

We were able to accomplish beveled cubes for our game WorldToBuild. The key is really that you can go ahead and make the beveled model, then just move the vertices in groups.

So in short, all I had to do to achieve the effect was:

  • Create a beveled cube (I used Blender).
  • Find what vertices you're going to move in each direction by their position from center.
  • Calculate out the beveled edges, and set the exact size.

I wrote an article about it here. Scroll to the bottom of the article if you just want to know the process:

https://www.linkedin.com/pulse/coding-resizable-beveled-cubes-unity-richard-christley

Sacchariferous answered 24/3, 2019 at 3:21 Comment(2)
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.Columbous
Hi @BhargavRao . The answer does, precisely, include the essential parts of the answer here.Lebna

© 2022 - 2024 — McMap. All rights reserved.