Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Editor/SDFTexture.shader
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#define COLOR_POS 1
#define COLOR_NEG float3(0.72, 0, 1)

int _HighContrast;

v2f vert(appdata v)
{
Expand All @@ -51,7 +53,15 @@
uvw = float3(i.texcoord.x, _Z, i.texcoord.y);

float dist = tex3D(_SDF, uvw).r * _DistanceScale;
float3 color = dist > 0.0 ? dist * COLOR_POS : -dist * COLOR_NEG;
float3 color;
if(_HighContrast == 1)
{
color = dist > 0.0 ? float3(1, 1, 1) : float3(0, 0, 0);
}
else
{
color = dist > 0.0 ? dist * COLOR_POS : -dist * COLOR_NEG;
}
return float4(color, 1);
}
ENDHLSL
Expand Down
5 changes: 5 additions & 0 deletions Editor/SDFTextureEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum Axis { X, Y, Z }
static Material s_Material;
static float s_Slice = 0.5f; // [0, 1]
static Axis s_Axis = Axis.X;
static bool s_HighContrast = false;

SerializedProperty m_SDF;
SerializedProperty m_Size;
Expand All @@ -22,6 +23,7 @@ static class Uniforms
internal static int _Mode = Shader.PropertyToID("_Mode");
internal static int _Axis = Shader.PropertyToID("_Axis");
internal static int _DistanceScale = Shader.PropertyToID("_DistanceScale");
internal static int _HighContrast = Shader.PropertyToID("_HighContrast");
}

void OnEnable()
Expand Down Expand Up @@ -96,6 +98,7 @@ static void DoSDFSlice(Matrix4x4 matrix, Camera camera, Vector3Int voxelResoluti
s_Material.SetVector("_VoxelResolution", new Vector4(voxelResolution.x, voxelResolution.y, voxelResolution.z));
s_Material.SetFloat(Uniforms._DistanceScale, distanceScale);
s_Material.SetTexture("_SDF", sdf);
s_Material.SetInt(Uniforms._HighContrast, s_HighContrast ? 1 : 0);

s_Material.SetPass(0);
Graphics.DrawMeshNow(s_Quad, matrix);
Expand Down Expand Up @@ -183,6 +186,8 @@ Rect GetColumnRect(Rect totalRect, int column)
s_Slice = slice;
SceneView.lastActiveSceneView?.Repaint();
}

s_HighContrast = EditorGUILayout.Toggle(new GUIContent("High Contrast", "Draw SDF visualisation using high contrast colors."), s_HighContrast);
}

bool HasFrameBounds()
Expand Down