├── ProjectSettings ├── ProjectVersion.txt ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── TagManager.asset ├── TimeManager.asset ├── EditorSettings.asset ├── NetworkManager.asset ├── DynamicsManager.asset ├── GraphicsSettings.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset └── UnityConnectSettings.asset ├── .gitattributes ├── Assets ├── Scene │ ├── Main.unity │ └── Main.unity.meta ├── Material │ ├── ObjMat.mat │ ├── CutPlaneMat.mat │ ├── ObjMat.mat.meta │ └── CutPlaneMat.mat.meta ├── Material.meta ├── Scene.meta ├── Script.meta ├── Shader.meta ├── Shader │ ├── ObjShader.shader.meta │ ├── CutPlaneShader.shader.meta │ ├── CutPlaneShader.shader │ └── ObjShader.shader └── Script │ ├── CutPlane.cs.meta │ └── CutPlane.cs ├── README.md └── .gitignore /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.6.2f1 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /Assets/Scene/Main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/Assets/Scene/Main.unity -------------------------------------------------------------------------------- /Assets/Material/ObjMat.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/Assets/Material/ObjMat.mat -------------------------------------------------------------------------------- /Assets/Material/CutPlaneMat.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/Assets/Material/CutPlaneMat.mat -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rcm4/Unity-CutPlane/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity-CutPlane 2 | 3 | ![cutplanegif](https://user-images.githubusercontent.com/1681495/27995863-0147e802-6493-11e7-9ce3-f83f309f1d8d.gif) 4 | -------------------------------------------------------------------------------- /Assets/Scene/Main.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 72d171d033ea1cf49beb9b50358006bd 3 | timeCreated: 1499602975 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Material.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9eaa81ad8a4307a46bac4d08d4b954fd 3 | folderAsset: yes 4 | timeCreated: 1499603065 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scene.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69e3da05ed267da4cba1debf9b3b1371 3 | folderAsset: yes 4 | timeCreated: 1499602970 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Script.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1604d58a291ef9a4891e88e48b48ffa4 3 | folderAsset: yes 4 | timeCreated: 1499603495 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45ec515676e7da34b936732594a44b7a 3 | folderAsset: yes 4 | timeCreated: 1499603069 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shader/ObjShader.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01f4cd1a05df61f4786f56d0cebfb86a 3 | timeCreated: 1499604078 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Shader/CutPlaneShader.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f94671b75b8d12d4d9eeedeb9bfe1045 3 | timeCreated: 1499614424 4 | licenseType: Free 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Material/ObjMat.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ef7147d5f0c82bd4ab7e4a5dbde1e185 3 | timeCreated: 1499603084 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Material/CutPlaneMat.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 63f7dce89fe5b9b478ffde15e3fd17e5 3 | timeCreated: 1499614451 4 | licenseType: Free 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Script/CutPlane.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0481f6aaf7f8ead4e8fd16f0d6913e53 3 | timeCreated: 1499603467 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Autogenerated VS/MD/Consulo solution and project files 9 | ExportedObj/ 10 | .consulo/ 11 | *.csproj 12 | *.unityproj 13 | *.sln 14 | *.suo 15 | *.tmp 16 | *.user 17 | *.userprefs 18 | *.pidb 19 | *.booproj 20 | *.svd 21 | 22 | 23 | # Unity3D generated meta files 24 | *.pidb.meta 25 | 26 | # Unity3D Generated File On Crash Reports 27 | sysinfo.txt 28 | 29 | # Builds 30 | *.apk 31 | *.unitypackage 32 | -------------------------------------------------------------------------------- /Assets/Shader/CutPlaneShader.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/CutPlaneShader" { 2 | Properties { 3 | _Color ("Color", Color) = (1,1,1,1) 4 | } 5 | SubShader { 6 | Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" } 7 | 8 | Cull Off 9 | Blend SrcAlpha OneMinusSrcAlpha 10 | 11 | LOD 200 12 | 13 | CGPROGRAM 14 | #pragma surface surf Standard alpha:fade 15 | #pragma target 3.0 16 | 17 | fixed4 _Color; 18 | 19 | struct Input { 20 | float2 uv_MainTex; 21 | }; 22 | 23 | void surf (Input IN, inout SurfaceOutputStandard o) { 24 | o.Emission = _Color.rgb; 25 | o.Alpha = _Color.a; 26 | } 27 | ENDCG 28 | } 29 | FallBack "Diffuse" 30 | } 31 | -------------------------------------------------------------------------------- /Assets/Script/CutPlane.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class CutPlane : MonoBehaviour { 6 | 7 | private Vector3 normal; 8 | private Vector3 rot; 9 | 10 | public GameObject clipObj; 11 | private Material clipObjMat; 12 | 13 | void Start () { 14 | this.normal = this.GetComponent().mesh.normals[0]; 15 | 16 | float angle = Mathf.Sin(Mathf.PI / 6.0F); 17 | this.rot = Vector3.one * angle; 18 | 19 | this.clipObjMat = clipObj.GetComponent().material; 20 | } 21 | 22 | void Update () { 23 | this.transform.Rotate(this.rot); 24 | 25 | this.clipObjMat.SetVector("_PlaneCenter", this.transform.position); 26 | this.clipObjMat.SetVector("_PlaneNormal", this.transform.TransformDirection(this.normal)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Assets/Shader/ObjShader.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/Obj Shader" { 2 | 3 | Properties{ 4 | _ColorExt("External color", Color) = (1.0, 1.0, 1.0, 1.0) 5 | _ColorInt("Internal color", Color) = (1.0, 1.0, 1.0, 1.0) 6 | _EdgeWidth("Edge width", Range(0.99, 0.5)) = 0.9 7 | 8 | [HideInInspector]_PlaneCenter("Plane Center", vector) = (0, 0, 0, 1) 9 | [HideInInspector]_PlaneNormal("Plane Normal", vector) = (0, 0, -1, 0) 10 | } 11 | 12 | CGINCLUDE 13 | 14 | float4 _PlaneCenter; 15 | float4 _PlaneNormal; 16 | 17 | float Distance2Plane(float3 pt) { 18 | 19 | float3 n = _PlaneNormal.xyz; 20 | float3 pt2 = _PlaneCenter.xyz; 21 | 22 | float d = (n.x*(pt.x - pt2.x)) + (n.y*(pt.y - pt2.y)) + (n.z*(pt.z - pt2.z)) / sqrt(n.x*n.x + n.y*n.y + n.z*n.z); 23 | 24 | return d; 25 | } 26 | 27 | ENDCG 28 | 29 | SubShader{ 30 | Tags{ "Queue" = "Geometry" } 31 | 32 | // Pass 1 33 | Pass{ 34 | 35 | CGPROGRAM 36 | #pragma vertex vert 37 | #pragma fragment frag 38 | #include "UnityCG.cginc" 39 | 40 | struct v2f { 41 | float4 pos : SV_POSITION; 42 | float4 worldPos : TEXCOORD0; 43 | }; 44 | 45 | v2f vert(appdata_base v) 46 | { 47 | v2f o; 48 | o.pos = UnityObjectToClipPos(v.vertex); 49 | o.worldPos = mul(unity_ObjectToWorld, v.vertex); 50 | return o; 51 | } 52 | 53 | fixed4 _ColorExt; 54 | 55 | fixed4 frag(v2f i) : SV_Target{ 56 | clip(-Distance2Plane(i.worldPos.xyz)); 57 | 58 | return _ColorExt; 59 | } 60 | ENDCG 61 | } 62 | 63 | // Pass 2 64 | Pass{ 65 | 66 | Cull Front 67 | 68 | CGPROGRAM 69 | #pragma vertex vert 70 | #pragma fragment frag 71 | #include "UnityCG.cginc" 72 | 73 | struct v2f { 74 | float4 pos : SV_POSITION; 75 | float4 worldPos : TEXCOORD0; 76 | }; 77 | 78 | v2f vert(appdata_base v) 79 | { 80 | v2f o; 81 | o.pos = UnityObjectToClipPos(v.vertex); 82 | o.worldPos = mul(unity_ObjectToWorld, v.vertex); 83 | return o; 84 | } 85 | 86 | fixed4 _ColorInt; 87 | 88 | fixed4 frag(v2f i) : SV_Target{ 89 | clip(-Distance2Plane(i.worldPos.xyz)); 90 | 91 | return _ColorInt; 92 | } 93 | ENDCG 94 | } 95 | 96 | // PASS 3 97 | Pass{ 98 | 99 | CGPROGRAM 100 | #pragma vertex vert 101 | #pragma fragment frag 102 | #include "UnityCG.cginc" 103 | 104 | struct v2f { 105 | float4 pos : SV_POSITION; 106 | float4 worldPos : TEXCOORD0; 107 | }; 108 | 109 | fixed4 _ColorInt; 110 | float _EdgeWidth; 111 | 112 | v2f vert(appdata_base v) 113 | { 114 | v2f o; 115 | v.vertex.xyz *= _EdgeWidth; 116 | o.pos = UnityObjectToClipPos(v.vertex); 117 | o.worldPos = mul(unity_ObjectToWorld, v.vertex); 118 | return o; 119 | } 120 | 121 | fixed4 frag(v2f i) : SV_Target{ 122 | clip(-Distance2Plane(i.worldPos.xyz)); 123 | 124 | return _ColorInt; 125 | } 126 | ENDCG 127 | } 128 | 129 | // PASS 4 130 | Pass{ 131 | 132 | Cull Front 133 | 134 | CGPROGRAM 135 | #pragma vertex vert 136 | #pragma geometry geom 137 | #pragma fragment frag 138 | #include "UnityCG.cginc" 139 | 140 | struct v2g { 141 | float4 pos : SV_POSITION; 142 | float4 worldPos : TEXCOORD0; 143 | }; 144 | 145 | struct g2f { 146 | float4 pos : SV_POSITION; 147 | float4 worldPos : TEXCOORD0; 148 | float3 bary : TEXCOORD1; 149 | }; 150 | 151 | fixed4 _ColorInt; 152 | fixed4 _ColorExt; 153 | 154 | float _EdgeWidth; 155 | 156 | v2g vert(appdata_base v) 157 | { 158 | v2g o; 159 | v.vertex.xyz *= _EdgeWidth; 160 | o.pos = UnityObjectToClipPos(v.vertex); 161 | o.worldPos = mul(unity_ObjectToWorld, v.vertex); 162 | return o; 163 | } 164 | 165 | [maxvertexcount(3)] 166 | void geom(triangle v2g IN[3], inout TriangleStream triStream) { 167 | float3 param = float3(0., 0., 0.); 168 | 169 | float edge1 = length(IN[0].worldPos - IN[1].worldPos); 170 | float edge2 = length(IN[1].worldPos - IN[2].worldPos); 171 | float edge3 = length(IN[2].worldPos - IN[0].worldPos); 172 | 173 | if(edge1 > edge2 && edge1 > edge3) 174 | param.y = 1.; 175 | else if (edge2 > edge3 && edge2 > edge1) 176 | param.x = 1.; 177 | else 178 | param.z = 1.; 179 | 180 | g2f o; 181 | o.pos = mul(UNITY_MATRIX_VP, IN[0].worldPos); 182 | o.bary = float3(1., 0., 0.) + param; 183 | o.worldPos = IN[0].worldPos; 184 | triStream.Append(o); 185 | 186 | o.pos = mul(UNITY_MATRIX_VP, IN[1].worldPos); 187 | o.bary = float3(0., 0., 1.) + param; 188 | o.worldPos = IN[1].worldPos; 189 | triStream.Append(o); 190 | 191 | o.pos = mul(UNITY_MATRIX_VP, IN[2].worldPos); 192 | o.bary = float3(0., 1., 0.) + param; 193 | o.worldPos = IN[2].worldPos; 194 | triStream.Append(o); 195 | } 196 | 197 | fixed4 frag(g2f i) : SV_Target{ 198 | clip(-Distance2Plane(i.worldPos.xyz)); 199 | 200 | float minBary = min(min(i.bary.x, i.bary.y), i.bary.z); 201 | float maxBary = max(max(i.bary.x, i.bary.y), i.bary.z); 202 | 203 | if (minBary >= (1 - _EdgeWidth)) 204 | return _ColorExt; 205 | 206 | return _ColorInt; 207 | } 208 | 209 | ENDCG 210 | } 211 | } 212 | } --------------------------------------------------------------------------------