Centralised code for setting material properties, and made sure the gradient texture is null when not needed.

This commit is contained in:
Matias Lavik 2020-02-26 18:55:58 +01:00
Родитель d012728c2e
Коммит 01e47a3052
6 изменённых файлов: 55 добавлений и 25 удалений

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

@ -148,9 +148,8 @@ namespace UnityVolumeRendering
tf2d.GenerateTexture();
needsRegenTexture = false;
}
// TODO:
volRendObject.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_TFTex", tf2d.GetTexture());
volRendObject.GetComponent<MeshRenderer>().sharedMaterial.EnableKeyword("TF2D_ON");
volRendObject.SetTransferFunctionMode(TFRenderMode.TF2D);
return;
}

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

@ -189,9 +189,7 @@ namespace UnityVolumeRendering
GUI.skin.label.wordWrap = false;
GUI.Label(new Rect(0.0f, bgRect.y + bgRect.height + 85.0f, 700.0f, 30.0f), "Left click to select and move a control point. Right click to add a control point, and ctrl + right click to delete.");
// TEST!!! TODO
volRendObject.GetComponent<MeshRenderer>().sharedMaterial.SetTexture("_TFTex", tfTexture);
volRendObject.GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("TF2D_ON");
volRendObject.SetTransferFunctionMode(TFRenderMode.TF1D);
GUI.color = oldColour;
}

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

@ -10,7 +10,7 @@ namespace UnityVolumeRendering
{
VolumeRenderedObject myTarget = (VolumeRenderedObject)target;
RenderMode oldRenderMode = myTarget.GetRemderMode();
RenderMode oldRenderMode = myTarget.GetRenderMode();
RenderMode newRenderMode = (RenderMode)EditorGUILayout.EnumPopup("Render mode", oldRenderMode);
if (newRenderMode != oldRenderMode)

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

@ -6,4 +6,10 @@
MaximumIntensityProjectipon,
IsosurfaceRendering
}
public enum TFRenderMode
{
TF1D,
TF2D
}
}

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

@ -28,7 +28,7 @@ namespace UnityVolumeRendering
volObj.transferFunction2D = tf2D;
meshRenderer.sharedMaterial.SetTexture("_DataTex", dataset.GetDataTexture());
meshRenderer.sharedMaterial.SetTexture("_GradientTex", dataset.GetGradientTexture());
meshRenderer.sharedMaterial.SetTexture("_GradientTex", null);
meshRenderer.sharedMaterial.SetTexture("_NoiseTex", noiseTexture);
meshRenderer.sharedMaterial.SetTexture("_TFTex", tfTexture);

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

@ -13,7 +13,8 @@ namespace UnityVolumeRendering
[HideInInspector]
public VolumeDataset dataset;
private RenderMode remderMode;
private RenderMode renderMode;
private TFRenderMode tfRenderMode;
public SlicingPlane CreateSlicingPlane()
{
@ -34,37 +35,63 @@ namespace UnityVolumeRendering
public void SetRenderMode(RenderMode mode)
{
remderMode = mode;
renderMode = mode;
UpdateMaaterialProperties();
}
switch (mode)
public void SetTransferFunctionMode(TFRenderMode mode)
{
tfRenderMode = mode;
UpdateMaaterialProperties();
}
public RenderMode GetRenderMode()
{
return renderMode;
}
private void UpdateMaaterialProperties()
{
MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
bool useGradientTexture = tfRenderMode == TFRenderMode.TF2D || renderMode == RenderMode.IsosurfaceRendering;
meshRenderer.sharedMaterial.SetTexture("_GradientTex", useGradientTexture ? dataset.GetGradientTexture() : null);
if(tfRenderMode == TFRenderMode.TF2D)
{
meshRenderer.sharedMaterial.SetTexture("_TFTex", transferFunction2D.GetTexture());
meshRenderer.sharedMaterial.EnableKeyword("TF2D_ON");
}
else
{
meshRenderer.sharedMaterial.SetTexture("_TFTex", transferFunction.GetTexture());
meshRenderer.sharedMaterial.DisableKeyword("TF2D_ON");
}
switch (renderMode)
{
case RenderMode.DirectVolumeRendering:
{
GetComponent<MeshRenderer>().sharedMaterial.EnableKeyword("MODE_DVR");
GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("MODE_MIP");
GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("MODE_SURF");
meshRenderer.sharedMaterial.EnableKeyword("MODE_DVR");
meshRenderer.sharedMaterial.DisableKeyword("MODE_MIP");
meshRenderer.sharedMaterial.DisableKeyword("MODE_SURF");
break;
}
case RenderMode.MaximumIntensityProjectipon:
{
GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("MODE_DVR");
GetComponent<MeshRenderer>().sharedMaterial.EnableKeyword("MODE_MIP");
GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("MODE_SURF");
meshRenderer.sharedMaterial.DisableKeyword("MODE_DVR");
meshRenderer.sharedMaterial.EnableKeyword("MODE_MIP");
meshRenderer.sharedMaterial.DisableKeyword("MODE_SURF");
break;
}
case RenderMode.IsosurfaceRendering:
{
GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("MODE_DVR");
GetComponent<MeshRenderer>().sharedMaterial.DisableKeyword("MODE_MIP");
GetComponent<MeshRenderer>().sharedMaterial.EnableKeyword("MODE_SURF");
meshRenderer.sharedMaterial.DisableKeyword("MODE_DVR");
meshRenderer.sharedMaterial.DisableKeyword("MODE_MIP");
meshRenderer.sharedMaterial.EnableKeyword("MODE_SURF");
break;
}
}
}
public RenderMode GetRemderMode()
{
return remderMode;
}
}
}