yorke Posted October 12, 2017 Share Posted October 12, 2017 Hi all, in order to improve the performance of a scene built dinamically, I'm facing this problem: is it possible to have one material, to which is applied one texture, using different uScale e vScale depending on the mesh to which that material is applied? I need this because I have a 3d model of a city with many street segments, each segment having quite different length from each others. Now, those segments are textured: if I use the same uScale for them all, the road texture would appear "stretched" or "shrinked" depending on the length of the segment on which the material is applied, while I want it to appear uniform. I can bypass this problem assigning one different material for every street segment and setting uScale according to its length, but in the end the amount of materials and textures grows dramatically and scene performance falls down at 3 - 4 fps. Any ideas of how reducing the number of materials? Those are the actual stats for a mid-sized city: Total meshes 7309 - Total vertices 170688 - Total materials 7309 - Total textures 3834 Any ideas on how to solve this? Thanks in advance, cheers Quote Link to comment Share on other sites More sharing options...
jerome Posted October 12, 2017 Share Posted October 12, 2017 If you're using two materials relying on the same texture, it doesn't really change the performance. Quote Link to comment Share on other sites More sharing options...
yorke Posted October 12, 2017 Author Share Posted October 12, 2017 Ok for 2 materials, but 7k materials really don't affect performances? On another thread i read a user having problems with 2k materials, and he was told of decreasing their amount. Otherwise, what could cause the performance problem, based on the numbers I posted and your experience? Too many meshes? Vertices? Meshes are basically Ribbons for streets and ExtrudePolygon for buildings. It's impossible for me to replicate this in a PG (it also would crosspost on open street map site), so I try to paste a screenshot of the scene in wireframe. No other computations are done, after having built the scene. 6 fps in wireframe, fps decrease at 3-4 with solid rendering Quote Link to comment Share on other sites More sharing options...
jerome Posted October 12, 2017 Share Posted October 12, 2017 yep, 7K materials must really impact the perfs, you're right. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 12, 2017 Share Posted October 12, 2017 The material count is directly linked to the draw calls. So if you have 7000 materials you could end up with 7000 draw calls which is FAR too much even for advanced gfx cards I really suggest that you merge meshes using the same (or compatible) materials to reduce your draw calls Quote Link to comment Share on other sites More sharing options...
yorke Posted October 12, 2017 Author Share Posted October 12, 2017 First of all thanks to both of you for your quick replies 2 minutes ago, Deltakosh said: The material count is directly linked to the draw calls. So if you have 7000 materials you could end up with 7000 draw calls which is FAR too much even for advanced gfx cards I really suggest that you merge meshes using the same (or compatible) materials to reduce your draw calls The problem is just here: I don't know how to use the same material for all road segments, so I'm using a material per segment. Basically all roads would have to use the same material (texture is the same for them all), but I don't know how to let segment A use a different uScale than segment B, in order to not stretch or shrink texture appearance according to segment length. E.g. if segment A is longer 10 times than segment B, and they use the same material and so the same uScale, texture results larger 10 times on segment A than on segment B. Is there another way to draw repeated textures on a surface not using uScale/vScale? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 13, 2017 Share Posted October 13, 2017 In this case you should not use the uScale/vScale from the texture. You should leave it to 1 and instead update the uv coordinates of the mesh Quote Link to comment Share on other sites More sharing options...
jerome Posted October 14, 2017 Share Posted October 14, 2017 If you use ribbons, you can customize your own UVs with the optional parameter uvs : http://doc.babylonjs.com/classes/3.0/meshbuilder#static-createribbon-name-options-scene-rarr-mesh-classes-3-0-mesh- Quote Link to comment Share on other sites More sharing options...
yorke Posted October 16, 2017 Author Share Posted October 16, 2017 Tnx for your suggestion Jerome. I tried to use those options (I didn't know them), but they seem to work for BABYLON.MeshBuilder.CreatePolygon but not for BABYLON.MeshBuilder.CreateRibbon. Here are two PGs in which I tried to set UVs to repeat texture on a 10x10 grid: For Polygons it works: http://playground.babylonjs.com/#4G18GY#8 For Ribbons, it seems to not work, grid still appears to be 1x1: http://www.babylonjs-playground.com/#165IV6#83 Am I missing something? Quote Link to comment Share on other sites More sharing options...
jerome Posted October 16, 2017 Share Posted October 16, 2017 yep : http://www.babylonjs-playground.com/#165IV6#84 the sideOrientation values, like the frontUvs and backUvs ones, because they build the internal ribbon geometry, must declared at construction time. The ribbon update method can only change then the vertex positions, colors or uvs. yorke 1 Quote Link to comment Share on other sites More sharing options...
yorke Posted October 16, 2017 Author Share Posted October 16, 2017 Woah finally I got it working... I got crazy because I was using BABYLON.Mesh.CreateRibbon instead of BABYLON.MeshBuilder.CreateRibbon and I couldn't figure why pathArray[0] was undefined, what a n00b Many thanks jerome, that did the trick, tnx for your time 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.