mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
103.03k stars 35.41k forks source link

Allow post effects to request access to depth and normal passes #7668

Open bhouston opened 9 years ago

bhouston commented 9 years ago

Many post effects request specific special passes, normal and depth mostly, to create their effect. Specifically:

DOF: depth SSAO: depth, normal SAO: depth, normal MB: motion, depth?

While it is possible to set up the creation of a normal and depth pass and then coordinate passing that result into another effect, it quickly becomes hard to manage if you can turn on or off the various effects, you may unnecessarily be computing a depth pass when you do not need it.

One alternative solution would be for each pass to state explicitly what passes it requires, so a DOF pass would state it needs a depth buffer. And a SAO pass would state that it needs a depth and a normal buffer.

It would then be the renderer's responsibility to create the buffers that the enabled post effects require. This would simplify creating post effects and it would make it more efficient to use post effects.

Focusing on a request model and encapsulating in the renderer how these buffers are generated would allow us to change how these buffers are generated. So that on Desktop we could use the WebGL DrawBuffers extension to create them in a single pass, while on mobile we can do multiple passes.

This also integrates well into AA systems where the normal or the depth buffer needs to be preprocessed with the same AA system that the beauty pass used for consistent sake -- this is the case with algorithms such as TAA.

(I would love to implement this but I've got other commitments for the next month. I am also not sure of the right design, even though I think the above is a good outline of a general direction to go in.)

/ping @benaadams @erichlof @MasterJames

benaadams commented 9 years ago

A sort of dependency resolution and build order step; declarative style (I need x, I produce y) rather than imperative (explicit linking)?

I like it very much.