Skip to content

Commit

Permalink
add inverse masking function for de-occlusion component
Browse files Browse the repository at this point in the history
  • Loading branch information
NUZEROVI committed Oct 29, 2022
1 parent 27c89dc commit c925625
Show file tree
Hide file tree
Showing 21 changed files with 2,083 additions and 48 deletions.
70 changes: 70 additions & 0 deletions Assets/Debugging/ShaderDebugging_Mask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using UnityEngine;

namespace UnityVolumeRendering
{
public class ShaderDebugging_Mask : MonoBehaviour
{
public GameObject target_Mask;

private Material material_Mask;
private ComputeBuffer buffer_Mask;
public Vector4[] element_Mask;
private string label_Mask;
private Renderer render_Mask;

MeshRenderer meshRenderer_Mask;
Material mat_Mask;


void Load()
{
buffer_Mask = new ComputeBuffer(10, 16, ComputeBufferType.Default);
element_Mask = new Vector4[10];
for(int i=0; i < buffer_Mask.count; i++)
{
element_Mask[i] = new Vector4(0, 0, 0, 0);
}
buffer_Mask.SetData(element_Mask);

label_Mask = string.Empty;
render_Mask = target_Mask.GetComponent<Renderer>();
material_Mask = render_Mask.material;
}

void Start()
{
Load();
VolumeRenderedObject_Mask[] objects_Mask = FindObjectsOfType<VolumeRenderedObject_Mask>();
if (objects_Mask.Length == 1)
{
meshRenderer_Mask = objects_Mask[0].meshRenderer;
mat_Mask = meshRenderer_Mask.material;
}
}

void Update()
{
Graphics.ClearRandomWriteTargets();
material_Mask.SetPass(0);
material_Mask.SetBuffer("buffer_Mask", buffer_Mask);
Graphics.SetRandomWriteTarget(2, buffer_Mask, false);

buffer_Mask.GetData(element_Mask);

label_Mask = (element_Mask != null && render_Mask.isVisible) ? element_Mask[0].ToString() : string.Empty;
}

void OnGUI()
{
GUIStyle style = new GUIStyle();

GUI.color = Color.white;
style.fontSize = 32;
}

void OnDestroy()
{
buffer_Mask.Dispose();
}
}
}
11 changes: 11 additions & 0 deletions Assets/Debugging/ShaderDebugging_Mask.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions Assets/Materials/DirectVolumeRenderingMaterial_Mask.mat
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: DirectVolumeRenderingMaterial_Mask
m_Shader: {fileID: 4800000, guid: a20d4a69f209bf64ea10de5efd333aa5, type: 3}
m_ShaderKeywords: MODE_DVR TF2D_ON _MODE_DVR _MODE_MIP
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses:
- pass0
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DataTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _GradientTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _NoiseTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _SegmentTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _TFTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _GlossMapScale: 1
- _Glossiness: 0.5
- _GlossyReflections: 1
- _MaxVal: 1
- _Metallic: 0
- _MinVal: 0
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
8 changes: 8 additions & 0 deletions Assets/Materials/DirectVolumeRenderingMaterial_Mask.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions Assets/Resources/VolumeContainer_Mask.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1642054173293210335
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3483431779698201852}
- component: {fileID: 4600922654780393457}
- component: {fileID: 1185744897911437941}
m_Layer: 0
m_Name: VolumeContainer_Mask
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3483431779698201852
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1642054173293210335}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &4600922654780393457
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1642054173293210335}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &1185744897911437941
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1642054173293210335}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 4294967295
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: dff8f83be22f4104b838e8253440b566, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
7 changes: 7 additions & 0 deletions Assets/Resources/VolumeContainer_Mask.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 68 additions & 7 deletions Assets/Scripts/GUI/UI/AnalysisBtn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public class AnalysisBtn : MonoBehaviour
public string isoRangeFilePath;
public string tFFilePath;
public string segTexturePath;
MeshRenderer meshRenderer;
Material mat;
MeshRenderer meshRenderer, meshRenderer_Mask;
Material mat, mat_Mask;
public float[] isoRange = new float[20];
public Vector4[] isoCluster = new Vector4[20];

Expand Down Expand Up @@ -73,6 +73,7 @@ void BtnClick(string btn)
endianness = initData.endianness;
ImportRawData();
GetIsoRangeAndSetTF();
GetIsoRangeAndSetTF_Mask();
}
}

Expand Down Expand Up @@ -106,14 +107,20 @@ private void ImportRawData()
}

VolumeRenderedObject obj = VolumeObjectFactory.CreateObject(dataset);

if(eulerX == 180.0f)
VolumeRenderedObject_Mask obj_Mask = VolumeObjectFactory_Mask.CreateObject(dataset);

if (eulerX == 180.0f)
{
obj.gameObject.transform.rotation *= Quaternion.AngleAxis(90, Vector3.right);
}else if(eulerX == 0.0f)
obj_Mask.gameObject.transform.rotation *= Quaternion.AngleAxis(90, Vector3.right);
}
else if(eulerX == 0.0f)
{
obj.gameObject.transform.rotation *= Quaternion.AngleAxis(-90, Vector3.right);
obj_Mask.gameObject.transform.rotation *= Quaternion.AngleAxis(-90, Vector3.right);
}


}
else
{
Expand Down Expand Up @@ -161,12 +168,66 @@ void GetIsoRangeAndSetTF()
//{
TransferFunction newTF = TransferFunctionDatabase.LoadTransferFunction(tFFilePath);
if (newTF != null)
{
objects[0].transferFunction = newTF;
//objects[0].SetVisibilityWindow(0.58f, 1.0f);
objects[0].UpdateMaterialProperties();
// }
// }
}


}


void GetIsoRangeAndSetTF_Mask()
{
VolumeRenderedObject_Mask[] objects_Mask = FindObjectsOfType<VolumeRenderedObject_Mask>();
if (objects_Mask.Length == 1)
{
meshRenderer_Mask = objects_Mask[0].meshRenderer;
mat_Mask = meshRenderer_Mask.material;
}
//if(isoRangeFilePath != "")
//{
List<string> fileLines = File.ReadAllLines(isoRangeFilePath).ToList();

int range = 0; //dataset.GetMinDataValue();
int Count = 0;
foreach (string line in fileLines)
{
range += int.Parse(line);

isoRange[Count] = range;

if (Count == 0)
{
isoCluster[Count] = new Vector4(0, isoRange[Count] - 1);
}
else
{
isoCluster[Count] = new Vector4(isoRange[Count - 1], isoRange[Count] - 1);
}
Count++;
}

mat_Mask.SetInt("_isoCount", Count);
mat_Mask.SetFloatArray("_isoRange", isoRange);
mat_Mask.SetVectorArray("_isoCluster", isoCluster);
// }

//if (tFFilePath != "")
//{
TransferFunction newTF = TransferFunctionDatabase.LoadTransferFunction(tFFilePath);
if (newTF != null)
{
objects_Mask[0].transferFunction = newTF;
//objects[0].SetVisibilityWindow(0.58f, 1.0f);
objects_Mask[0].UpdateMaterialProperties();
// }
}


}

}
}
Loading

0 comments on commit c925625

Please sign in to comment.