Jump to content

Mesh part smooth part flat shading


Stalker
 Share

Recommended Posts

Hi!

 

I'm trying to figure out how to set part of the mesh shading as smooth and part of it as flat.

 

A quick sample on an image bellow rendered with Blender (from left to right):

  • Mesh with smooth shading
  • Mesh with flat shading
  • Mesh with mixed shading (achieved with edge split modifier) <- what I want

Ideally shading type could be set per vertex group or per material.

post-17157-0-96694200-1447626956.png

Link to comment
Share on other sites

Hi.

From what I know, this is achieved through normal setting for each vertex.

At the vertex (or edge) common between 2 or more faces, the normal can be set differently.

 

With flat shading, the normal of vertex is just orthogonal to the face. Giving your gray sharp change from one face to the other (assuming faces are not parallel).

 

With smooth shading, the normal at vertex is kind of averaged with the normal of the vertex of the neighbour face (giving a smooth transition at the edge).

When the pixel is not close to edge, the fragment shader is interpolating the normal between all vertex of the face.

This gives smooth gray shading when moving on face and smooth transition as well when crossing face edge. Goal.

 

With edge split modifier, it a mix of both. The modifier check the angle between faces at the edge, then 2 cases: case 1: the angle is small enough to get almost parallel face then get normal as flat. case 2: the angle is high than threshold, so you get different normal on the vertex shared between faces. (should get a bit more complex when more than 2 faces involved on a single vertex, but you probably get the picture).

 

IN BJS, a face is 3 vertex, each one can have its own normal (I mean independent normal from neighbour face vertex).

This is how you can model smooth/flat shading in your babylon mesh.

As far as I know, this should not be linked to the material used (material will just render as needed by normal definition in the geometry of the object).

 

I you have this setting done as you like in a blender object, then the normal should be set as required. You can probably export to BJS and get your flat/smooth rendering as well (any basic material should do).

Link to comment
Share on other sites

@DK and JCPalmer, what I wanted was really the third options on my image which is a mix of both.  (updated to make my question clearer for future readers) 

 

@G'kar, Thanks for the explanation! I tried exporting my model and normals weren't set as they should (that's why I came here). Tried again with a new exported Blender file (in a BJS Sandbox) and it works. Looks like I'll need to double check my code and Blend file.

 

Thanks to all!

Link to comment
Share on other sites

  • 8 months later...

Hi together,

sry for answering in this old thread, but I have exactly the same problem. In Blender there is a switch to enable "Autosmooth", which uses smooth or flat shading according to the angle between the faces. But the Babylon exporter is ignoring this setting. I think the normals should be all right if I create a new basic cylinder and export it directly to a .babylon file without modifying anything. If you create a cylinder in Babylon itself, it is exactly this mixed shading I desire. Is there something I am missing? Maybe some global setting in Blender or Babylon to enable mixed shading?

Thanks

 

 

Link to comment
Share on other sites

The same question on my side ...

after importing an OBJ-File I only can apply a flat shading although the OBJ has smoothing-groups in it.

Would be great to be able to convert to "smoothShaded" meshes.

Link to comment
Share on other sites

1 hour ago, V!nc3r said:

In Blender you just have to apply an edge split modifier, and all your sharp and smooth faces should be exported correctly.

You're talking about .babylon-files, correct? So the ObjFileLoader is not possible to achieve that smoothing, is it?

Link to comment
Share on other sites

thanks for the info.

This is what I've also read ... and unfortunately it looks like that feature won't come in anymore because the extension is pretty old right now :-(

For me actually it is the solution to model my meshes with 3ds max or blender to export it as a babylon file. *urgs*

Link to comment
Share on other sites

Yeah, you can write books about it.
http://blender.stackexchange.com/questions/6425/keep-sharp-edges-when-using-subdivision-surface

 

99% of the models you find here in the forum are from online shoping places, so the models are 10x more subsurft then its actually needed, also the auto-edge slip auto remove this and than are highly used. If you know, a better workaround on anything, feel free to share!  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...