Skip to content

Commit 4b2fd4f

Browse files
pigselatedEvergreen
authored andcommitted
Add APV Sky Occlusion Testing
1 parent e3e5d66 commit 4b2fd4f

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

Packages/com.unity.render-pipelines.core/Runtime/Lighting/ProbeVolume/ProbeReferenceVolume.Debug.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,22 +1108,35 @@ static void DecompressSH(ref SphericalHarmonicsL2 shv)
11081108
}
11091109
}
11101110

1111+
internal static Vector3 DecodeSkyShadingDirection(uint directionIndex)
1112+
{
1113+
var precomputedDirections = ProbeVolumeConstantRuntimeResources.GetSkySamplingDirections();
1114+
Debug.Assert(directionIndex < precomputedDirections.Length + 1);
1115+
return directionIndex == precomputedDirections.Length ? new Vector3(0.0f, 0.0f, 0.0f) : precomputedDirections[directionIndex];
1116+
}
1117+
11111118
internal bool GetFlattenedProbeData(
11121119
string scenario,
11131120
out Vector3[] positions,
11141121
out SphericalHarmonicsL2[] irradiance,
11151122
out float[] validity,
1116-
out Vector4[] occlusion)
1123+
out Vector4[] occlusion,
1124+
out Vector4[] skyOcclusion,
1125+
out Vector3[] skyOcclusionDirections)
11171126
{
11181127
positions = null;
11191128
irradiance = null;
11201129
validity = null;
11211130
occlusion = null;
1131+
skyOcclusion = null;
1132+
skyOcclusionDirections = null;
11221133

11231134
var positionsList = new List<Vector3>();
11241135
var irradianceList = new List<SphericalHarmonicsL2>();
11251136
var validityList = new List<float>();
11261137
var occlusionList = new List<Vector4>();
1138+
var skyOcclusionList = new List<Vector4>();
1139+
var skyOcclusionDirectionList = new List<Vector3>();
11271140

11281141
foreach (var cell in cells.Values)
11291142
{
@@ -1172,6 +1185,24 @@ internal bool GetFlattenedProbeData(
11721185
float occlusionValue3 = scenarioData.probeOcclusion[occlusionOffset+3] / 255.0f;
11731186
occlusionList.Add(new Vector4(occlusionValue0, occlusionValue1, occlusionValue2, occlusionValue3));
11741187

1188+
if (cell.data.skyOcclusionDataL0L1.Length > 0)
1189+
{
1190+
// sky occlusion L0/L1 SH
1191+
var skyOccSH_dc = Mathf.HalfToFloat(cell.data.skyOcclusionDataL0L1[probeFlatIndex * 4]);
1192+
var skyOccSH_x = Mathf.HalfToFloat(cell.data.skyOcclusionDataL0L1[probeFlatIndex * 4 + 1]);
1193+
var skyOccSH_y = Mathf.HalfToFloat(cell.data.skyOcclusionDataL0L1[probeFlatIndex * 4 + 2]);
1194+
var skyOccSH_z = Mathf.HalfToFloat(cell.data.skyOcclusionDataL0L1[probeFlatIndex * 4 + 3]);
1195+
skyOcclusionList.Add(new Vector4(skyOccSH_dc, skyOccSH_x, skyOccSH_y, skyOccSH_z));
1196+
}
1197+
1198+
if (cell.data.skyShadingDirectionIndices.Length > 0)
1199+
{
1200+
// sky occlusion direction
1201+
var skyOccSDI = cell.data.skyShadingDirectionIndices[probeFlatIndex];
1202+
var skyOcclusionDirection = DecodeSkyShadingDirection(skyOccSDI);
1203+
skyOcclusionDirectionList.Add(skyOcclusionDirection);
1204+
}
1205+
11751206
Vector4 L0_L1Rx = Vector4.zero;
11761207
Vector4 L1G_L1Ry = Vector4.zero;
11771208
Vector4 L1B_L1Rz = Vector4.zero;
@@ -1271,6 +1302,8 @@ internal bool GetFlattenedProbeData(
12711302
irradiance = irradianceList.ToArray();
12721303
validity = validityList.ToArray();
12731304
occlusion = occlusionList.ToArray();
1305+
skyOcclusion = skyOcclusionList.ToArray();
1306+
skyOcclusionDirections = skyOcclusionDirectionList.ToArray();
12741307

12751308
return true;
12761309
}

0 commit comments

Comments
 (0)