playcanvas / engine

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.32k stars 1.32k forks source link

Static batching does not work when loading scenes additively #2455

Open dexterdeluxe88 opened 3 years ago

dexterdeluxe88 commented 3 years ago

Forum Post: https://forum.playcanvas.com/t/static-batching-for-additive-scene-loading/15069 Sample Project: https://playcanvas.com/project/723629/settings

Description

When additive loading a scene, the static batched models in this scene don't get loaded/rendered.

Steps to Reproduce

  1. Open sample project: https://playcanvas.com/project/723629/settings
  2. Start from "Master" scene
  3. Click "Load Van Scene"
  4. Observe that just 1 van (with dynamic batching) gets loaded, but not the other van (with static batching enabled)
leonidaspir commented 3 years ago

Hi @dexterdeluxe88 ,

The pc.Batcher instance will automatically generate batches once when the pc.Application instance starts rendering.

Loading new scenes, which basically removes and adds entities in the hierarchy won't trigger that again. You can easily do this yourself, after the new scene hierarchy has been appended by running:

this.app.batcher.generate();

https://developer.playcanvas.com/en/api/pc.BatchManager.html#generate

dexterdeluxe88 commented 3 years ago

@leonidaspir calling this.app.batcher.generate() doesn't resolve the issue

leonidaspir commented 3 years ago

It seems the issue isn’t with batching, but with the Static model component flag. There is some optimization there that breaks batching. If you disable that flag batching works as expected:

image

mvaligursky commented 3 years ago

yep, agreed with @leonidaspir - just what I wanted to write. The static flag is not needed for static batching I believe. I'll investigate in due time, but leave it off for now please.

valentincognito commented 3 years ago

I don't know if this is related or not but I noticed that batching and lightmapping doesn't work together at the moment.. I don't know if it's a normal behavior or not. I tried with static flag both enabled and disabled but it doesn't change anything.

If I just call:

this.app.batcher.generate();

I can see the batching working.

If I call batching then baking:

this.app.batcher.generate();
this.app.lightmapper.bake();

The light baking won't work

and finally if I call baking then batching:

this.app.lightmapper.bake();
this.app.batcher.generate();

Batching won't work. Seems like I cannot have the cake and eat it ^_^

Anyone ran into a similar problem ?

mvaligursky commented 3 years ago

@valentincognito - I don't have the answer to this, but it'd be worth investigating in the future. Could you please create a separate issue for it and link it to this one. If you have some simple test project to test on, that'd be fantastic as well.

dexterdeluxe88 commented 3 years ago

yep, agreed with @leonidaspir - just what I wanted to write. The static flag is not needed for static batching I believe. I'll investigate in due time, but leave it off for now please.

@mvaligursky do you have an estimate?

mvaligursky commented 3 years ago

yep, agreed with @leonidaspir - just what I wanted to write. The static flag is not needed for static batching I believe. I'll investigate in due time, but leave it off for now please.

@mvaligursky do you have an estimate?

I don't at the moment - as there seems to be an easy workaround (don't mark the mesh static), this does not sound like urgent at the moment.