This commit is contained in:
Rob Cupisz 2022-10-13 11:52:39 +02:00
Родитель 113b5a26f4
Коммит cb5b042356
3 изменённых файлов: 27 добавлений и 2 удалений

Просмотреть файл

@ -5,6 +5,7 @@ using UnityEditor;
public class MeshToSDFEditor : Editor
{
SerializedProperty m_SDFTexture;
SerializedProperty m_FlipSign;
SerializedProperty m_FloodMode;
SerializedProperty m_FloodFillQuality;
SerializedProperty m_FloodFillIterations;
@ -14,6 +15,7 @@ public class MeshToSDFEditor : Editor
void OnEnable()
{
m_SDFTexture = serializedObject.FindProperty("m_SDFTexture");
m_FlipSign = serializedObject.FindProperty("m_FlipSign");
m_FloodMode = serializedObject.FindProperty("m_FloodMode");
m_FloodFillQuality = serializedObject.FindProperty("m_FloodFillQuality");
m_FloodFillIterations = serializedObject.FindProperty("m_FloodFillIterations");
@ -50,12 +52,26 @@ public class MeshToSDFEditor : Editor
else
{
GUI.enabled = false;
int oldValue = m_DistanceMode.enumValueIndex;
int oldDistanceMode = m_DistanceMode.enumValueIndex;
m_DistanceMode.enumValueIndex = (int)MeshToSDF.DistanceMode.Unsigned;
EditorGUILayout.PropertyField(m_DistanceMode);
m_DistanceMode.enumValueIndex = oldValue;
m_DistanceMode.enumValueIndex = oldDistanceMode;
GUI.enabled = true;
}
if ((MeshToSDF.FloodMode)m_FloodMode.enumValueIndex == MeshToSDF.FloodMode.Linear && (MeshToSDF.DistanceMode)m_DistanceMode.enumValueIndex == MeshToSDF.DistanceMode.Signed)
{
EditorGUILayout.PropertyField(m_FlipSign);
}
else
{
bool oldFlipSign = m_FlipSign.boolValue;
m_FlipSign.boolValue = false;
EditorGUILayout.PropertyField(m_FlipSign);
m_FlipSign.boolValue = oldFlipSign;
}
serializedObject.ApplyModifiedProperties();
}

Просмотреть файл

@ -47,12 +47,17 @@ If you need signed distance or just need a limited shell around your surface, us
[SerializeField]
DistanceMode m_DistanceMode = DistanceMode.Signed;
[SerializeField]
[Tooltip("Flip the sign of the distance field, so that the interior is positive and exterior - negative.")]
bool m_FlipSign = false;
[SerializeField]
UpdateMode m_UpdateMode = UpdateMode.OnBeginFrame;
public SDFTexture sdfTexture { get { return m_SDFTexture; } set { m_SDFTexture = value; } }
public bool flipSign { get { return m_FlipSign; } set { m_FlipSign = value; } }
public FloodMode floodMode { get { return m_FloodMode; } set { m_FloodMode = value; } }
public FloodFillQuality floodFillQuality { get { return m_FloodFillQuality; } set { m_FloodFillQuality = value; } }
public int floodFillIterations { get { return m_FloodFillIterations; } set { m_FloodFillIterations = Mathf.Clamp(value, 0, 64); } }
public DistanceMode distanceMode { get { return m_DistanceMode; } set { m_DistanceMode = value; } }
public UpdateMode updateMode { get {return m_UpdateMode; } set { m_UpdateMode = value; } }
[SerializeField]
@ -104,6 +109,7 @@ If you need signed distance or just need a limited shell around your surface, us
internal static int g_NumCellsZ = Shader.PropertyToID("g_NumCellsZ");
internal static int g_Origin = Shader.PropertyToID("g_Origin");
internal static int g_CellSize = Shader.PropertyToID("g_CellSize");
internal static int g_FlipSign = Shader.PropertyToID("g_FlipSign");
internal static int g_VertexBuffer = Shader.PropertyToID("g_VertexBuffer");
internal static int g_IndexBuffer = Shader.PropertyToID("g_IndexBuffer");
internal static int _VertexBufferStride = Shader.PropertyToID("_VertexBufferStride");
@ -240,6 +246,7 @@ If you need signed distance or just need a limited shell around your surface, us
cmd.SetComputeIntParam(m_Compute, Uniforms.g_NumCellsX, voxelResolution.x);
cmd.SetComputeIntParam(m_Compute, Uniforms.g_NumCellsY, voxelResolution.y);
cmd.SetComputeIntParam(m_Compute, Uniforms.g_NumCellsZ, voxelResolution.z);
cmd.SetComputeFloatParam(m_Compute, Uniforms.g_FlipSign, m_FlipSign ? -1 : 1);
int[] voxelResolutionArray = {voxelResolution.x, voxelResolution.y, voxelResolution.z, voxelCount};
cmd.SetComputeIntParams(m_Compute, Uniforms._VoxelResolution, voxelResolutionArray);
float maxDistance = voxelBounds.size.magnitude;

Просмотреть файл

@ -28,6 +28,7 @@ float g_CellSize;
int g_NumCellsX;
int g_NumCellsY;
int g_NumCellsZ;
float g_FlipSign;
#define MARGIN g_CellSize
#define GRID_MARGIN int3(1, 1, 1)
@ -204,6 +205,7 @@ float SignedDistancePointToTriangle(float3 p, float3 x0, float3 x1, float3 x2)
#ifdef SIGNED
d = (dot(p - x0, nTri) < 0.f) ? -d : d;
d *= g_FlipSign;
#endif
return d;