Skip to content

Scalable volumetrics [skip ci] #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 73 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
fa1f5e8
Adaptive sampling works
Feb 19, 2020
d4aaf3d
Compute the PDF
Feb 20, 2020
a94f376
URL
Feb 20, 2020
30e21ad
Fix stuff up (except for profile preview)
Feb 20, 2020
cf7bde2
Attempt to fix previews
Feb 21, 2020
9537b68
Fix transmission
Feb 21, 2020
e9afd28
Support quality levels
Feb 22, 2020
8b8222f
Clean shader
Feb 22, 2020
1ce50a4
Remove 2 kernels
Feb 22, 2020
9e33e3f
PURGE
Feb 22, 2020
294d09a
Automatically adjust the number of samples at runtime
Feb 22, 2020
d1bec8f
Changelog
Feb 22, 2020
a69c046
Spaaaaace
Feb 22, 2020
d2c4ddc
Add comment
Feb 22, 2020
ee8ff7c
Spaaaaaace
Feb 22, 2020
e74aaf8
Rename
Feb 22, 2020
f119b58
Update ref img 1215, 1216, 1217
Feb 22, 2020
787c06a
Revert "Update ref img 1215, 1216, 1217"
Feb 22, 2020
d265b2d
Robust filter radius
Feb 24, 2020
e78aa86
Solve the NaN problem
Feb 24, 2020
6268d71
Save 1x VGPR
Feb 24, 2020
3467d0b
Update SSS defaults
Feb 25, 2020
bf2b7d1
Add migration steps
Feb 25, 2020
6b55308
Volume resolution WIP
Feb 26, 2020
7678bd7
Shorter names FTW
Feb 26, 2020
5d89ce6
Comment
Feb 26, 2020
95fba9f
Dynamic slice count works
Feb 26, 2020
f14b2d2
Dynamic res works
Feb 27, 2020
e3f48e7
Changelog
Feb 27, 2020
7180a79
Stretch the limits
Feb 27, 2020
94f6ebf
Fix bug (order matters)
Feb 27, 2020
2438833
Comments
Feb 27, 2020
4ca5145
Remove volumetric quality presets
Feb 27, 2020
6907c80
Changelog
Feb 27, 2020
5e428f9
Reorder
Feb 27, 2020
a8c17a4
Solve the mystery of RTs going NULL
Feb 27, 2020
7f45eab
More robust bad history detection
Feb 27, 2020
dd4cd00
Update test scenes for High Quality
Feb 27, 2020
541063a
More bug fixes
Feb 27, 2020
1bb82d2
More accurate comment
Feb 27, 2020
571f522
Do not reinvent the wheel
Feb 27, 2020
5f8e7d7
Merge branch 'master' of https://github.com/Unity-Technologies/Script…
Mar 3, 2020
0498224
Fix broken test 1351
Mar 3, 2020
2db068c
Attempt to migrate HQ SSS settings
Mar 3, 2020
30f2c5a
Remove all branches
Mar 4, 2020
c2a99fb
Optimize a bit
Mar 4, 2020
0af4763
7x WF
Mar 5, 2020
d064f01
Merge branch 'HDRP/adaptive-sss' into HDRP/scalable-volumetrics
Mar 5, 2020
e49fb4b
Fix the rounding error
Mar 5, 2020
7c4ad79
Fix the rounding error
Mar 5, 2020
d1bf09f
Merge branch 'HDRP/adaptive-sss' into HDRP/scalable-volumetrics
Mar 5, 2020
e4f4dd7
Remove garbage allocation
Mar 6, 2020
0ae669b
Fix typos
EvgeniiG Mar 24, 2020
3b4ca2b
Copy the SSS value
EvgeniiG Mar 30, 2020
e0cb0aa
Revert HDRP asset changes
EvgeniiG Mar 30, 2020
e7cdff5
Fix default UI value
EvgeniiG Mar 30, 2020
f594d90
Pass the right asset
EvgeniiG Mar 30, 2020
6617634
Merge branch 'master' into 'HDRP/adaptive-sss'
EvgeniiG Mar 30, 2020
f1e0661
Update ref img 1215
EvgeniiG Mar 30, 2020
99e7433
update reference screenshots
sebastienlagarde Mar 31, 2020
95fed2e
Update CHANGELOG.md
sebastienlagarde Mar 31, 2020
ff74ed8
Update CHANGELOG.md
sebastienlagarde Mar 31, 2020
5e7c1fc
Merge branch 'HDRP/adaptive-sss' into 'HDRP/scalable-volumetrics'
EvgeniiG Apr 1, 2020
6492884
Merge branch 'master' into 'HDRP/scalable-volumetrics'
EvgeniiG Apr 1, 2020
2959232
Switch to RTHandles
EvgeniiG Apr 1, 2020
043cfd7
Rename textures used by the fog filtering pass
EvgeniiG Apr 1, 2020
4ba1428
Merge branch 'master' into HDRP/scalable-volumetrics' (reprojection i…
EvgeniiG Apr 18, 2020
57bb67d
Fix reprojection
EvgeniiG Apr 18, 2020
e8da602
Merge branch 'HDRP/staging' into HDRP/scalable-volumetrics
sebastienlagarde Apr 18, 2020
f3697b9
Merge branch 'HDRP/staging' into HDRP/scalable-volumetrics
sebastienlagarde Apr 18, 2020
e379743
Fix shader warning + typo+
sebastienlagarde Apr 18, 2020
96e76a4
fix another shader warning
sebastienlagarde Apr 18, 2020
c8e7e12
Merge branch 'HDRP/staging' into HDRP/scalable-volumetrics
sebastienlagarde Apr 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ MonoBehaviour:
m_Value: 0.75
min: 0
max: 1
screenResolutionPercentage:
m_OverrideState: 1
m_Value: 25
min: 6.25
max: 100
volumeSliceCount:
m_OverrideState: 1
m_Value: 128
min: 1
max: 1024
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ MonoBehaviour:
m_Value: 0.75
min: 0
max: 1
screenResolutionPercentage:
m_OverrideState: 1
m_Value: 25
min: 6.25
max: 100
volumeSliceCount:
m_OverrideState: 1
m_Value: 128
min: 1
max: 1024
--- !u!114 &3474294613101294443
MonoBehaviour:
m_ObjectHideFlags: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ MonoBehaviour:
m_Value: 0.75
min: 0
max: 1
screenResolutionPercentage:
m_OverrideState: 1
m_Value: 25
min: 6.25
max: 100
volumeSliceCount:
m_OverrideState: 1
m_Value: 128
min: 1
max: 1024
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,13 @@ MonoBehaviour:
m_Value: 1
min: 0
max: 1
screenResolutionPercentage:
m_OverrideState: 1
m_Value: 25
min: 6.25
max: 100
volumeSliceCount:
m_OverrideState: 1
m_Value: 128
min: 1
max: 1024
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ MonoBehaviour:
m_Value: 0.75
min: 0
max: 1
screenResolutionPercentage:
m_OverrideState: 1
m_Value: 25
min: 6.25
max: 100
volumeSliceCount:
m_OverrideState: 1
m_Value: 128
min: 1
max: 1024
filter:
m_OverrideState: 1
m_Value: 1
Expand Down
3 changes: 3 additions & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added alpha channel support in motion blur pass.
- Added the HDRP Compositor Tool (in Preview).
- Added a ray tracing mode option in the HDRP asset that allows to override and shader stripping.
- Added support for arbitrary resolution scaling of Volumetric Lighting to the Fog volume component.

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down Expand Up @@ -662,6 +663,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Raytracing: Remove the LOD cross fade multi compile for ray tracing.
- Cookie are now supported in lightmaper. All lights casting cookie and baked will now include cookie influence.
- Avoid building the mip chain a second time for SSR for transparent objects.
- Replaced "High Quality" Subsurface Scattering with a set of Quality Levels.
- Replaced "High Quality" Volumetric Lighting with "Screen Resolution Percentage" and "Volume Slice Count" on the Fog volume component.

## [7.1.1] - 2019-09-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -865,13 +865,6 @@ static void Drawer_SectionLightingUnsorted(SerializedHDRenderPipelineAsset seria
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportSSAO, Styles.supportSSAOContent);

EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportVolumetrics, Styles.supportVolumetricContent);
using (new EditorGUI.DisabledScope(serialized.renderPipelineSettings.supportVolumetrics.hasMultipleDifferentValues
|| !serialized.renderPipelineSettings.supportVolumetrics.boolValue))
{
++EditorGUI.indentLevel;
EditorGUILayout.PropertyField(serialized.renderPipelineSettings.increaseResolutionOfVolumetrics, Styles.volumetricResolutionContent);
--EditorGUI.indentLevel;
}

EditorGUILayout.PropertyField(serialized.renderPipelineSettings.supportProbeVolume, Styles.supportProbeVolumeContent);
using (new EditorGUI.DisabledScope(!serialized.renderPipelineSettings.supportProbeVolume.boolValue))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class SerializedRenderPipelineSettings
public SerializedScalableSetting sssSampleBudget;
[FormerlySerializedAs("supportVolumetric")]
public SerializedProperty supportVolumetrics;
public SerializedProperty increaseResolutionOfVolumetrics;
public SerializedProperty supportLightLayers;
public SerializedProperty lightLayerName0;
public SerializedProperty lightLayerName1;
Expand Down Expand Up @@ -88,7 +87,6 @@ public SerializedRenderPipelineSettings(SerializedProperty root)
supportSubsurfaceScattering = root.Find((RenderPipelineSettings s) => s.supportSubsurfaceScattering);
sssSampleBudget = new SerializedScalableSetting(root.Find((RenderPipelineSettings s) => s.sssSampleBudget));
supportVolumetrics = root.Find((RenderPipelineSettings s) => s.supportVolumetrics);
increaseResolutionOfVolumetrics = root.Find((RenderPipelineSettings s) => s.increaseResolutionOfVolumetrics);
supportLightLayers = root.Find((RenderPipelineSettings s) => s.supportLightLayers);
lightLayerName0 = root.Find((RenderPipelineSettings s) => s.lightLayerName0);
lightLayerName1 = root.Find((RenderPipelineSettings s) => s.lightLayerName1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class FogEditor : VolumeComponentEditor
protected SerializedDataParameter m_EnableVolumetricFog;
protected SerializedDataParameter m_DepthExtent;
protected SerializedDataParameter m_SliceDistributionUniformity;
protected SerializedDataParameter m_ScreenResolutionPercentage;
protected SerializedDataParameter m_VolumeSliceCount;
protected SerializedDataParameter m_Filter;

static GUIContent s_Enabled = new GUIContent("Enable", "Check this to enable fog in your scene.");
Expand Down Expand Up @@ -61,6 +63,8 @@ public override void OnEnable()
m_EnableVolumetricFog = Unpack(o.Find(x => x.enableVolumetricFog));
m_DepthExtent = Unpack(o.Find(x => x.depthExtent));
m_SliceDistributionUniformity = Unpack(o.Find(x => x.sliceDistributionUniformity));
m_ScreenResolutionPercentage = Unpack(o.Find(x => x.screenResolutionPercentage));
m_VolumeSliceCount = Unpack(o.Find(x => x.volumeSliceCount));
m_Filter = Unpack(o.Find(x => x.filter));
}

Expand Down Expand Up @@ -117,6 +121,8 @@ public override void OnInspectorGUI()
{
PropertyField(m_DepthExtent);
PropertyField(m_SliceDistributionUniformity);
PropertyField(m_ScreenResolutionPercentage);
PropertyField(m_VolumeSliceCount);
PropertyField(m_Filter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
#endif

TEXTURE3D(_VBufferLighting);

float3 ExpLerp(float3 A, float3 B, float t, float x, float y)
{
// Remap t: (exp(10 k t) - 1) / (exp(10 k) - 1) = exp(x t) y - y.
Expand Down Expand Up @@ -276,14 +278,14 @@ void EvaluateAtmosphericScattering(PositionInputs posInput, float3 V, out float3
if (_EnableVolumetricFog != 0)
{
float4 value = SampleVBuffer(TEXTURE3D_ARGS(_VBufferLighting, s_linear_clamp_sampler),
posInput.positionNDC,
fogFragDist,
_VBufferViewportSize,
_VBufferSharedUvScaleAndLimit.xy,
_VBufferSharedUvScaleAndLimit.zw,
_VBufferDistanceEncodingParams,
_VBufferDistanceDecodingParams,
true, false);
posInput.positionNDC,
fogFragDist,
_VBufferViewportSize,
_VBufferLightingViewportScale.xyz,
_VBufferLightingViewportLimit.xyz,
_VBufferDistanceEncodingParams,
_VBufferDistanceDecodingParams,
true, false);

// TODO: add some slowly animated noise (dither?) to the reconstructed value.
// TODO: re-enable tone mapping after implementing pre-exposure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public class Fog : VolumeComponent
/// <summary>Controls the distribution of slices along the Camera's focal axis. 0 is exponential distribution and 1 is linear distribution.</summary>
[Tooltip("Controls the distribution of slices along the Camera's focal axis. 0 is exponential distribution and 1 is linear distribution.")]
public ClampedFloatParameter sliceDistributionUniformity = new ClampedFloatParameter(0.75f, 0, 1);
/// <summary>Resolution of the volumetric buffer (3D texture) along the X and Y axes relative to the resolution of the frame buffer.</summary>
[Tooltip("Resolution of the volumetric buffer (3D texture) along the X and Y axes relative to the resolution of the frame buffer. " +
"Setting it to 12.5% (1/8) means the number of voxels per slice is 1/8^2 = 1/64 = 1.5625% of the resolution of the frame buffer.")]
public ClampedFloatParameter screenResolutionPercentage = new ClampedFloatParameter((1.0f/8.0f) * 100, (1.0f/16.0f) * 100, 100);
/// <summary>Number of slices of the volumetric buffer (3D texture) along the camera's focal axis.</summary>
[Tooltip("Number of slices of the volumetric buffer (3D texture) along the camera's focal axis.")]
public ClampedIntParameter volumeSliceCount = new ClampedIntParameter(64, 1, 1024);

/// <summary>Applies a blur to smoothen the volumetric lighting output.</summary>
[Tooltip("Applies a blur to smoothen the volumetric lighting output.")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
TEXTURE3D(_VBufferLighting);
TEXTURECUBE_ARRAY(_SkyTexture);

#define _MipFogNear _MipFogParameters.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
// This means storing tone mapped radiance and transmittance instead of optical depth.
// See "A Fresh Look at Generalized Sampling", p. 51.
//
// if (clampToBorder), samples outside of the buffer return 0 (we perform a smooth fade).
// if (clampToBorder), samples outside of the buffer return 0 (border color).
// Otherwise, the sampler simply clamps the texture coordinate to the edge of the texture.
// Warning: clamping to border may not work as expected with the quadratic filter due to its extent.
float4 SampleVBuffer(TEXTURE3D_PARAM(VBuffer, clampSampler),
float2 positionNDC,
float linearDistance,
float4 VBufferViewportSize,
float2 VBufferUvScale,
float2 VBufferUvLimit,
float3 VBufferViewportScale,
float3 VBufferViewportLimit,
float4 VBufferDistanceEncodingParams,
float4 VBufferDistanceDecodingParams,
bool quadraticFilterXY,
Expand All @@ -27,17 +27,19 @@ float4 SampleVBuffer(TEXTURE3D_PARAM(VBuffer, clampSampler),
float2 uv = positionNDC;
float w = EncodeLogarithmicDepthGeneralized(linearDistance, VBufferDistanceEncodingParams);

bool coordIsInsideFrustum = true;
bool coordIsInsideFrustum;

if (clampToBorder)
{
// Coordinates are always clamped to edge. We just introduce a clipping operation.
// Coordinates are always clamped to the edge. We just introduce a clipping operation.
float3 positionCS = float3(uv, w) * 2 - 1;

coordIsInsideFrustum = Max3(abs(positionCS.x), abs(positionCS.y), abs(positionCS.z)) < 1;
}

float4 result = 0;
else
{
coordIsInsideFrustum = true; // No clipping, only clamping
}

#if defined(UNITY_STEREO_INSTANCING_ENABLED)
// With XR single-pass, one 3D buffer is used to store all views (split along w)
Expand All @@ -51,6 +53,8 @@ float4 SampleVBuffer(TEXTURE3D_PARAM(VBuffer, clampSampler),
w = clamp(w, lowerSliceRange + limitSliceRange, upperSliceRange - limitSliceRange);
#endif

float4 result = 0;

if (coordIsInsideFrustum)
{
if (quadraticFilterXY)
Expand All @@ -62,21 +66,30 @@ float4 SampleVBuffer(TEXTURE3D_PARAM(VBuffer, clampSampler),
float2 weights[2], offsets[2];
BiquadraticFilter(1 - fc, weights, offsets); // Inverse-translate the filter centered around 0.5

const float2 ssToUv = VBufferViewportSize.zw * VBufferUvScale;
// Don't want to pass another shader parameter...
const float2 rcpBufDim = VBufferViewportScale.xy * VBufferViewportSize.zw; // (vp_dim / buf_dim) * (1 / vp_dim)

// And these are the texture coordinates.
// TODO: will the compiler eliminate redundant computations?
float2 texUv0 = (ic + float2(offsets[0].x, offsets[0].y)) * rcpBufDim; // Top left
float2 texUv1 = (ic + float2(offsets[1].x, offsets[0].y)) * rcpBufDim; // Top right
float2 texUv2 = (ic + float2(offsets[0].x, offsets[1].y)) * rcpBufDim; // Bottom left
float2 texUv3 = (ic + float2(offsets[1].x, offsets[1].y)) * rcpBufDim; // Bottom right
float texW = w * VBufferViewportScale.z;

// The sampler clamps to edge. This takes care of 4 frustum faces out of 6.
// Due to the RTHandle scaling system, we must take care of the other 2 manually.
// The sampler clamps to the edge (so UVWs < 0 are OK).
// TODO: perform per-sample (4, in this case) bilateral filtering, rather than per-pixel. This should reduce leaking.
result = (weights[0].x * weights[0].y) * SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, float3(min((ic + float2(offsets[0].x, offsets[0].y)) * ssToUv, VBufferUvLimit), w), 0) // Top left
+ (weights[1].x * weights[0].y) * SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, float3(min((ic + float2(offsets[1].x, offsets[0].y)) * ssToUv, VBufferUvLimit), w), 0) // Top right
+ (weights[0].x * weights[1].y) * SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, float3(min((ic + float2(offsets[0].x, offsets[1].y)) * ssToUv, VBufferUvLimit), w), 0) // Bottom left
+ (weights[1].x * weights[1].y) * SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, float3(min((ic + float2(offsets[1].x, offsets[1].y)) * ssToUv, VBufferUvLimit), w), 0); // Bottom right
result = (weights[0].x * weights[0].y) * SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, min(float3(texUv0, texW), VBufferViewportLimit), 0)
+ (weights[1].x * weights[0].y) * SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, min(float3(texUv1, texW), VBufferViewportLimit), 0)
+ (weights[0].x * weights[1].y) * SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, min(float3(texUv2, texW), VBufferViewportLimit), 0)
+ (weights[1].x * weights[1].y) * SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, min(float3(texUv3, texW), VBufferViewportLimit), 0);
}
else
{
// The sampler clamps to edge. This takes care of 4 frustum faces out of 6.
// Due to the RTHandle scaling system, we must take care of the other 2 manually.
result = SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, float3(min(uv * VBufferUvScale, VBufferUvLimit), w), 0);
// And these are the texture coordinates.
float3 texUVW = float3(uv, w) * VBufferViewportScale;
// The sampler clamps to the edge (so UVWs < 0 are OK).
result = SAMPLE_TEXTURE3D_LOD(VBuffer, clampSampler, min(texUVW, VBufferViewportLimit), 0);
}
}

Expand All @@ -88,22 +101,22 @@ float4 SampleVBuffer(TEXTURE3D_PARAM(VBuffer, clampSampler),
float3 cameraPositionWS,
float4x4 viewProjMatrix,
float4 VBufferViewportSize,
float2 VBufferUvScale,
float2 VBufferUvLimit,
float3 VBufferViewportScale,
float3 VBufferViewportLimit,
float4 VBufferDistanceEncodingParams,
float4 VBufferDistanceDecodingParams,
bool quadraticFilterXY,
bool clampToBorder)
{
float2 positionNDC = ComputeNormalizedDeviceCoordinates(positionWS, viewProjMatrix);
float2 positionNDC = ComputeNormalizedDeviceCoordinates(positionWS, viewProjMatrix);
float linearDistance = distance(positionWS, cameraPositionWS);

return SampleVBuffer(TEXTURE3D_ARGS(VBuffer, clampSampler),
positionNDC,
linearDistance,
VBufferViewportSize,
VBufferUvScale,
VBufferUvLimit,
VBufferViewportScale,
VBufferViewportLimit,
VBufferDistanceEncodingParams,
VBufferDistanceDecodingParams,
quadraticFilterXY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
// #pragma enable_d3d11_debug_symbols
#pragma only_renderers d3d11 playstation xboxone vulkan metal switch

#pragma kernel VolumeVoxelizationBruteforceMQ VolumeVoxelization=VolumeVoxelizationBruteforceMQ LIGHTLOOP_DISABLE_TILE_AND_CLUSTER VL_PRESET_MQ
#pragma kernel VolumeVoxelizationTiledMQ VolumeVoxelization=VolumeVoxelizationTiledMQ VL_PRESET_MQ
#pragma kernel VolumeVoxelizationBruteforceHQ VolumeVoxelization=VolumeVoxelizationBruteforceHQ LIGHTLOOP_DISABLE_TILE_AND_CLUSTER VL_PRESET_HQ
#pragma kernel VolumeVoxelizationTiledHQ VolumeVoxelization=VolumeVoxelizationTiledHQ VL_PRESET_HQ
#pragma kernel VolumeVoxelizationBruteforceOptimal VolumeVoxelization=VolumeVoxelizationBruteforceOptimal LIGHTLOOP_DISABLE_TILE_AND_CLUSTER VL_PRESET_OPTIMAL
#pragma kernel VolumeVoxelizationTiledOptimal VolumeVoxelization=VolumeVoxelizationTiledOptimal VL_PRESET_OPTIMAL
#pragma kernel VolumeVoxelizationBruteforce VolumeVoxelization=VolumeVoxelizationBruteforce LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
#pragma kernel VolumeVoxelizationTiled VolumeVoxelization=VolumeVoxelizationTiled

#ifndef LIGHTLOOP_DISABLE_TILE_AND_CLUSTER
#define USE_BIG_TILE_LIGHTLIST
#endif

#ifdef VL_PRESET_MQ
// E.g. for 1080p: (1920/8)x(1080/8)x(64) = 2,073,600 voxels
// Same texel count as in a 1080p frame buffer.
#define VBUFFER_TILE_SIZE 8
#endif
#ifdef VL_PRESET_HQ
// E.g. for 1080p: (1920/4)x(1080/4)x(128) = 16,588,800 voxels
// Double the texel count of a 4K frame buffer!
#define VBUFFER_TILE_SIZE 4
#ifdef VL_PRESET_OPTIMAL
// E.g. for 1080p: (1920/8)x(1080/8)x(64) = 2,073,600 voxels
#define VBUFFER_VOXEL_SIZE 8
#endif

#define GROUP_SIZE_1D 8
Expand Down Expand Up @@ -316,15 +310,21 @@ void VolumeVoxelization(uint3 dispatchThreadId : SV_DispatchThreadID,
uint2 groupId : SV_GroupID,
uint2 groupThreadId : SV_GroupThreadID)
{
// Perform compile-time checks.
if (!IsPower2(VBUFFER_TILE_SIZE) || !IsPower2(TILE_SIZE_BIG_TILE)) return;

UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);

uint2 groupOffset = groupId * GROUP_SIZE_1D;
uint2 voxelCoord = groupOffset + groupThreadId;
uint2 tileCoord = groupOffset * VBUFFER_TILE_SIZE / TILE_SIZE_BIG_TILE;
uint tileIndex = tileCoord.x + _NumTileBigTileX * tileCoord.y;
#ifdef VL_PRESET_OPTIMAL
// The entire thread group is within the same light tile.
uint2 tileCoord = groupOffset * VBUFFER_VOXEL_SIZE / TILE_SIZE_BIG_TILE;
#else
// No compile-time optimizations, no scalarization.
// If _VBufferVoxelSize is not a power of 2 or > TILE_SIZE_BIG_TILE, a voxel may straddle
// a tile boundary. This means different voxel subsamples may belong to different tiles.
// We accept this error, and simply use the coordinates of the center of the voxel.
uint2 tileCoord = (uint2)((voxelCoord + 0.5) * _VBufferVoxelSize / TILE_SIZE_BIG_TILE);
#endif
uint tileIndex = tileCoord.x + _NumTileBigTileX * tileCoord.y;

// Reminder: our voxels are sphere-capped right frustums (truncated right pyramids).
// The curvature of the front and back faces is quite gentle, so we can use
Expand Down
Loading