Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#

RayTracingAccelerationStructure.GetNativeBufferPtr

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public IntPtr GetNativeBufferPtr();

Returns

IntPtr The pointer to the underlying graphics API TLAS buffer.

Description

Returns a native pointer to the top-level acceleration structure (TLAS) buffer as it is represented in the native graphics API, for example an `ID3D12Resource`.

Use this method to enable binding the TLAS buffer to shaders from native code plugins.

If you call RayTracingAccelerationStructure.Build, the underlying TLAS buffer might change, for example if number of ray tracing instances can't fit into the existing buffer storing the TLAS data. Call GetNativeBufferPtr to get the new native pointer after a build operation.

If you call the function from a non-main thread or if the acceleration structure was never built then the function returns null.

Note that calling this method will synchronize with the rendering thread which is a slow operation.

Additional resources: GraphicsBuffer.GetNativeBufferPtr, Native code plugins.

using UnityEngine;
using UnityEngine.Rendering;

[ExecuteInEditMode] public class RayTracingExample : MonoBehaviour { private RayTracingAccelerationStructure rtas = null;

private int rayTracingInstanceCount = -1;

void OnDisable() { if (rtas != null) { rtas.Release(); rtas = null;

rayTracingInstanceCount = -1; } }

private void Update() { if (!SystemInfo.supportsRayTracing) { Debug.Log("Ray Tracing is not supported by this GPU or by the current graphics API."); return; }

if (rtas == null) { RayTracingAccelerationStructure.Settings settings = new RayTracingAccelerationStructure.Settings(); settings.rayTracingModeMask = RayTracingAccelerationStructure.RayTracingModeMask.Everything; settings.managementMode = RayTracingAccelerationStructure.ManagementMode.Automatic; settings.layerMask = 255;

rtas = new RayTracingAccelerationStructure(settings); }

rtas.Build();

// The native pointer of the TLAS can change if the amount of ray tracing instances grows from frame to frame. if (rayTracingInstanceCount < (int)rtas.GetInstanceCount()) { rayTracingInstanceCount = (int)rtas.GetInstanceCount();

Debug.Log("Native TLAS resource is: " + rtas.GetNativeBufferPtr()); } } }

The script in this example configures an acceleration structure based on the contents of the Scene, builds the acceleration structure and displays the native pointer of the TLAS in the console.