saltemishel Posted July 12, 2017 Share Posted July 12, 2017 Hi All, It appears that .getHeightAtCoordinates() doesn't correctly when I'm using .convertToFlatShadedMesh() Without converting to flat shaded mesh https://www.dropbox.com/s/fydn2uq78ek43qm/Screenshot 2017-07-12 10.50.08.png?dl=0 After converting to flat shaded mesh, the boxes starts to float everywhere https://www.dropbox.com/s/982wiz0rnjfshvm/Screenshot 2017-07-12 10.52.03.png?dl=0 Can this be fixed? Or is there a way for my to make the ground flat shaded without using .convertToFlatShadedMesh()? Thanks. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 12, 2017 Share Posted July 12, 2017 Hello I'll be happy to fix it if you can repro it in the PG..Thanks a lot:) Quote Link to comment Share on other sites More sharing options...
saltemishel Posted July 12, 2017 Author Share Posted July 12, 2017 Hi @Deltakosh, I've modified this playground to flatshade it. http://www.babylonjs-playground.com/#1LEGTP Modified version: http://www.babylonjs-playground.com/#1LEGTP#3 Thanks! Quote Link to comment Share on other sites More sharing options...
jerome Posted July 12, 2017 Share Posted July 12, 2017 When you convert the ground to a flat shaded one, this adds a lot of new vertices what modify the ground geometry (actually it's no more a real ground mesh... but something else). As the method getHeightAtCoordinates() relies on the knowledge of the geometry to be the fastest possible, it doesn't work anylonger with a newly computed geometry. I can't check this before weeks ... and it's not that simple to modify to work a flat shaded mesh, but I'll have a look when I am back. For now, please just consider that the method getHeightAtCoordinates() only works with un-modified grounds (still works with rotated or translated grounds though) Quote Link to comment Share on other sites More sharing options...
saltemishel Posted July 12, 2017 Author Share Posted July 12, 2017 Hi Jerome, Thanks for the info, do let me know when you have the fix for this. Thanks! Quote Link to comment Share on other sites More sharing options...
Convergence Posted July 12, 2017 Share Posted July 12, 2017 Maybe you can duplicate the grondMesh before flatshading() it, and perform the getHeightAtCoordinates() on the smoothshaded mesh, while its hidden? Pryme8 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 12, 2017 Share Posted July 12, 2017 Agree with @Convergence: Keep the groundMesh, call setEnabled(false) on it and do your testing with it Quote Link to comment Share on other sites More sharing options...
jerome Posted July 12, 2017 Share Posted July 12, 2017 smart idea or use a ray and its intersection with the ground (old way) Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 12, 2017 Share Posted July 12, 2017 Couldn't he just do the hit tests on a separate ground that was not converted and has its visibility to 0; while just displaying the flat shaded version? *Edit* Dumb that's what @Convergence suggested... I'm late to the party. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 12, 2017 Share Posted July 12, 2017 [Wingnut hugs @Pryme8 for his warm-hearted humility] Ok... let's see... what needs my annoying touch, here. Umm... When a heightMap ground gets converted to flat shaded, DO the added verts/indices/normals/etc... get appended-onto the original vertexData arrays? OR... do the new verts/indices/normals/etc... get inter-mixed with the original v-data? Or maybe... shifted into the original v-data? I suppose I could go look at code. https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.mesh.ts#L1600 Okay, that just made my brain hurt. My question is... WHY is getHeightAtCoordinates() giving bad values when mesh is flat shaded? Is the problem ACTUALLY happening... due-to the way we are converting to flat shaded? hmm. And... IF getHeightAtCoordinates() has a minor problem, I bet we can adjust it before @jerome gets back from vacation, and give him a happy surprise. Quote Link to comment Share on other sites More sharing options...
jerome Posted July 12, 2017 Share Posted July 12, 2017 it returns bad values after flat shading because the method knows the initial geometry (that's why it's fast, no need for ray intersection). When flat shading, a new array is built, containing new vertices being in between the initial ones ... so another different geomety the method doesn't know anythting about. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 12, 2017 Share Posted July 12, 2017 Why don't we have a flat shade option in the standard shader? Manipulating the mesh in order to make it flat shaded seems counter intuitive to me when this could simply be handled with its fragment shader.https://www.gamedev.net/articles/programming/graphics/the-basics-of-glsl-40-shaders-r2861 There is a section on a flat shader on this page. Quote Link to comment Share on other sites More sharing options...
saltemishel Posted July 13, 2017 Author Share Posted July 13, 2017 Ya, I think converting the whole mesh to flat feels a bit overkill too. In the meantime, I try the options to have 2 different mesh and doing the ray intersection way too. Thanks for the suggestions Quote Link to comment Share on other sites More sharing options...
sable Posted July 13, 2017 Share Posted July 13, 2017 9 hours ago, Pryme8 said: Why don't we have a flat shade option in the standard shader? Manipulating the mesh in order to make it flat shaded seems counter intuitive to me when this could simply be handled with its fragment shader. Seems like it would be fairly simple to do this. Assuming that std derivatives are supported you can implement it like this. Example playground with shader version on the left and convertToFlatShadedMesh on right: https://www.babylonjs-playground.com/#E0PJHQ Pryme8 and Wingnut 2 Quote Link to comment Share on other sites More sharing options...
saltemishel Posted July 13, 2017 Author Share Posted July 13, 2017 @sable sorry about the noob question, I'm not sure if I'm missing anything, though you've already show me the playground. It looks like this after I implement this material, maybe I'm doing it wrong? https://www.dropbox.com/s/w4bx67e9gd36h6k/Screenshot 2017-07-13 11.34.12.png?dl=0 this is what I did: this.mesh = BABYLON.Mesh.CreateGroundFromHeightMap("ground", "media/graphics/sprites/heightmap.jpg", 256, 256, 50, 0, 50, wgl.game.currentScene, false, this.successCallback.bind(this)); var mat = new BABYLON.CustomMaterial("cm", wgl.game.currentScene); mat.Fragment_MainBegin( "vec3 U = dFdx(vPositionW);" + "vec3 V = dFdy(vPositionW); " + "vNormalW = -normalize(cross(U,V));" ); this.mesh.material = mat; Ow it says Uncaught TypeError: BABYLON.CustomMaterial is not a constructor Edit: I implemented this library, the error is now gone but it's still looking like in the screenshothttps://preview.babylonjs.com/materialsLibrary/babylon.customMaterial.min.js Quote Link to comment Share on other sites More sharing options...
sable Posted July 13, 2017 Share Posted July 13, 2017 I think it's only been added to babylonjs in the last month or so. Quote Link to comment Share on other sites More sharing options...
saltemishel Posted July 13, 2017 Author Share Posted July 13, 2017 ow, is it supported in babylon 2.5? Quote Link to comment Share on other sites More sharing options...
sable Posted July 13, 2017 Share Posted July 13, 2017 I'm assuming you probably can't just drop it in to 2.5, but I'm not sure. Does modifying the material (such as adding a diffuse colour) still do what it should? Quote Link to comment Share on other sites More sharing options...
saltemishel Posted July 13, 2017 Author Share Posted July 13, 2017 hmm.. nope just change the colour but still the same. Quote Link to comment Share on other sites More sharing options...
sable Posted July 13, 2017 Share Posted July 13, 2017 Yeah, pretty sure you'll need to move to version 3. Quote Link to comment Share on other sites More sharing options...
saltemishel Posted July 13, 2017 Author Share Posted July 13, 2017 ow okie, will try that out then, thanks. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted July 13, 2017 Share Posted July 13, 2017 11 hours ago, sable said: Seems like it would be fairly simple to do this. Assuming that std derivatives are supported you can implement it like this. Example playground with shader version on the left and convertToFlatShadedMesh on right: https://www.babylonjs-playground.com/#E0PJHQ We should just add this to the standard shader now. That will fix this whole topic then correct? As far as I can see it looks to have the same effect and then the vertex data will not have changed. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 13, 2017 Share Posted July 13, 2017 Good idea I added an issue to tackle it for 3.1: https://github.com/BabylonJS/Babylon.js/issues/2520 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 13, 2017 Share Posted July 13, 2017 Done: https://www.babylonjs-playground.com/#U0L5NA jerome, Pryme8 and sable 3 Quote Link to comment Share on other sites More sharing options...
saltemishel Posted July 14, 2017 Author Share Posted July 14, 2017 Cool, so is the new method using the flat shader or is it converting to flat meshes but using another method? Thanks~! 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.