cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
5.49k stars 1.58k forks source link

Texture nearest filter breaks batching #17225

Open boruok opened 3 days ago

boruok commented 3 days ago

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:

  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)

to reproduce

  1. check button in inspector
  2. assign texture with filter is set to nearest
  3. run scene
  4. check drawcall number (increased to 3 and depends how many buttons you have)

Minimal reproduction project

NewProject.zip

minggo commented 3 days ago

check drawcall number (stays at 2)

It is 3 in my case.

boruok commented 3 days ago

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.

image

minggo commented 2 days ago

Yep, it is 9 for 4 buttons, but 3 for one button.

So, what's the issue?

boruok commented 2 days ago

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.

minggo commented 2 days ago

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?

boruok commented 2 days ago

@minggo here EXACT steps:

  1. make empty scene (make sure that scene have canvas + camera
  2. add png texture at least 32x32px size to assets folder
  3. add button to scene (under canvas)
  4. click button
  5. assign newly created texture to button (cc.Sprite -> Sprite Frame -> yourtexture)
  6. click button in hearchy to unfold button
  7. click label under button
  8. in label inspector switch cache mode to bitmap
  9. click button in scene
  10. press ctrl + c to copy button
  11. press ctrl + v to paste button
  12. optinally rearrange in button in scene
  13. repeat 7 and 8 step until you get 4 buttons
  14. click play button in top center corner
  15. check drawcall number in bottom left corner (make sure that you clicked stats button if you previewing in editor)

to reproduce issue:

  1. click your created button texture in assets folder
  2. in texture properties switch texture filter mode to nearest(none)
  3. click play button in top center corner
  4. check drawcall number in bottom left corner (make sure that you clicked stats button if you previewing in editor)

preview in editor (bilinear filter) Снимок экрана 2024-06-27 153541

preview in browser (bilinear filter) Снимок экрана 2024-06-27 153521

preview in editor (nearest filter) Снимок экрана 2024-06-27 153327

preview in browser(nearest filter) Снимок экрана 2024-06-27 153343

minggo commented 2 days ago

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.

minggo commented 1 day ago

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.