Restructured volume settings. Added light source as setting.

This commit is contained in:
Matias Lavik 2022-09-13 22:02:15 +02:00
Родитель 8121d8d05e
Коммит 4b4d3f7734
6 изменённых файлов: 90 добавлений и 20 удалений

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

@ -6,7 +6,10 @@ namespace UnityVolumeRendering
[CustomEditor(typeof(VolumeRenderedObject))]
public class VolumeRenderedObjectCustomInspector : Editor
{
bool otherSettings = false;
private bool tfSettings = true;
private bool lightSettings = true;
private bool otherSettings = false;
public override void OnInspectorGUI()
{
VolumeRenderedObject volrendObj = (VolumeRenderedObject)target;
@ -17,30 +20,48 @@ namespace UnityVolumeRendering
if (newRenderMode != oldRenderMode)
volrendObj.SetRenderMode(newRenderMode);
// Lighting settings
if (volrendObj.GetRenderMode() == RenderMode.DirectVolumeRendering)
volrendObj.SetLightingEnabled(GUILayout.Toggle(volrendObj.GetLightingEnabled(), "Enable lighting"));
else
volrendObj.SetLightingEnabled(false);
// Visibility window
// Visibility window
Vector2 visibilityWindow = volrendObj.GetVisibilityWindow();
EditorGUILayout.MinMaxSlider("Visible value range", ref visibilityWindow.x, ref visibilityWindow.y, 0.0f, 1.0f);
EditorGUILayout.Space();
volrendObj.SetVisibilityWindow(visibilityWindow);
// Transfer function type
TFRenderMode tfMode = (TFRenderMode)EditorGUILayout.EnumPopup("Transfer function type", volrendObj.GetTransferFunctionMode());
if (tfMode != volrendObj.GetTransferFunctionMode())
volrendObj.SetTransferFunctionMode(tfMode);
// Show TF button
if (GUILayout.Button("Edit transfer function"))
// Transfer function settings
EditorGUILayout.Space();
tfSettings = EditorGUILayout.Foldout(tfSettings, "Transfer function");
if (tfSettings)
{
if (tfMode == TFRenderMode.TF1D)
TransferFunctionEditorWindow.ShowWindow();
// Transfer function type
TFRenderMode tfMode = (TFRenderMode)EditorGUILayout.EnumPopup("Transfer function type", volrendObj.GetTransferFunctionMode());
if (tfMode != volrendObj.GetTransferFunctionMode())
volrendObj.SetTransferFunctionMode(tfMode);
// Show TF button
if (GUILayout.Button("Edit transfer function"))
{
if (tfMode == TFRenderMode.TF1D)
TransferFunctionEditorWindow.ShowWindow();
else
TransferFunction2DEditorWindow.ShowWindow();
}
}
// Lighting settings
GUILayout.Space(10);
lightSettings = EditorGUILayout.Foldout(lightSettings, "Lighting");
if (lightSettings)
{
if (volrendObj.GetRenderMode() == RenderMode.DirectVolumeRendering)
volrendObj.SetLightingEnabled(GUILayout.Toggle(volrendObj.GetLightingEnabled(), "Enable lighting"));
else
TransferFunction2DEditorWindow.ShowWindow();
volrendObj.SetLightingEnabled(false);
if (volrendObj.GetLightingEnabled() || volrendObj.GetRenderMode() == RenderMode.IsosurfaceRendering)
{
LightSource oldLightSource = volrendObj.GetLightSource();
LightSource newLightSource = (LightSource)EditorGUILayout.EnumPopup("Light source", oldLightSource);
if (newLightSource != oldLightSource)
volrendObj.SetLightSource(newLightSource);
}
}
// Other settings for direct volume rendering

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

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8675c369de4b9999692fafb7e5b5be58
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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

@ -0,0 +1,8 @@
namespace UnityVolumeRendering
{
public enum LightSource
{
ActiveCamera,
SceneMainLight
}
}

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

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c9bd811fe872275a4bb14b907b08a56d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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

@ -1,4 +1,6 @@
namespace UnityVolumeRendering
using UnityEngine;
namespace UnityVolumeRendering
{
public enum RenderMode
{
@ -9,7 +11,9 @@
public enum TFRenderMode
{
[InspectorName("1D Transfer Function")]
TF1D,
[InspectorName("2D Transfer Function")]
TF2D
}
}

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

@ -23,6 +23,8 @@ namespace UnityVolumeRendering
private TFRenderMode tfRenderMode;
[SerializeField, HideInInspector]
private bool lightingEnabled;
[SerializeField, HideInInspector]
private LightSource lightSource;
[SerializeField, HideInInspector]
private Vector2 visibilityWindow = new Vector2(0.0f, 1.0f);
@ -84,6 +86,11 @@ namespace UnityVolumeRendering
return lightingEnabled;
}
public LightSource GetLightSource()
{
return lightSource;
}
public void SetLightingEnabled(bool enable)
{
if (enable != lightingEnabled)
@ -93,6 +100,12 @@ namespace UnityVolumeRendering
}
}
public void SetLightSource(LightSource source)
{
lightSource = source;
UpdateMaterialProperties();
}
public void SetVisibilityWindow(float min, float max)
{
SetVisibilityWindow(new Vector2(min, max));
@ -161,6 +174,11 @@ namespace UnityVolumeRendering
else
meshRenderer.sharedMaterial.DisableKeyword("LIGHTING_ON");
if (lightSource == LightSource.SceneMainLight)
meshRenderer.sharedMaterial.EnableKeyword("USE_MAIN_LIGHT");
else
meshRenderer.sharedMaterial.DisableKeyword("USE_MAIN_LIGHT");
switch (renderMode)
{
case RenderMode.DirectVolumeRendering: