Centralised code for setting material properties, and made sure the gradient texture is null when not needed.
This commit is contained in:
Родитель
d012728c2e
Коммит
01e47a3052
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче