Coder Social home page Coder Social logo

Comments (15)

pfcDorn avatar pfcDorn commented on May 29, 2024

Hey,
that is as intended. At line 505, it will only be created when the previous created texture has other sampler settings (like filterMode or WarpMode).
When they have both the same sampler settings, it's likely a bug.

from unitygltf.

umeraamir-arthur avatar umeraamir-arthur commented on May 29, 2024

Can we just change sampler settings of first one and assign it to the second one? As the first one (I suppose) has no use here after...

from unitygltf.

pfcDorn avatar pfcDorn commented on May 29, 2024

So the first created Texture is not in use? Maybe you can share the file here?

from unitygltf.

umeraamir-arthur avatar umeraamir-arthur commented on May 29, 2024

It is the same case for any GLB it'll load the texture twice.... First one has only 1 reference which is (I guess) ImageCache list... and the second one is assigned to materials and has a proper use
image

from unitygltf.

pfcDorn avatar pfcDorn commented on May 29, 2024

i will check! that's very likely a bug :)

from unitygltf.

umeraamir-arthur avatar umeraamir-arthur commented on May 29, 2024

It is a very old bug since first build which I once resolved as well but wasn't able to share at that time unfortunately.

Basically, the problem is that when you load any GLB from code using GLTFComponent in a build and then if you use memory profiler by Unity then it'll show that every texture is loaded 2 times. First texture has only 1 reference and the second has proper use of it. Also if you use CPU profiler then you can see big spikes when a texture is loaded because it once load a texture through LoadImage() and then Object.Instantiate() on same frame. Above mentioned places are the exact points which I found after profiling.

Hope these information help.

from unitygltf.

pfcDorn avatar pfcDorn commented on May 29, 2024

Still needs some tests, but should prevent this behaviour now: 73f7b66

from unitygltf.

umeraamir-arthur avatar umeraamir-arthur commented on May 29, 2024

Hi @pfcDorn... Thankyou for sharing the implementation

I managed to brought back my implementation of the issue.

I would prefer older implementation because of many reasons

  • If isFirstInstance is null then there might be issues to call Object.Instantiate(null) in that case
  • isFirstInstance can't be null because of if (!source) return; at line 427
  • No if-else needed for Object.Instantiate so it is a simpler version of it
  • I've tested this on few test cases and was working fine on previous version

Here is the commit I made.

from unitygltf.

pfcDorn avatar pfcDorn commented on May 29, 2024

With your solution you just removed completly the support for multiple sampler settings on a single texture. In Unity we need to duplicate a texture when we have in the gltf different sampler settings for the same texture.
Lets say we use Texture A in Material 1 and in Material 2. In Material 1 the texture will have WrapMode Repeat, and in Material 2 it will set to Clamp. So in this case we must dublicate the texture on import to support this. Otherwise one material will not be displayed correctly.

from unitygltf.

umeraamir-arthur avatar umeraamir-arthur commented on May 29, 2024

Yes but this statement is true for both of the above solutions I suppose.

The issue was that if you've 1 texture and 1 material it was still loading the texture twice.

from unitygltf.

pfcDorn avatar pfcDorn commented on May 29, 2024

thats the reason why i added the isFirstInstance, so it only create the texture twice or more when it's needed (in case of multiple sampler states)

from unitygltf.

umeraamir-arthur avatar umeraamir-arthur commented on May 29, 2024

But I think isFirstInstance might always be true because of the lines on 429 and 430 ???

var source = _assetCache.ImageCache[sourceId];
if (!source) return;

Which means matchSamplerState on line 491 will always be false

from unitygltf.

umeraamir-arthur avatar umeraamir-arthur commented on May 29, 2024

@pfcDorn did you manage to find a work around?

from unitygltf.

pfcDorn avatar pfcDorn commented on May 29, 2024

line 430 is only false (null) when the texture can't be created in line 427. So don't worry. Don't get confused with ImageCache and TextureCache here ;)

from unitygltf.

umeraamir-arthur avatar umeraamir-arthur commented on May 29, 2024

Oops! I was missing a point there... Thankyou

from unitygltf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.