Jump to content

Question about Camera.attachPostProcess and detachPostProcess


Kesshi
 Share

Recommended Posts

Maybe someone can help me to understand this.
Because there is no "nice" way to enable/disable a post-process i have to call attachPostProcess/detachPostProcess very frequently in my project. Not so nice but it works.

Today i noticed that the internal textures of the post-processes are recreated all the time. After looking at the BJS sources i saw that attachPostProcess and detachPostProcess both are calling _cascadePostProcessesToRigCams which always invalidates the texture of the first post-process: https://github.com/BabylonJS/Babylon.js/blob/master/src/Cameras/babylon.camera.ts#L298
That means every time i disable/enable a post-process the texture will be recreated.

My question is, why is it necessary to invalidate the post-process textures (and only for the first one??) in this case?
I disabled this for a short test and everything was working as expected without that annoying texture recreation.

Link to comment
Share on other sites

The main reason to do it is because the canvas size may have changed while the postprocess was detached so we need to recreate it (just in case).

Why do you find it "not nice" ? We could think also about a postprocess.isEnabled but this will force us to go through the list of camera.postProcesses on every frame to determine the actual postproces chain.

Link to comment
Share on other sites

1 hour ago, Deltakosh said:

The main reason to do it is because the canvas size may have changed while the postprocess was detached so we need to recreate it (just in case).

But then it should be done for the post process which was added and not for the first one or? And the resizing is checked for every frame already in the activate function here: https://github.com/BabylonJS/Babylon.js/blob/master/src/PostProcess/babylon.postProcess.ts#L168

1 hour ago, Deltakosh said:

Why do you find it "not nice" ? We could think also about a postprocess.isEnabled but this will force us to go through the list of camera.postProcesses on every frame to determine the actual postproces chain.

Often the order of the post processes is important to get the same result. If i remove some post processes in the middle of the chain, i need to be careful later when i add some of them again that i add them at the correct position. It would be easier to add all frequently used post processes once in the correct order and just enabling/disabling them. 

Link to comment
Share on other sites

I'm not opposed to add more flexibility here to be honest.

The check is done for the first one only because we need the first one to provide a depth buffer for the chain. So if you remove the first one, bjs need to attach a depth buffer to the new first one.

Perhaps we could think about a bool to turn off postprocesses completely for a camera

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...