Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


IntegrateOcclusion(IDeviceContext, int, int, int, int, BufferSlice<int>, BufferSlice<float>)

Computes occlusion values for mixed lighting scenarios with shadowmask support.
Read time 2 minutesLast updated 10 days ago

Definition

IProbeIntegrator.Result IntegrateOcclusion(IDeviceContext context, int positionOffset, int positionCount, int sampleCount, int maxLightsPerProbe, BufferSlice<int> perProbeLightIndices, BufferSlice<float> probeOcclusionEstimateOut)

Parameters

Device context for computation and memory operations.

positionOffset

Starting index in the probe position buffer.

positionCount

Number of probe positions to process.

sampleCount

Number of directional samples to take per probe.

maxLightsPerProbe

Maximum number of lights to compute occlusion for per probe (typically 4).

perProbeLightIndices

Buffer containing light indices for each probe, computed using ComputeOcclusionLightIndicesFromBakeInput.

probeOcclusionEstimateOut

Output buffer for occlusion values. Size must be positionCount × maxLightsPerProbe × sizeof(float).

Returns

Type

Description

ResultResult indicating success or failure with detailed error information.

Remarks

This method computes occlusion factors for mixed lights at each probe position. Mixed lights are lights that provide both real-time dynamic lighting and baked shadows through shadowmasks.
The occlusion calculation:
  • Value 1.0: No occlusion (light is fully visible).
  • Values between 0-1: Partial occlusion.
  • Value 0.0: Full occlusion (light is completely blocked).
The light indices can be precomputed using ComputeOcclusionLightIndicesFromBakeInput to select the most influential lights for each probe position.
Additional Resources: ComputeOcclusionLightIndicesFromBakeInput, GetShadowmaskChannelsFromLightIndices.

Examples

// Compute light indices for occlusionvar probePositions = GetProbePositions(); // Vector3[]var lightIndices = InputExtraction.ComputeOcclusionLightIndicesFromBakeInput(bakeInput, probePositions, 4);// Create buffer for light indicesBufferID lightIndexBuffer = context.CreateBuffer((ulong)(probePositions.Length * 4), sizeof(int));var lightIndexSlice = new BufferSlice<int>(lightIndexBuffer, 0);context.WriteBuffer(lightIndexSlice, new NativeArray<int>(lightIndices, Allocator.Temp));// Create output buffer for occlusion valuesBufferID occlusionBuffer = context.CreateBuffer((ulong)(probePositions.Length * 4), sizeof(float));var occlusionSlice = new BufferSlice<float>(occlusionBuffer, 0);// Compute occlusionvar result = integrator.IntegrateOcclusion(context, 0, probePositions.Length, 512, 4, lightIndexSlice, occlusionSlice);Assert.AreEqual(IProbeIntegrator.ResultType.Success, result.type);