纹理 | 要绘制的体积纹理。 |
stepScale | 乘以光线步长的数字。光线步长是 2 个相邻像素之间的距离。默认值为 1。 |
surfaceOffset | 渲染表面的像素的强度。当此值大于零时,Unity 会扩展渲染表面。当此值小于零时,Unity 会将空白空间作为表面渲染,并将表面作为空白空间渲染。默认值为 0。 |
customColorRamp | Unity 用作颜色渐变的自定义颜色渐变。如果未指定此值,Unity 将使用 Google Turbo 颜色渐变。 |
以 3D 空间中的符号距离场渲染模式绘制 3D 纹理。
此可视化模式仅支持非定向符号距离场。
使用 Google Turbo 颜色渐变可视化的 Corridor SDF。
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; } }