Skip to content

First WIP introduction of Adaptive Probe Volumes. #2953

Merged
sebastienlagarde merged 142 commits into
masterfrom
HDRP/probe-volume2-lightloop-sampling
Dec 21, 2020
Merged

First WIP introduction of Adaptive Probe Volumes. #2953
sebastienlagarde merged 142 commits into
masterfrom
HDRP/probe-volume2-lightloop-sampling

Conversation

@FrancescoC-unity
Copy link
Copy Markdown
Contributor

This PR introduce a first iteration over APV, it is not yet in a usable state, just to have some core code in master.
APV stands for Adaptive Probe Volume, it replaces Probe Volumes v1. It works essentially by adaptively placing probes around the scene, subdividing as required.

The sampling code is simpler as it is a single lookup on the indirection structure and finally samples the SH coefficients from a storage.

The PR includes:

  • Basic workflow (might contain bugs) with asset and profile production.
  • Basic baking and placement (will see improvements)
  • Lightloop sampling of the APV structure
  • Volumetrics sampling.
  • Material AO support.
  • L0 and L1 sampling code (everything does L1, volumetrics do L0)
  • Some debug visualization.
  • Multiple scene handling for additive loading of different assets.

The loading in player needs still to be handled with user-side script, but possible with the simple asset that gets produced by the baking process.

A lot is meant to be changed in a near future, so the usage is not recommended.
It is of course turned off by default.

urasmus and others added 30 commits November 10, 2020 13:03
…obevolumes-draft.

This reorganization lets us work on Adaptive Probe Volumes in context of Env2.0 without having to wait for Env2.0 to update to HDRP master.

# Conflicts:
#	com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume.meta
…ssed from Env2.0 code.

This may not be needed for the final version, but for now we need this.
…ocation. Also fixed a minor issue in the index, but indexing is still not correctly location aware.
# Conflicts:
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume.meta
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/ProbeVolumeEditor.cs
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/ProbeVolumeEditor.cs.meta
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/ProbeVolumeUI.Drawer.cs
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/ProbeVolumeUI.Drawer.cs.meta
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/ProbeVolumeUI.Skin.cs
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/ProbeVolumeUI.Skin.cs.meta
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/SerializedProbeVolume.cs
#	com.unity.render-pipelines.high-definition/Editor/Lighting/ProbeVolume/SerializedProbeVolume.cs.meta
#	com.unity.render-pipelines.high-definition/Editor/Lighting/VolumetricLighting/VolumetricMenuItem.cs
#	com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolume.cs
#	com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolume.cs.meta
… probes when evaluating GI influence. Also fixed a few issues with the existing data flow.

# Conflicts:
#	com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolume.hlsl
#	com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolume.hlsl.meta
#	com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs
#	com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLighting.cs.meta
#	com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinGIUtilities.hlsl
#	com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
#	com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs
Introduced a new base offset per column which is automatically updated
based on the bricks added to the index.
…ng up the index based on previous additions.
We saw surprising behaviour when debugging this line in Rider. The
variable would increment at unexpected times presumably due to a bug in
the Rider debugger.
We decided to not use a ref here because:
* This requires the caller to set up a mutable value which is not always ideal.
* We might as well follow the convensions established by the Entities
package.
@github-actions github-actions Bot added the SRP label Dec 18, 2020
@FrancescoC-unity
Copy link
Copy Markdown
Contributor Author

All tests pass locally.


From 10.x, a new pass ScenePickingPass have been added to all the shader and master node to allow the editor to correctly handle the picking with tesselated objects and backfaced objects.

From 10.x, if material ambient occlusion needs to be applied to probe volume GI and the material is deferred, the material needs to define `HAS_PAYLOAD_WITH_UNINIT_GI` constant and a function `float GetUninitializedGIPayload(SurfaceData surfaceData)` that returns the AO factor that is desired to be applied. No action is needed for forward only materials or if no material AO needs to be applied to probe volume GI.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can remove this statement,

  1. it is not the right location (upagre 2020.1 to 2020.2)
  2. we haven't ship the feature, so we don't care.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I now understand why it is there, should be in 2021.1 to 2021.2 upgrading guide (that we haven't created)

#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_instancing
#include "UnityCG.cginc"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We must convert this shader to new style SRP way, i.e don't use UnityCg.cginc. Can be done in next PR


float3 evalSH(float3 normal, float4 SHAr, float4 SHAg, float4 SHAb)
{
float4 normalPadded = float4(normal, 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure why you don't reuse the functoin provided in EntityLighting.hlsl?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To answer this and the before, @thefranke lifted this code from another project altogether. We indeed need to rewrite it anyway to be more SRP complaint.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This wasn't considered a blocker for opening the PR though.


if (ShaderConfig.s_EnableProbeVolumes == 1)
{
ProbeReferenceVolume.instance.InitProbeReferenceVolume(1024, m_Asset.currentPlatformRenderPipelineSettings.probeVolumeMemoryBudget, new Vector3Int(1024, 64, 1024));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what are the hardcoded value 1024 and other? (can be fix in next pr)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The first 1024 is just how much the pool allocator uses as size for the brick pool. It is a value that we need to tweak and see on profiling if it makes a difference changing it, realistically we just don't need it as a parameter of the Init function, but would need investigation whether it makes sense for different pipelines (not different projects) to have different values.

Note that the value is not really that hardcoded, as in it is a fixed number in a constructor, but then the value itself is correctly named in the rest of the code.

The second set is again just whatever is the default for the index dimension of the reference volume. It will be overwritten at first load if it mismatches what's on the profile. We can give it a name and store as static somewhere indeed.

// No need to branch internally on _EnableProbeVolumes uniform.
if (featureFlags & LIGHTFEATUREFLAGS_PROBE_VOLUME)
// Even so, the bound resources might be invalid in some cases, so we still need to check on _EnableProbeVolumes.
bool apvEnabled = featureFlags & LIGHTFEATUREFLAGS_PROBE_VOLUME && _EnableProbeVolumes;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

use (featureFlags & LIGHTFEATUREFLAGS_PROBE_VOLUME) && _EnableProbeVolumes for clarity

obbExtents = float3(probeVolumeBounds.extentX, probeVolumeBounds.extentY, probeVolumeBounds.extentZ);
obbCenter = probeVolumeBounds.center;
real4 SHCoefficients[7];
SHCoefficients[0] = unity_SHAr;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should create a function with this one, the exact same code is used in builtinGIUtilities.hlsl (next PR)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This the function :)
I just need to move this to the builtinGIUtilities and use there.

float3 sampleOutgoingRadiance = SHEvalLinearL0L1(normalWS, coefficients.data[0], coefficients.data[1], coefficients.data[2]);
return sampleOutgoingRadiance;
// no valid brick, fallback to ambient probe
bakeDiffuseLighting = EvaluateAmbientProbe(normalWS);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See my comment above, same code is use for both front and back lighting in builtinGIUtilitiers.hlsl

posInput.positionWS = ray.originWS + t * ray.jitterDirWS;

float3 apvDiffuseGI;
EvaluateAdaptiveProbeVolume(GetAbsolutePositionWS(posInput.positionWS), apvDiffuseGI);
Copy link
Copy Markdown
Contributor

@sebastienlagarde sebastienlagarde Dec 21, 2020

Choose a reason for hiding this comment

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

EvaluateAdaptiveProbeVolume evaluate the lighting with the lambert cosine convolution coefficient in it. We should remove it to apply on volumetric. Similar to what is done with Ambient probe in SetPreconvolvedAmbientLightProbe() function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point

}

#define HAS_PAYLOAD_WITH_UNINIT_GI
float GetUninitializedGIPayload(SurfaceData surfaceData)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel bad about this one, we will need to add it to all our lit material (hair, fabric, eye, staacklit...). But guess we have no choice. Problem is very similar to
GetAmbientOcclusionForMicroShadowing().
Let's let it for now for the experimental development, but not sure we have alternative. At least we should change the name to GetAmbientOcclusionFromSurface() so we can reuse it for other purpose

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't need to add it to everything that's why I added the define, we only need to add it to deferred materials.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The reason why I avoided using AmbientOcclusion in that name is exactly to allow potential reuse for something else.

Copy link
Copy Markdown
Contributor

@sebastienlagarde sebastienlagarde left a comment

Choose a reason for hiding this comment

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

Some random comment

@sebastienlagarde sebastienlagarde marked this pull request as ready for review December 21, 2020 13:54
# Conflicts:
#	com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs
#	com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs
#	com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs
#	com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs
@sebastienlagarde sebastienlagarde marked this pull request as draft December 21, 2020 15:30
@sebastienlagarde sebastienlagarde marked this pull request as ready for review December 21, 2020 15:48
@sebastienlagarde sebastienlagarde merged commit c8311fb into master Dec 21, 2020
@sebastienlagarde sebastienlagarde deleted the HDRP/probe-volume2-lightloop-sampling branch December 21, 2020 17:43
@sebastienlagarde sebastienlagarde restored the HDRP/probe-volume2-lightloop-sampling branch December 22, 2020 10:50
@sebastienlagarde sebastienlagarde deleted the HDRP/probe-volume2-lightloop-sampling branch April 26, 2021 10:42
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.

5 participants