depth of field with webgl

2019-07-11 11:19发布

I would like to simulate the "depth of field"-effect in webgl, moving the camera on a circle: https://en.wikibooks.org/wiki/OpenGL_Programming/Depth_of_Field

In OpenGl I would use the accumulation-buffer. But unfortunately webgl doesn´t know such buffer.

Is it possible to use blending to simulate such an effect?

2条回答
贪生不怕死
2楼-- · 2019-07-11 11:41

A simple way of simulating depth of field is

  • Render scene to texture
  • Blur texture with renderer scene to another texture
  • Mix the 2 textures (in focus scene texture + blurred scene texture) using the depth information.

There's an example here. Click the tiny * to and adjust the "dof" slider. Press d a few times to see the different textures.

查看更多
Bombasti
3楼-- · 2019-07-11 11:46

You can also render the scene to several different framebuffers, then bind those framebuffers as textures and accumulate the color from all of them in one final post-processing gathering pass. So that is more or less the manual way of doing accumulation.

查看更多
登录 后发表回答