Jump to content

Best way to disable a type of texture for all materials


demonixis
 Share

Recommended Posts

Hi,

 

For performances reasons on mobile devices, I need to disable some textures at runtime to get a good FPS rate. In BABYLON.Scene.js  there is a parameter to disable all textures but it's don't what I need. I need to disable only some textures not all.

 

I haven't found a method to do that. A good way could be to easily remove a specified uniform define. We can add some parameters in Scene.js to disable a specified type of texture. 

if (this._scene.texturesEnabled) {        if (this.specularTexture && this._scene.specularTextureEnabled) { }}
Is there a better method ? What do you think about that ? If you want I can send a pull request that do this job :)
 
Yann.
 
Edit: I send a pull request which has been merged, we can achieve this by using static parameters:
 
// Disable bump and specular texture for all Standard MaterialsBabylon.StandardMaterial.BumpTextureEnabled = false;Babylon.StandardMaterial.SpecularTextureEnabled = false;

@Deltakosh: Thanks for merging ;)

Link to comment
Share on other sites

Hi.  Didn't all this flag checking add a ton of processing time to StandardMaterial?  Why not put in CreateScene()...

 

   if (client == crappy phone) {

         crappyPhone = 1;

   }

 

And then later...

 

     if (!crappyPhone) {

         add some texture

     }

 

   etc.

 

It seems to me that the framework is having to do a bunch of extra work, when the scene author should be doing the check-for-crappy-device in their CreateScene() function.  Something is not good or right, here, it seems.  We shouldn't be slowing EVERYONE down... just so an author can kiss the butt of a slow mobile device.  Maybe I am mis-interpreting this,  but I see tons of extra testing in this modifed version of standardMaterial.  I sure hope ALL OF US don't need to use this "heavy version" of standardMaterial.  That would seem terrible, and if my thoughts are correct, my vote is to reject this idea/modification.

Link to comment
Share on other sites

Hi, 

 

I understand your point of view but I can assure you that there is not so much to test it in the code and are not these tests that will impact the performance of an application. 

 

In the StandardMaterial class there are already several tests that are done and I've just added a test by texture. I let you look at the code so that you can see that this is really not heavy. 

 

I suggest you to read StandardMaterial class and you'll see that there are a lot of tests that are done for each textures for each frames. So if you're using only one diffuse texture you may think that this class is to heavy for you right ? These tests are really simple.

Link to comment
Share on other sites

I agree with demonixis, for each texture you have on your material, there is only 1 more boolean to test.

 

The best part is, since JavaScript has lazy evaluation on booleans, whenever you have

this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled

If this.ambientTexture === undefined, the evaluation will stop here and BABYLON.StandardMaterial.AmbientTextureEnabled will not even be tested.

Link to comment
Share on other sites

Hi gang.  I understand, and thanks for the clarification and added knowledge for me.  Yes, for one material, there is not too much added overhead.  But in a 400 material big scene... that is where my concern lies.  That info about lazy boolean evaluation is VERY good news, thanks for that.

 

In other projects, though, I have seen flags get completely out of control.  Although this is a ridiculous example, I have seen things like...

 

if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled && this.isInFrustum(scene.activeCamera) && this.isLit() && !("BlackAndWhite" in this.tags) && this.isEnabled() && this.isVisible() && this.LOD > this.LodTexturingThreshhold && !daughterPregnant) { ... }  ;)

 

We just can't let things get out of control. I sure don't want to stand in the way of progress and innovation... but I have seen ugly things.  Let's be careful.   :)  Thanks again for the info and reassurances, friends.

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...