EEVEE Next: Ambient Occlusion #108398

Merged
Miguel Pozo merged 29 commits from pragma37/blender:pull-eevee-next-ao into main 2023-06-30 19:37:37 +02:00
Member

Port Ambient Occlusion to EEVEE Next.

Only the AO pass and the AO node work at the moment. Regular shading AO requires IBL.

Port Ambient Occlusion to EEVEE Next. Only the AO pass and the AO node work at the moment. Regular shading AO requires IBL.
Miguel Pozo added this to the EEVEE & Viewport project 2023-05-29 20:07:04 +02:00
Miguel Pozo force-pushed pull-eevee-next-ao from f5ab001261 to 1d60aced03 2023-05-31 17:56:32 +02:00 Compare
Miguel Pozo added 1 commit 2023-05-31 19:49:20 +02:00
Miguel Pozo added 1 commit 2023-05-31 20:01:12 +02:00
Miguel Pozo added 2 commits 2023-06-02 17:36:28 +02:00
Miguel Pozo added 1 commit 2023-06-02 17:40:47 +02:00
Miguel Pozo added 1 commit 2023-06-05 12:32:38 +02:00
Miguel Pozo added the
Module
EEVEE & Viewport
label 2023-06-05 12:33:08 +02:00
Miguel Pozo requested review from Clément Foucault 2023-06-05 12:33:24 +02:00
Clément Foucault requested changes 2023-06-14 15:40:06 +02:00
@ -0,0 +49,4 @@
}
data_.distance = scene->eevee.gtao_distance;
data_.factor = std::max(1e-4f, scene->eevee.gtao_factor);

Remove that. We don't want that in the new implementation. Same for the UI parameter and the code.

This was a NPR parameter that was ported from the old AO implementation and has no meaning in the PBR world. It is a hindrance to a better PBR integration of the AO.

Remove that. We don't want that in the new implementation. Same for the UI parameter and the code. This was a NPR parameter that was ported from the old AO implementation and has no meaning in the PBR world. It is a hindrance to a better PBR integration of the AO.
pragma37 marked this conversation as resolved
@ -0,0 +51,4 @@
data_.distance = scene->eevee.gtao_distance;
data_.factor = std::max(1e-4f, scene->eevee.gtao_factor);
data_.quality = scene->eevee.gtao_quality;
data_.use_bent_normals = scene->eevee.flag & SCE_EEVEE_GTAO_BENT_NORMALS;

Remove also that parameter. Bent normals will be used by default.

Remove also that parameter. Bent normals will be used by default.
pragma37 marked this conversation as resolved
@ -0,0 +52,4 @@
data_.factor = std::max(1e-4f, scene->eevee.gtao_factor);
data_.quality = scene->eevee.gtao_quality;
data_.use_bent_normals = scene->eevee.flag & SCE_EEVEE_GTAO_BENT_NORMALS;
data_.bounce_factor = (scene->eevee.flag & SCE_EEVEE_GTAO_BOUNCE) ? 1.0f : 0.0f;

Also remove.

Also remove.
pragma37 marked this conversation as resolved
Miguel Pozo added 4 commits 2023-06-15 17:18:23 +02:00
Miguel Pozo requested review from Clément Foucault 2023-06-15 17:20:34 +02:00
Clément Foucault requested changes 2023-06-16 17:06:56 +02:00
Clément Foucault left a comment
Member
  • Rename all _ao_ files to ambient_occlusion.
  • Remove plural from horizons > horizon.
  • Make sure all functions inside eevee_ao_lib.glsl have the ambient_occlusion_ prefix.
  • Why does this contains part of the raytracing module? I would prefer if the AO module was self sufficient. It should only rely on HiZ.
- Rename all `_ao_` files to `ambient_occlusion`. - Remove plural from `horizons` > `horizon`. - Make sure all functions inside `eevee_ao_lib.glsl` have the `ambient_occlusion_` prefix. - Why does this contains part of the raytracing module? I would prefer if the AO module was self sufficient. It should only rely on HiZ.
@ -148,0 +157,4 @@
def draw_header(self, context):
scene = context.scene
props = scene.eevee
self.layout.prop(props, "use_gtao", text="")

Do not make it optional. Always enable it if render pass is needed. It might become a core part of the raytracing module.

Do not make it optional. Always enable it if render pass is needed. It might become a core part of the raytracing module.
Author
Member

Always enable it if render pass is needed

It already works that way. See AmbientOcclusion::init.

Do you want to always enable it for the main shading too?
I think some users wouldn’t like that.

> Always enable it if render pass is needed It already works that way. See `AmbientOcclusion::init`. Do you want to always enable it for the main shading too? I think some users wouldn’t like that.

Do you want to always enable it for the main shading too?

Kind of. If it has to be an option it would be elsewhere.

> Do you want to always enable it for the main shading too? Kind of. If it has to be an option it would be elsewhere.
pragma37 marked this conversation as resolved
@ -0,0 +63,4 @@
return;
}
horizons_search_ps_.init();

I'm almost tempted to remove this pass altogether. It might just become a subpass of the raytracing pipeline.

I'm almost tempted to remove this pass altogether. It might just become a subpass of the raytracing pipeline.
pragma37 marked this conversation as resolved
@ -243,0 +248,4 @@
ELEM(pipeline_type, MAT_PIPE_FORWARD, MAT_PIPE_DEFERRED) &&
ELEM(geometry_type, MAT_GEOM_MESH, MAT_GEOM_CURVES))
{
info.define("MAT_AO");

no abreviation here too MAT_AMBIENT_OCCLUSION

no abreviation here too `MAT_AMBIENT_OCCLUSION`
pragma37 marked this conversation as resolved
@ -889,0 +912,4 @@
/** \name Ambient Occlussion
* \{ */
struct AOData {

Do not use AO as abreviation in either typenames or members name.

Do not use AO as abreviation in either typenames or members name.
pragma37 marked this conversation as resolved
@ -0,0 +4,4 @@
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_raytrace_lib.glsl)
/* TODO(Miguel Pozo): Move somewhere else. */

It is unclear what this TODO is referring to: a specific function, or the whole file?

It is unclear what this TODO is referring to: a specific function, or the whole file?
pragma37 marked this conversation as resolved
@ -0,0 +25,4 @@
* http://blog.selfshadow.com/publications/s2016-shading-course/activision/s2016_pbs_activision_occlusion.pptx
*/
#define NO_OCCLUSION_DATA OcclusionData(vec4(M_PI, -M_PI, M_PI, -M_PI), 1.0)

Prefer a function that returns an empty occlusion data.

Prefer a function that returns an empty occlusion data.
pragma37 marked this conversation as resolved
@ -0,0 +38,4 @@
#ifdef GPU_METAL
/* Constructors required for OcclusionData(..) syntax. */
inline OcclusionData() = default;
inline OcclusionData(vec4 in_horizons, float in_custom_occlusion)

Remove these and prefer individual member assignment.

Remove these and prefer individual member assignment.
pragma37 marked this conversation as resolved
@ -0,0 +397,4 @@
/* Visibility to cone angle (eq. 18). */
float vis_angle = fast_acos(sqrt(1 - visibility));
/* Roughness to cone angle (eq. 26). */
float spec_angle = max(0.00990998744964599609375, fast_acos(cone_cosine(roughness)));

Declare the constant before this line and add a comment that this fixes a NaN issue on some Intel GPU (add link to original issue).

Declare the constant before this line and add a comment that this fixes a NaN issue on some Intel GPU (add link to original issue).
Author
Member

What's the original issue?
I don't see any recent change in the current EEVEE implementation or any related open issue.

What's the original issue? I don't see any recent change in the current EEVEE implementation or any related open issue.
https://archive.blender.org/developer/D12508
Author
Member

I got it the other way around.
I thought moving it to a separate const WAS the fix.

I got it the other way around. I thought moving it to a separate const WAS the fix.
pragma37 marked this conversation as resolved
@ -0,0 +78,4 @@
vec3 Ng = transform_direction(ViewMatrixInverse, vNg);
vec3 N = imageLoad(in_normal_img, texel).xyz;
// OcclusionData data = unpack_occlusion_data(texelFetch(horizons_tx, texel, 0));

Remove commented code without purpose.

Remove commented code without purpose.
pragma37 marked this conversation as resolved
@ -88,3 +89,3 @@
imageStore(rp_value_img, ivec3(texel, rp_buf.shadow_id), vec4(shadow));
}
/* TODO: AO. */
/** NOTE: AO is done on its own pass. */

Remove the comment.

Remove the comment.
Author
Member

Why specifically on this one?
It's in the other shaders that write to the renderpasses too.
I think it makes sense to mention why AO is omitted.

Why specifically on this one? It's in the other shaders that write to the renderpasses too. I think it makes sense to mention why AO is omitted.
fclem marked this conversation as resolved
Clément Foucault reviewed 2023-06-16 17:08:36 +02:00
@ -10,6 +10,7 @@
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_hair_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_ao_lib.glsl)

Why is this needed?

Why is this needed?
Author
Member

Because the AO lib is required by the AO node in the nodetree lib.
But I can’t include the AO lib directly from the nodetree lib since then it ends up also in the depth, shadow and world passes.
AFAIK there’s no way to make a conditional BLENDER_REQUIRE, so the other option would be to put the whole AO lib behind a define (which would be kind of annoying in most code editors).

Because the AO lib is required by the AO node in the nodetree lib. But I can’t include the AO lib directly from the nodetree lib since then it ends up also in the depth, shadow and world passes. AFAIK there’s no way to make a conditional BLENDER_REQUIRE, so the other option would be to put the whole AO lib behind a define (which would be kind of annoying in most code editors).
fclem marked this conversation as resolved
Miguel Pozo added 3 commits 2023-06-16 21:02:24 +02:00
Author
Member

Why does this contains part of the raytracing module? I would prefer if the AO module was self sufficient. It should only rely on HiZ.

The AO lib depends on the raytracing lib, which depends on its own buffer parameters.
We can make it self-contained, but it would require duplicating the screen space ray creation code.

Related to this, I think we could re-evaluate the way uniform buffers are used in EEVEE Next.
There are many small ones that could be easily merged, and their management would become simpler.
There's also some data that is useful in general, like the render extent or the pixel size.

> Why does this contains part of the raytracing module? I would prefer if the AO module was self sufficient. It should only rely on HiZ. The AO lib depends on the raytracing lib, which depends on its own buffer parameters. We can make it self-contained, but it would require duplicating the screen space ray creation code. Related to this, I think we could re-evaluate the way uniform buffers are used in EEVEE Next. There are many small ones that could be easily merged, and their management would become simpler. There's also some data that is useful in general, like the render extent or the pixel size.
Miguel Pozo added 1 commit 2023-06-27 15:59:07 +02:00
Clément Foucault requested changes 2023-06-27 17:03:16 +02:00
Clément Foucault left a comment
Member

The AO lib depends on the raytracing lib, which depends on its own buffer parameters.

I would like to avoid this.
One lib file for common structures (here eevee_ray_types_lib.glsl for the ray init).
One specific file for each effect that need specific resources: eevee_ray_screen_trace_lib.glsl (not to include in this PR), eevee_ambient_occlusion_trace_lib.glsl.

This way you can include one without having to add much of other resource dependencies.

Related to this, I think we could re-evaluate the way uniform buffers are used in EEVEE Next.

The design is like this. Everything should be granular and well contained. When an effect depends on a shared module, it should be a simple dependency addition in a few places.

There's also some data that is useful in general, like the render extent or the pixel size.

Render extent should usually be queried by some fullscreen buffer textureSize(tx, 0).xy and pixel size by inversing it.

> The AO lib depends on the raytracing lib, which depends on its own buffer parameters. I would like to avoid this. One lib file for common structures (here `eevee_ray_types_lib.glsl` for the ray init). One specific file for each effect that need specific resources: `eevee_ray_screen_trace_lib.glsl` (not to include in this PR), `eevee_ambient_occlusion_trace_lib.glsl`. This way you can include one without having to add much of other resource dependencies. > Related to this, I think we could re-evaluate the way uniform buffers are used in EEVEE Next. The design is like this. Everything should be granular and well contained. When an effect depends on a shared module, it should be a simple dependency addition in a few places. > There's also some data that is useful in general, like the render extent or the pixel size. Render extent should usually be queried by some fullscreen buffer `textureSize(tx, 0).xy` and pixel size by inversing it.
@ -0,0 +49,4 @@
template<typename T> void bind_resources(draw::detail::PassBase<T> *pass)
{
inst_.sampling.bind_resources(pass);

Do not bind other resources here. Will result in double binds and it is against the design of this function.

Do not bind other resources here. Will result in double binds and it is against the design of this function.
pragma37 marked this conversation as resolved
@ -0,0 +188,4 @@
return hit;
}
#if 0

Just remove the code. Dead code lying around is not good.

Just remove the code. Dead code lying around is not good.
pragma37 marked this conversation as resolved

Also the F12 Ambient Occlusion render pass doesn't work. It doesn't show in the render passes.

Also the F12 Ambient Occlusion render pass doesn't work. It doesn't show in the render passes.
Miguel Pozo added 1 commit 2023-06-28 21:03:58 +02:00
Miguel Pozo added 5 commits 2023-06-29 17:31:51 +02:00
Author
Member

The design is like this. Everything should be granular and well contained. When an effect depends on a shared module, it should be a simple dependency addition in a few places.

I know it's intended, and I see the advantage for initializing the data.
But on the GPU side, it adds a lot of busy work for managing many small buffers that in practice are used in pretty much the same passes.

Anyway, I addressed all the feedback.
I fixed the F12 rendering for Shadows too, although It may have made more sense as a separate PR.

> The design is like this. Everything should be granular and well contained. When an effect depends on a shared module, it should be a simple dependency addition in a few places. I know it's intended, and I see the advantage for initializing the data. But on the GPU side, it adds a lot of busy work for managing many small buffers that in practice are used in pretty much the same passes. Anyway, I addressed all the feedback. I fixed the F12 rendering for Shadows too, although It may have made more sense as a separate PR.
Clément Foucault approved these changes 2023-06-30 10:58:20 +02:00

Note that you need have to change the UBO slot in eevee_defines as I made some changes there yesterday.
Now slot 0 is reserved for nodetree and slots 0-6 are reserved for engine use.

Note that you need have to change the UBO slot in `eevee_defines` as I made some changes there yesterday. Now slot 0 is reserved for nodetree and slots 0-6 are reserved for engine use.
Miguel Pozo added 1 commit 2023-06-30 19:33:20 +02:00
Miguel Pozo changed title from WIP: EEVEE Next: Ambient Occlusion to EEVEE Next: Ambient Occlusion 2023-06-30 19:33:52 +02:00
Miguel Pozo merged commit 221f985129 into main 2023-06-30 19:37:37 +02:00
Miguel Pozo deleted branch pull-eevee-next-ao 2023-06-30 19:37:38 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#108398
No description provided.