Sign in to follow this  
yorke

[Solved] Different uScale values for same material

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

image.png.c1ea74468355946347502d21824946fc.png

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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?

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 :P

Many thanks jerome, that did the trick, tnx for your time

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.