Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


IntegrateDirectRadiance(IDeviceContext, int, int, int, bool, BufferSlice<SphericalHarmonicsL2>)

Computes direct lighting contribution at probe positions using spherical sampling.
Read time 2 minutesLast updated 11 days ago

Definition

IProbeIntegrator.Result IntegrateDirectRadiance(IDeviceContext context, int positionOffset, int positionCount, int sampleCount, bool ignoreEnvironment, BufferSlice<SphericalHarmonicsL2> radianceEstimateOut)

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 samples to take per probe.

ignoreEnvironment

If true, excludes environment lighting from the direct contribution calculation.

Output BufferSlice that the direct radiance estimate is written into, encoded as SphericalHarmonicsL2.

Returns

Type

Description

ResultResult indicating success or failure with detailed error information.

Remarks

This method performs spherical sampling around each probe position to compute direct lighting contributions from all light sources in the scene. The results are stored as SphericalHarmonicsL2 that can be used for real-time lighting lookups.
Direct radiance includes contributions from:
  • Directional lights
  • Point lights
  • Spot lights
  • Area lights
  • Environment lighting (unless ignored)
The quality of the integration depends on the sample count - higher values produce more accurate results but require more computation time.

Examples

// Extract scene databool result = InputExtraction.ExtractFromScene(out var input);Assert.IsTrue(result);// Create context and worldusing var context = new RadeonRaysContext();Assert.IsTrue(context.Initialize());var world = new RadeonRaysWorld();// Populate world with scene datausing var progress = new BakeProgressState();var worldResult = InputExtraction.PopulateWorld(input, progress, context, world);Assert.IsTrue(worldResult);// Create integratorvar integrator = new RadeonRaysProbeIntegrator();integrator.SetProgressReporter(progress);// Prepare probe positionsvar probePositions = new NativeArray<Vector3>(64, Allocator.Persistent);// ... fill probe positions ...BufferID posBuffer = context.CreateBuffer(64, 12); // Vector3 = 12 bytesvar posSlice = new BufferSlice<Vector3>(posBuffer, 0);context.WriteBuffer(posSlice, probePositions);// Prepare integrator.integrator.Prepare(context, world, posSlice, 0.1f, 2);// Integrate direct lightingvar result = integrator.IntegrateDirectRadiance( context, 0, // Start from first probe 32, // Process 32 probes 64, // Faster, low quality sampling, usually okay for final bake if area lights are not used. false, // Include environment lighting shBuffer);if (result.type != IProbeIntegrator.ResultType.Success){ Debug.LogError($"Direct radiance integration failed: {result}");}// Cleanupintegrator.Dispose();context.DestroyBuffer(posBuffer);context.DestroyBuffer(shBuffer);probePositions.Dispose();