EEVEE Next: Tag shadowmap usage for transparent object volumes #104580

Merged
Miguel Pozo merged 31 commits from pragma37/blender:pull-eevee-shadows-tag-usage-transparent into main 2023-03-08 13:51:35 +01:00
Member

Render the transparent object bounds to a low-res frame-buffer and ray-march the bounds volume, tagging tiles along the way.

Render the transparent object bounds to a low-res frame-buffer and ray-march the bounds volume, tagging tiles along the way.
Miguel Pozo requested review from Clément Foucault 2023-02-10 17:38:25 +01:00
Clément Foucault added this to the EEVEE & Viewport project 2023-02-11 12:47:01 +01:00
Clément Foucault requested changes 2023-02-14 01:07:19 +01:00
Clément Foucault left a comment
Member

I think the debug code is confusing and not isolated. Might be better to remove it. We don't need that in production (I mean the cost of having a separate framebuffer + clear etc...), you can just use an empty framebuffer for that.

It came to my mind that we also need to raster one pixel outside the frustum. Otherwise we could miss tagging pages that are between the center of the texel and the border.
One way would be to do the raycast 2 to 4 times (for the corners) for these border pixels.

I do think we can use a much coarser LOD. I think LOD 4 (16px stride) or 5 (32px stride) would be nicer. This needs to be somewhat adjusted to the mean screenspace tile size (which is quite hard to figure out). Too big and you might skip over some tiles.

Note that the LOD selection (not in this patch) will need to take into account not only the step size but also the spacing between the fragments.

I think the debug code is confusing and not isolated. Might be better to remove it. We don't need that in production (I mean the cost of having a separate framebuffer + clear etc...), you can just use an empty framebuffer for that. It came to my mind that we also need to raster one pixel outside the frustum. Otherwise we could miss tagging pages that are between the center of the texel and the border. One way would be to do the raycast 2 to 4 times (for the corners) for these border pixels. I do think we can use a much coarser LOD. I think LOD 4 (16px stride) or 5 (32px stride) would be nicer. This needs to be somewhat adjusted to the mean screenspace tile size (which is quite hard to figure out). Too big and you might skip over some tiles. Note that the LOD selection (not in this patch) will need to take into account not only the step size but also the spacing between the fragments.
@ -16,0 +58,4 @@
float near_box_t = distance(ws_near_plane, ws_near_box);
float far_box_t = distance(ws_near_plane, interp.P);
/* Depth test. */
far_box_t = min(far_box_t, distance(ws_near_plane, ws_opaque));

Be conservative in Z too. Bias far_box_t by step_size to have one more iteration before and after.

This is for the same issue as the full 1px inflate.

Be conservative in Z too. Bias `far_box_t` by step_size to have one more iteration before and after. This is for the same issue as the full 1px inflate.
pragma37 marked this conversation as resolved
@ -16,0 +78,4 @@
vec3 P = ws_near_plane + (ws_view_direction * t);
vec3 vP = vs_near_plane + (vs_view_direction * t);
/* TODO (Miguel Pozo): Pass step size to ensure conservative enough LOD selection */
shadow_tag_usage(vP, P, gl_FragCoord.xy * pow(2, fb_lod));

Use exp2 instead of pow(2, x). Try to apply this everywhere.

Use `exp2` instead of `pow(2, x)`. Try to apply this everywhere.
pragma37 marked this conversation as resolved
@ -10,0 +19,4 @@
if (is_persp) {
inflate_scale *= -vP.z;
}
inflate_scale *= 0.5f; /* Half pixel. */

I think we need a fullpixel here.

Imagine a really tiny box.

      tagged    |   not tagged    < Tiles tagging. Tilemap boundary at the middle
 --------------T|---------------  < the shadow tilemap at the correct LOD
            |----x----|           < the half inflated bounds (covers 1 pixel)
                 x                < the object (infinitesimal)
|----x----|----x----|----x----|   < Screen LOD where we raster the bboxes

A tile map boundary cannot be mitigated by tagging a lower LOD selection.

Inflating a whole pixel:

      tagged    |    tagged       < Tiles tagging. Tilemap boundary at the middle
 --------------T|--------T------  < the shadow tilemap at the correct LOD
       |---------x--------|       < the FULL inflated bounds (covers 2 pixel)
                 x                < the object (infinitesimal)
|----x----|----x----|----x----|   < Screen LOD where we raster the bboxes
I think we need a fullpixel here. Imagine a really tiny box. ``` tagged | not tagged < Tiles tagging. Tilemap boundary at the middle --------------T|--------------- < the shadow tilemap at the correct LOD |----x----| < the half inflated bounds (covers 1 pixel) x < the object (infinitesimal) |----x----|----x----|----x----| < Screen LOD where we raster the bboxes ``` A tile map boundary cannot be mitigated by tagging a lower LOD selection. Inflating a whole pixel: ``` tagged | tagged < Tiles tagging. Tilemap boundary at the middle --------------T|--------T------ < the shadow tilemap at the correct LOD |---------x--------| < the FULL inflated bounds (covers 2 pixel) x < the object (infinitesimal) |----x----|----x----|----x----| < Screen LOD where we raster the bboxes ```
pragma37 marked this conversation as resolved
@ -10,0 +23,4 @@
vec3 vs_inflate_vector = normal_object_to_view(sign(lP - ls_center));
vs_inflate_vector.z = 0;
vs_inflate_vector /= max_v2(abs(vs_inflate_vector));

This only works because max_v2 is a define. Use vs_inflate_vector.xy to avoid the confusion.
Also not entierly sure what's this about. Can you add a comment on this?

This only works because `max_v2` is a define. Use `vs_inflate_vector.xy` to avoid the confusion. Also not entierly sure what's this about. Can you add a comment on this?
pragma37 marked this conversation as resolved
@ -14,0 +63,4 @@
}
#ifdef DEBUG_CONSERVATIVE_RASTERIZATION
interp.ls_aabb_min = point_world_to_object(ws_aabb_min);

Im' not sure why you are changing that for the debug visuals.

Im' not sure why you are changing that for the debug visuals.
Author
Member

Because to debug the conservative rasterization I raycast against the original aabb in the fragment shader. If there's no hit, then it's a "conservatively rasterized" pixel.

If we keep the debugging visualizations that will have to be sent through its own varying.

Because to debug the conservative rasterization I raycast against the original aabb in the fragment shader. If there's no hit, then it's a "conservatively rasterized" pixel. If we keep the debugging visualizations that will have to be sent through its own varying.
pragma37 marked this conversation as resolved
Miguel Pozo force-pushed pull-eevee-shadows-tag-usage-transparent from 1683255827 to 02cc1bcdfa 2023-02-14 18:08:58 +01:00 Compare
Author
Member

I think the debug code is confusing and not isolated. Might be better to remove it. We don't need that in production (I mean the cost of having a separate framebuffer + clear etc...), you can just use an empty framebuffer for that.

I think the decission to take is whether we want/need to have debugging visualizations for this, at least for now.
If we do, then the code must be cleaned up and ensure the non-debugging path doesn't do anything unnecesary. Otherwise it can be deleted.

But I don't think we should decide whether to keep it or not based on the current (hacky and WIP) quality of the code.

I do think we can use a much coarser LOD

I've tried to use LOD5 and the tagging breaks.
It seems to be related to the step sizes, not to the conservative rasterization. 🤔

> I think the debug code is confusing and not isolated. Might be better to remove it. We don't need that in production (I mean the cost of having a separate framebuffer + clear etc...), you can just use an empty framebuffer for that. I think the decission to take is whether we want/need to have debugging visualizations for this, at least for now. If we do, then the code must be cleaned up and ensure the non-debugging path doesn't do anything unnecesary. Otherwise it can be deleted. But I don't think we should decide whether to keep it or not based on the current (hacky and WIP) quality of the code. > I do think we can use a much coarser LOD I've tried to use LOD5 and the tagging breaks. It seems to be related to the step sizes, not to the conservative rasterization. 🤔
Miguel Pozo requested review from Clément Foucault 2023-02-17 16:50:42 +01:00
Miguel Pozo force-pushed pull-eevee-shadows-tag-usage-transparent from 18f7a4aeb8 to 241978b13e 2023-02-20 11:56:44 +01:00 Compare
Clément Foucault requested changes 2023-03-03 20:13:43 +01:00
Clément Foucault left a comment
Member

The TODO (Miguel Pozo) comments should be removed or solved. A bit more documentation is needed to for such algorithm.

Functionality wise, it works.

The `TODO (Miguel Pozo)` comments should be removed or solved. A bit more documentation is needed to for such algorithm. Functionality wise, it works.
@ -18,0 +25,4 @@
}
void shadow_tag_usage_tilemap_directional(
uint l_idx, vec3 P, vec3 V, float dist_to_cam, float radius)

dist_to_cam is not used.

`dist_to_cam` is not used.
pragma37 marked this conversation as resolved
@ -89,3 +148,3 @@
}
void shadow_tag_usage(vec3 vP, vec3 P, vec2 pixel)
void shadow_tag_usage(vec3 vP, vec3 P, vec3 V, float radius, float dist_to_cam, vec2 pixel)

Document the parameters of this functions. This should be enough to explain the need for radius.

Document the parameters of this functions. This should be enough to explain the need for radius.
pragma37 marked this conversation as resolved
Clément Foucault reviewed 2023-03-03 20:46:54 +01:00
@ -176,0 +174,4 @@
ShadowCoordinates shadow_directional_coordinates(LightData light, vec3 lP)
{
/* TODO (Miguel Pozo): This is somewhat confusing, lP is used for P in light space, but also for
* P in light oriented world space ? */

Well, light oriented world space is the light local space for directional. This is because they are considered always at the origin. Maybe this should be added somewhere.

Well, `light oriented world space` is the light local space for directional. This is because they are considered always at the origin. Maybe this should be added somewhere.
Author
Member

Could you confirm if this is correct? 29d79d2210

Could you confirm if this is correct? https://projects.blender.org/blender/blender/commit/29d79d221017ae1fa6f9eb59d586ddc540c16ec6

Not quite.
lP here is shading point relative to the shadow origin in light space.
light._position isn't the actual position of the light in world space but the offset in light space to the shadow center, which is chosen by using the view near plane center point projected to the tile space of the shadow.

So lP is still a position and it is still in light local space but it hasn't the same origin.

Not quite. `lP` here is shading point relative to the shadow origin in light space. `light._position` isn't the actual position of the light in world space but the offset in light space to the shadow center, which is chosen by using the view near plane center point projected to the tile space of the shadow. So `lP` is still a position and it is still in light local space but it hasn't the same origin.
Author
Member

Ok, so the original lP shading point position in light space (world unit) and translated to camera position snapped to smallest clipmap level. comment was correct, but it should be in shadow_directional_level instead of shadow_directional_coordinates.

Ok, so the original `lP shading point position in light space (world unit) and translated to camera position snapped to smallest clipmap level.` comment was correct, but it should be in `shadow_directional_level` instead of `shadow_directional_coordinates`.
pragma37 marked this conversation as resolved
Miguel Pozo force-pushed pull-eevee-shadows-tag-usage-transparent from 241978b13e to 29d79d2210 2023-03-06 15:40:00 +01:00 Compare
Miguel Pozo added 1 commit 2023-03-06 15:58:56 +01:00
Miguel Pozo changed title from WIP: EEVEE Next: Tag shadowmap usage for transparent object volumes to EEVEE Next: Tag shadowmap usage for transparent object volumes 2023-03-06 18:07:37 +01:00
Miguel Pozo added 1 commit 2023-03-06 19:08:54 +01:00
Clément Foucault approved these changes 2023-03-07 15:40:22 +01:00
@ -102,0 +102,4 @@
* This function should be the inverse of ShadowDirectional::coverage_get().
*
* \a lP shading point position in light space relative to the view position
* (shadow_world_to_local - light._position).

This is confusing since shadow_world_to_local is a function. Also put backticks ` around code inside comments.

This is confusing since `shadow_world_to_local` is a function. Also put backticks ` around code inside comments.
pragma37 marked this conversation as resolved
Miguel Pozo added 1 commit 2023-03-08 13:41:42 +01:00
Miguel Pozo merged commit 25016b56ef into main 2023-03-08 13:51:35 +01:00
Miguel Pozo deleted branch pull-eevee-shadows-tag-usage-transparent 2023-03-08 13:51:36 +01: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#104580
No description provided.