Blurry alpha maps on planes

Hello,
I have a glb model with a part that looks like this:

As it is a plane, I have to set

side: THREE.DoubleSide

on the material for the texture to appear on both sides.

The expected look is something like this:

But I get this:
SniĢmek obrazovky 2024-01-11 v 10.27.59

As the model is meshopt compressed, I have to call this to be able to assign any map:

const modelMaterial = node.material;
texture.repeat.copy(modelMaterial.map.repeat);
texture.offset.copy(modelMaterial.map.offset);

I tried to play around with setting different repeat values for hours but the texture either appears cropped, misaligned or otherwise blurry. I get the best results without setting the repeat value at all.

I use alpha maps on different parts of the mesh for hair but they are not planes and it works well. I have one more mesh part that is a plane (eyelashes) and they appear blurry as well but they are so small that itā€™s almost invisible and it doesnā€™t bother me that much.
The map resolution is 2048x2048 and I even tried to increase the size with no effect. I believe the UV mapping is done correctly as it looks fine in blender. I donā€™t mind the occasional stretching but the texture canā€™t be blurry (altough I understand there may be some limitations in the resolution).

Any suggestions please? Thanks in advance.

Meshopt does a lot of stuff under the hood with the goal of making it smaller. It may be converting/downsampling your textures. It may be quantizing your UV coordinates.

What meshopt parameters are you using?

Can you try loading the model without running it through meshopt and see if the problem goes away?

I tried to display the mesh without compression and the issue persists.

Hmm ok. perhaps you can load it up in a glitch like this: Glitch :ļ½„ļ¾Ÿāœ§

and we can experiment with it?

You can ā€œremixā€ that glitch, then replace the stuff in test.js with your gltfLoader.load( and texture setupā€¦

There seems to be an error on that prevents me to open the page and remixā€¦

Hmm ok. If it isnā€™t working in chromeā€¦ Well perhaps you can reproduce your problem in a codepen or something?

I tried to set up a pen but I struggle importing the file due to crossorigin issuesā€¦ I never made a codepen with glb files before so I donā€™t know of good places to host modelsā€¦

The pen is here, take a look, but itā€™s a blind copypasta from my local setup. Itā€™s highly possible there are some mistakes or missing code as I canā€™t see what Iā€™m doing. Thanks!

codepen

Ahh right. codepen asset uploading is a paid feature. :frowning:

I copied your stuffs over to glitch and messed with it and got it looking close to what you want:

Maybe try in chrome, make a free account on glitch, then go to this link?

Your code is in test.js and I uploaded your assets to the ā€œassetsā€ tab, and grabbed their URLs for loading in test.js

To make it look like what you wanted, I had to add:

      alphaMap.repeat.set(1, 4);   //Make the texture repeat 4x on the V axis
      alphaMap.wrapS = alphaMap.wrapT = THREE.RepeatWrapping; // Enable repeat wrapping on texture, otherwise it will only repeat the edges of the texture...

By the way, you may not have to set this stuff up manually and instead, you can export the GLB with the textures and UVs set up in your modelling tool. What modeller are you using? Blender supports exporting GLB with textures embedded etc.

With some more tweaks:

Looks like I wasnā€™t patient enough playing with different values as I interpreted all of them as ā€œbadā€ - in my setting te camera is more zoomed out and it it didnā€™t occur to me that it would be a good idea to zoom in to actually see whatā€™s going on. So now it looks very good when zoomed in and weird when zoomed out, so Iā€™ll probably rethink the implementation.
Anyway thank you very much for your time and help. I really appreciate it!

1 Like

yeah I tried some different filtering for ā€œminFilterā€ which is what happens when a texture is zoomed out, but NearestFilter looked really weird. There are some other things worth trying like disabling mipMapping or using custom mipmaps.
Are you trying to duplicate a reference image from a 3d model?

Yes, I try to match the materials in three as much as possible to the look of the model in blender. Iā€™m aware of some limitations and your suggestions for little tweaks are helpful.

alphaMap.generateMipmaps = false

seems to help a little but I decided to go for a different alpha map with slightly thicker hair strands and it looks a little better.
Thank you!

1 Like