Texture nearest filter breaks batching
Cocos Creator version
3.8.3
System information
Windows 11 Pro
Issue description
Noticed that if Label parent (Button, Sprite) texture filter is set to nearest leads to breaking batching with increased number of drawcalls (depends on how many nodes you have). But drawcalls stays at 2 if texture filter is set to bilinear
Relevant error log output
n/a
Steps to reproduce
you can use any project and run scene:
- add button to scene
- switch label cache mode to bitmap (for reducing drawcalls)
- run scene
- check drawcall number (stays at 2)
to reproduce
- check button in inspector
- assign texture with filter is set to nearest
- run scene
- check drawcall number (increased to 3 and depends how many buttons you have)
Minimal reproduction project
check drawcall number (stays at 2)
It is 3 in my case.
check drawcall number (stays at 2)
It is 3 in my case.
strange, mine shows 9 drawcalls for 4 buttons. Uploaded example project, maybe i'm doing something wrong.
Yep, it is 9 for 4 buttons, but 3 for one button.
So, what's the issue?
Yep, it is 9 for 4 buttons, but 3 for one button.
So, what's the issue?
4 buttons with texture bilinear filter requires 2 drawcalls (and stays the same) 4 buttons with texture nearest filter requires 9 drawcalls (can increase, depends how many button you have)
isn't that the issue? if you have, for example pixelart texture, which require nearest filter.
I just want to know how to reproduce it. You said
you can use any project and run scene:
1. add button to scene
2. switch label cache mode to bitmap (for reducing drawcalls)
3. run scene
4. check drawcall number (stays at 2)
I did as you said, the the draw call is 3, not 2.
4 buttons with texture bilinear filter requires 2 drawcalls (and stays the same)
Where to show 2 drawcalls?
@minggo here EXACT steps:
- make empty scene (make sure that scene have canvas + camera
- add png texture at least 32x32px size to assets folder
- add button to scene (under canvas)
- click button
- assign newly created texture to button (cc.Sprite -> Sprite Frame -> yourtexture)
- click button in hearchy to unfold button
- click label under button
- in label inspector switch cache mode to bitmap
- click button in scene
- press ctrl + c to copy button
- press ctrl + v to paste button
- optinally rearrange in button in scene
- repeat 7 and 8 step until you get 4 buttons
- click play button in top center corner
- check drawcall number in bottom left corner (make sure that you clicked stats button if you previewing in editor)
to reproduce issue:
- click your created button texture in assets folder
- in texture properties switch texture filter mode to nearest(none)
- click play button in top center corner
- check drawcall number in bottom left corner (make sure that you clicked stats button if you previewing in editor)
preview in editor (bilinear filter)
preview in browser (bilinear filter)
preview in editor (nearest filter)
preview in browser(nearest filter)
Ok, i can reproduce the issue now. I think it is because when i changed filter mode, i didn't save the change, then the preview result didn't take effect.
Thanks for your detail information.
It is caused by this PR: https://github.com/cocos/cocos-engine/pull/9780 to fix issue for pixel style games. But i have not idea how to fix it as the batch mechanism works for all UI elements.