Skip to content

Conversation

alelievr
Copy link
Member

@alelievr alelievr commented Dec 3, 2021

Purpose of this PRimage

  • This PR improves the behavior of the voxelization used to place probes for APV when dealing with small objects.
    The problem was that when an object is smaller than a brick (3 x min probe distance) it could be ignored by the probe placement system, this is caused by the rasterization of objects and can be solved by enabling conservative rasterization

  • There is also a small bugfix about cell position not being correct when enabling realtime voxelization

  • Replaced the geometry distance offset since it's not necessary anymore with the conservative rasterization and added a new field called "Minimum Renderer Volume Size" to ignore small renderers when placing probes.

You can override this new field per probe volume or set it globally in the baking set:
image
image

When the bounding box volume of a renderer in a probe volume is smaller than the value of this field, then the renderer is discarded from the list of objects to place probes around

Added a new LayerMask field in the APV window and an override on the probe volume component instead of only being able to set it on the probe volume.

image
image

technical details

The main issue with conservative rasterization is that it's not made to work in 3D and causes extreme artifacts when directly writing to a UAV in a fragment. There is no good solution for this as it's expected that conservative rasterization gives "bad" results for fragment interpolated values, especially when the triangle is close to being degenerate. So the only solution I found was to discard voxels written outside of the bounding box of the current rasterized triangle (this is done with a geometry shader, it's not optimal but still better than writing a software rasterizer in compute).

Note that in some cases this implementation can lead to false positives and generate more probes than before (especially in scenes with very large triangular shapes).


Testing status

Without conservative voxelization

WithoutConservative.mp4

With conservative voxelization

WithConservative.mp4

Minimum renderers size feature:

Renderers.volume.size.mp4

@github-actions
Copy link

github-actions bot commented Dec 3, 2021

Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed.
Link to Yamato: https://unity-ci.cds.internal.unity3d.com/project/902/
Search for your PR branch using the search bar at the top, then add the following segment(s) to the end of the URL (you may need multiple tabs depending on how many packages you change)

HDRP
/jobDefinition/.yamato%2Fall-hdrp.yml%23PR_HDRP_trunk
With changes to HDRP packages, you should also run
/jobDefinition/.yamato%2Fall-lightmapping.yml%23PR_Lightmapping_trunk

SRP Core
You could run ABV on your branch before merging your PR, but it will start A LOT of jobs. Please be responsible about it and run it only when you feel the PR is ready:
/jobDefinition/.yamato%252F_abv.yml%2523all_project_ci_trunk
Be aware that any modifications to the Core package impacts everyone in the Graphics repo so please discuss the PR with your lead.

Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure.

@github-actions github-actions bot added the SRP label Dec 3, 2021
@FrancescoC-unity
Copy link
Contributor

Because this can lead to more probes we should add this as an option (ON by default probably, but turn offable regardless)

@JMargevics
Copy link
Contributor

Don't forget the changelog 👍

@alelievr alelievr marked this pull request as ready for review December 3, 2021 17:09
var go = renderer.component.gameObject;
int rendererLayerMask = 1 << go.layer;
renderer.volume.CalculateCenterAndSize(out _, out var rendererBoundsSize);
float rendererBoundsVolume = rendererBoundsSize.x * rendererBoundsSize.y * rendererBoundsSize.z;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid issues with planes I'd say we should min all dimensions to avoid 0, probably to 2/3 cm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, in this renderer size, there is already padding of 1cm in every axis

internal static readonly GUIContent s_ObjectLayerMask = new GUIContent("Layer Mask", "Control which layers will be used to select the meshes for the probe placement algorithm.");
internal static readonly GUIContent s_GeometryDistanceOffset = new GUIContent("Probe Placement Distance Offset", "Affects the minimum distance at which the subdivision system will attempts to place probes near the geometry. This value can be useful in situations where the generated probes don't fully cover an object.");
internal static readonly GUIContent s_MinRendererVolumeSize = new GUIContent("Minimum Renderer Volume Size", "Specifies the minimum bounding box volume of renderers to consider placing probes around.");
internal static readonly GUIContent s_OverrideMinRendererVolumeSize = new GUIContent("Override Renderer Filters", "Overrides the Minimum Renderer Volume Size specified in the Probe Volume Settings Window.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this

Override Renderer Filters

Should have been Minimum Renderer Volume Size?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Override Minimum Renderer Volume Size
Was too long in the inspector, needed to find another name

Copy link
Contributor

@FrancescoC-unity FrancescoC-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM waiting for QA testing.

Copy link
Contributor

@TomasKiniulis TomasKiniulis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't ran into any issues. Changes look good to me!

What I've checked:

  • Renderer Filter Settings - Layer Mask
  • Renderer Filter Settings - Minimum Renderer Volume Size, smaller objects are correctly ignored
    • Bounding Box Of 0.5x0.5x0.5 - bricks are shown with Min Renderer Volume Size up to 0.13
    • Bounding Box Of 1x1x1 - bricks are shown with Min Renderer Volume Size up to 1.03
    • Bounding Box Of 5x5x5 - bricks are shown with Min Renderer Volume Size up to 125
    • Bounding Box Of 5x10x50 - bricks are shown with Min Renderer Volume Size up to 2500
    • Overlapping bounding boxes - overlap is ignored, setting only checks for individual renderer bounding boxes
  • Multiple local volumes with different settings
  • Complex shapes
  • Different Max Distance Between Probes settings

image (5)

  • Probe comparison between master and PR in Classroom project - looks nearly identical

Classroom scene PR
image (6)

Classroom scene master
image (7)

@sebastienlagarde
Copy link
Contributor

quesotin: is it possible to create an APV test like this ?

image

@sebastienlagarde sebastienlagarde merged commit 1fe51a8 into master Dec 16, 2021
@sebastienlagarde sebastienlagarde deleted the hd/apv-conservative-voxelization branch December 16, 2021 12:38
@TomasKiniulis
Copy link
Contributor

quesotin: is it possible to create an APV test like this ?

image

I could try to see if I can add one in. Although do we have a way to visualize probe volume subdivision levels debug mode in Graphics Test? We have a Debug View Controller script in use for some scenes, but it seems to support only Materials, Lighting and Rendering section, will need to dig into it how to get that extended.

@FrancescoC-unity
Copy link
Contributor

quesotin: is it possible to create an APV test like this ?

image

It'd be cool, the problem is that it'd also be fairly slow as we'd need to retrigger the baking.

Although I guess we can have a scene with realtime subdivision enabled, that won't be too slow. With realtime subdiv and no asset assigned in the scene (no baking ever triggered), it should work, no @alelievr ?

FrancescoC-unity added a commit that referenced this pull request Jan 4, 2022
This reverts commit 1fe51a8.

# Conflicts:
#	com.unity.render-pipelines.high-definition/CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants