Stalker Posted November 15, 2015 Share Posted November 15, 2015 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 shadingMesh with flat shadingMesh with mixed shading (achieved with edge split modifier) <- what I wantIdeally shading type could be set per vertex group or per material. Quote Link to comment Share on other sites More sharing options...
G'kar Posted November 16, 2015 Share Posted November 16, 2015 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). Stalker 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 16, 2015 Share Posted November 16, 2015 Hello! by default bjs will smooth normals. But you can ask for flat shading (see sphere in the middle there: http://www.babylonjs.com/?FOG) To get this, just call mesh.convertToFlatShadedMesh(). Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted November 16, 2015 Share Posted November 16, 2015 The request can also be done from Blender, on the data properties for the mesh. There is a Flat shading checkbox Quote Link to comment Share on other sites More sharing options...
Stalker Posted November 16, 2015 Author Share Posted November 16, 2015 @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! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Steffen Posted July 29, 2016 Share Posted July 29, 2016 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 Quote Link to comment Share on other sites More sharing options...
jellix Posted July 29, 2016 Share Posted July 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted July 29, 2016 Share Posted July 29, 2016 In Blender you just have to apply an edge split modifier, and all your sharp and smooth faces should be exported correctly. Steffen 1 Quote Link to comment Share on other sites More sharing options...
jellix Posted July 29, 2016 Share Posted July 29, 2016 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? Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted July 29, 2016 Share Posted July 29, 2016 Oops, yes ^^ It say here that smoothing groups aren't yet supported in obj loader https://doc.babylonjs.com/extensions/OBJ#not-supported-currently Quote Link to comment Share on other sites More sharing options...
jellix Posted July 29, 2016 Share Posted July 29, 2016 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* Quote Link to comment Share on other sites More sharing options...
Steffen Posted July 29, 2016 Share Posted July 29, 2016 I misunderstood the modifier and thought there should be a better solution - so I haven't tried it.....well, it works like a charm. So easy and fast. Thank you! Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted July 29, 2016 Share Posted July 29, 2016 @jellix why not using fbx or dae format rather than obj if you want to avoid .babylon ? Quote Link to comment Share on other sites More sharing options...
jellix Posted July 29, 2016 Share Posted July 29, 2016 fbx is possible!?!? wow, that info is new to me. I have to test it right now. Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted July 29, 2016 Share Posted July 29, 2016 I don't know, i personnaly only use .babylon... Sorry if i create false hope Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 29, 2016 Share Posted July 29, 2016 i'm using blender since 2.49 already 10 years, time is running so fast. Quote Link to comment Share on other sites More sharing options...
jellix Posted July 29, 2016 Share Posted July 29, 2016 lol - no problem, but THAT would be nice if it would be possible (it isn't, as I just tested). Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 29, 2016 Share Posted July 29, 2016 Quote Link to comment Share on other sites More sharing options...
V!nc3r Posted July 29, 2016 Share Posted July 29, 2016 Using subsurf modifier for realtime application seems to be... violent ^^ The edge crease in blender don't exactly set sharp or smooth ; like the tooltip said, it's "weight used by subsurf modifier". Quote Link to comment Share on other sites More sharing options...
Nabroski Posted July 29, 2016 Share Posted July 29, 2016 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.