Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use automatic angle-based smoothing for CSG faces instead of manual per-node smoothing #1862

Open
Calinou opened this issue Nov 19, 2020 · 5 comments

Comments

@Calinou
Copy link
Member

Calinou commented Nov 19, 2020

Describe the project you are working on:

The Godot editor 🙂

Describe the problem or limitation you are having in your project:

Designing a nice-looking CSG prototype takes longer than it should, since you have to manually mark all curved surfaces as smooth to get a good appearance.

On top of that, marking CSG nodes as smooth is an all-or-nothing process. For example, you can't have only certain polygons of a CSGPolygon be marked as smooth.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

Automatic smoothing based on angle could be used to smooth out curved surfaces automatically. This way, the user would never have to fiddle with smoothness settings while designing their level.

In Blender, this is known as Auto Smooth (make sure to mark the whole object as smooth too):

image

Also, most level design tools provide this feature in an automatic manner (such as Cube 2's map editor):

lerpangle 44 (the default):

image

lerpangle 89:

image

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

  • Add a project setting that controls the maximum CSG smoothing angle (between 0 and 180). The default value should probably be 30 (the same as Blender). If it's set to 0, automatic face smoothing is disabled and all faces will be considered sharp. If it's set to 180, automatic face smoothing is always enabled. (This can be useful to improve performance when only using unshaded meshes for CSG.)
    • If the angle limit is 0 or 180, the smoothing calculation process is skipped since no faces (or all faces) will be considered smooth.
  • Remove the Smooth Faces property on individual CSG nodes.

This angle calculation will likely slow down CSG mesh generation a bit. If you use CSG in a real-time scenario (which isn't recommended), you can still set the maximum angle to 0 to skip the automatic smoothing calculations.

If this enhancement will not be used often, can it be worked around with a few lines of script?:

No, as this is core CSG functionality.

Is there a reason why this should be core and not an add-on in the asset library?:

See above.

@winston-yallow
Copy link

This sounds really good to me, I only have one question: Couldn't this setting be done per CSG mesh? (probably only using the value of the "root" CSG node and showing a warning if enabled on a non root node). That way different CSG meshes could have different setting.

But regardless of this it would be really helpful to have this.

@Calinou
Copy link
Member Author

Calinou commented Nov 19, 2020

@winston-yallow I'm not sure how useful it would be to have this setting on a per-node basis. This is why I suggested making it a project setting instead. Also, I'm worried that intersections with different CSG nodes could cause conflicts or performance issues.

@madmiraal
Copy link

First, it's worth pointing out that CSG Smoothing is on by default. Compare the front row meshes with the back row meshes, which have had the smoothing disabled:
CSGSmoothing

CSG smoothing simply changes the faces' vertex normals. I think what you're after is changing the default number of sides used when creating a shape. Currently these are inconsistent (as are the default sizes of the shapes):

  • CSGSphere: Y-axis: 12, X/Z-axis: 6
  • CSGCylinder: Y-axis: 8
  • CSGTorus: Y-axis: 8, Ring-axis: 6

These would equate to Cube 2's lerpangle:

  • 6 sides: 30°
  • 8 sides: 45°
  • 12 sides: 60°

There may be an argument for making these consistent and creating a editor setting for adjusting the default.

Finally, bear in mind that the Blender Auto Smooth is for display within Blender only, to obtain that level of smoothing on exported models requires adding subdivision modifiers and support loops i.e. increasing the number of faces i.e. sides.

@Jummit
Copy link

Jummit commented Nov 20, 2020

Finally, bear in mind that the Blender Auto Smooth is for display within Blender only,

Blenders Auto Smooth is a similar to the edge split modifier, it splits all edges above a certain angle, making them sharp.

@Calinou
Copy link
Member Author

Calinou commented Nov 20, 2020

@madmiraal I forgot to mention that CSGCylinder is indeed smoothed by default, but that's not the issue I had here.

The issue I have right now is mainly with CSGPolygon nodes. Here's an example:

Smooth Faces disabled

image

Smooth Faces enabled

image

I'd like something akin to CSGCylinder where the top and bottom faces aren't smoothed, and only the side sections are:

image

However, I'd also like to have an angle limit so that sharp angles are never smoothed in CSGPolygon.

Edit: Looking at it again, it seems the top and bottom faces are actually sharp. I think there's a bug in the smoothing of side faces in CSGPolygon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants