First WIP introduction of Adaptive Probe Volumes. #2953
Conversation
…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
…ating the ambient probe.
Introduced a new base offset per column which is automatically updated based on the bricks added to the index.
…there are no bricks to subdivide anymore.
…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.
|
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. |
There was a problem hiding this comment.
you can remove this statement,
- it is not the right location (upagre 2020.1 to 2020.2)
- we haven't ship the feature, so we don't care.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
not sure why you don't reuse the functoin provided in EntityLighting.hlsl?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
what are the hardcoded value 1024 and other? (can be fix in next pr)
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
We should create a function with this one, the exact same code is used in builtinGIUtilities.hlsl (next PR)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Good point
| } | ||
|
|
||
| #define HAS_PAYLOAD_WITH_UNINIT_GI | ||
| float GetUninitializedGIPayload(SurfaceData surfaceData) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
The reason why I avoided using AmbientOcclusion in that name is exactly to allow potential reuse for something else.
sebastienlagarde
left a comment
There was a problem hiding this comment.
Some random comment
# 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
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:
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.