processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.13k stars 3.23k forks source link

Introduce Depth Access for Filters Functionality #6818

Open perminder-17 opened 4 months ago

perminder-17 commented 4 months ago

Increasing access

The feature request entails an enhancement to the current functionality of the filters() function. It proposes the addition of a third parameter, allowing for depth access when applying filters.

Most appropriate sub-area of p5.js?

Feature request details

This parameter would be utilized in the following format: filter(BLUR, BLUR-VALUE, DEPTH). Previously, our implementation relied on p5.Graphics, which facilitated filter access through a hidden WEBGL canvas. Now, with the transition to framebuffers, which serve a similar purpose, we have the opportunity to incorporate depth into filter shaders. Initially, this update will focus on integrating depth into filters applied through framebuffers. Subsequently, we plan to extend this capability to encompass 2D filters as well, ensuring a comprehensive enhancement to our filtering system. Maybe giving depth access to 2D filters can be a follow-up update.

Following the implementation of depth buffers for filters, we can expand the range of available filters that utilize depth, such as adding a Fog filter. The addition of depth is crucial for the Fog filter, as it enables objects closer to the viewer to be less obscured by fog, while objects farther away appear more obscured.

An image I found from photoshop:- Maybe a depth blur filter will look something like-

depth blur

Maybe a depth fog filter will look something like:-(maybe fog can be a followup update after adding depth access to filters)

depth fog

perminder-17 commented 4 months ago

Tagging WebGL stewards for their inputs, let me know what you think! @aferriss, @davepagurek ,@aceslowman, @ShenpaiSharma, @ChihYungChang, @teragramgius, @JazerUCSB, @richardegil, @itsjoopark, @Gaurav-1306, @jeanetteandrews

Also let me know what are your plans on the implementation part. Thankyou ;)

davepagurek commented 4 months ago

I think the main technical hurdle here is that we only have access to depth information on framebuffers, so this would involve looking into https://github.com/processing/p5.js/issues/5571 again.

If we have a default framebuffer for the main canvas, we'd need to: