texture | The volumetric texture to draw. |
stepScale | The number by which to multiply the ray step size. The ray step size is the distance between 2 neighboring pixels. The default value is 1. |
surfaceOffset | The intensity of the pixels at which the surface is rendered. When this value is positive, Unity will expand the rendered surface. When this value is negative, Unity will render empty space as a surface, and a surface as empty space. The default value is 0. |
customColorRamp | The custom gradient that Unity uses as a color ramp. If this is not specified, Unity uses Google Turbo color ramp. |
Draws a 3D texture using Signed Distance Field rendering mode in 3D space.
This visualization mode supports only non-directional Signed Distance Fields.
Corridor SDF visualized using Google Turbo color ramp.
using UnityEditor; using UnityEngine;
[ExecuteInEditMode] public class Reference : MonoBehaviour { public Texture3D texture; public float stepScale = 1; public float surfaceOffset; public bool useCustomColorRamp;
// We should initialize this gradient before using it as a custom color ramp public Gradient customColorRampGradient; }
[CanEditMultipleObjects] [CustomEditor(typeof(Reference))] public class Handle : Editor { private void OnSceneViewGUI(SceneView sv) { Object[] objects = targets; foreach (var obj in objects) { Reference reference = obj as Reference; if (reference != null && reference.texture != null) { Handles.matrix = reference.transform.localToWorldMatrix; Handles.DrawTexture3DSDF(reference.texture, reference.stepScale, reference.surfaceOffset, reference.useCustomColorRamp ? reference.customColorRampGradient : null); } } }
void OnEnable() { SceneView.duringSceneGui += OnSceneViewGUI; }
void OnDisable() { SceneView.duringSceneGui -= OnSceneViewGUI; } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.