postprocessing icon indicating copy to clipboard operation
postprocessing copied to clipboard

How disable effect

Open revyTH opened this issue 7 years ago • 2 comments

Hi! I was trying your beautiful library, really awesome! Apologies this is more a question then an issue. I would like to know if is it possible to selectively disable/enable an effect inside EffectPass. I see that each effect has several passes inside, I've tried to set enabled = false for each of the inner passes to disable the effect but it didn't work.

Thanks!

revyTH avatar Apr 15 '19 09:04 revyTH

Hi,

that's a nice question 👍 I should probably add some information about this topic to the wiki.

You may have noticed that the Effect class doesn't have an enabled flag. That's a deliberate design decision. Since the EffectPass bakes effects into a single shader, enabling or disabling one effect at runtime would require a slow recompilation of the shader program. The EffectPass actually provides a recompile method that allows you to do that, but it blocks the render thread and causes a noticeable hiccup when performed at runtime. This method is not intended for toggling effects and should only be used in a situation where a user changes special effect parameters that require a shader recompilation.

Now, to answer your question, you should prepare multiple EffectPass instances with the desired effect combinations ahead of time and enable or disable these passes as needed using the Pass.enabled flag. This requires some planning ahead and uses a little bit more memory but is the most efficient solution. Note that Effect instances can be reused in other EffectPass instances so you won't have to worry about redundant frame buffers.

I hope this helps!

vanruesc avatar Apr 15 '19 19:04 vanruesc

Hi,

that's a nice question 👍 I should probably add some information about this topic to the wiki.

You may have noticed that the Effect class doesn't have an enabled flag. That's a deliberate design decision. Since the EffectPass bakes effects into a single shader, enabling or disabling one effect at runtime would require a slow recompilation of the shader program. The EffectPass actually provides a recompile method that allows you to do that, but it blocks the render thread and causes a noticeable hiccup when performed at runtime. This method is not intended for toggling effects and should only be used in a situation where a user changes special effect parameters that require a shader recompilation.

Now, to answer your question, you should prepare multiple EffectPass instances with the desired effect combinations ahead of time and enable or disable these passes as needed using the Pass.enabled flag. This requires some planning ahead and uses a little bit more memory but is the most efficient solution. Note that Effect instances can be reused in other EffectPass instances so you won't have to worry about redundant frame buffers.

I hope this helps!

Ehi thank you very much for the great explanation! I will do as you suggested, using different EffectPass merging effects that should be enable/disable together

revyTH avatar Apr 16 '19 19:04 revyTH