Commit 9d349ccc authored by Mustafa Temel's avatar Mustafa Temel
Browse files

grabcut now works

parent 78b3ce41
File added
No preview for this file type
This diff is collapsed.
No preview for this file type
fileFormatVersion: 2 fileFormatVersion: 2
guid: 97443dc830478e445aea6c16fce06c35 guid: 83c6e35c9ac2299488f3dcc25c0ec81b
PluginImporter: PluginImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
......
...@@ -17,12 +17,14 @@ public class NTScript : MonoBehaviour ...@@ -17,12 +17,14 @@ public class NTScript : MonoBehaviour
[DllImport("FancyLibrary", EntryPoint = "Coordinates")] [DllImport("FancyLibrary", EntryPoint = "Coordinates")]
private static extern int Coordinates(); private static extern int Coordinates();
MeshRenderer rend;
void Start() void Start()
{ {
Initialize(); Initialize();
Debug.Log("done"); Debug.Log("done");
m = new Material(Shader.Find("Transparent/Diffuse")); m = new Material(Shader.Find("Transparent/Diffuse"));
rend = GetComponent<MeshRenderer>();
} }
void Update() void Update()
...@@ -49,45 +51,72 @@ public class NTScript : MonoBehaviour ...@@ -49,45 +51,72 @@ public class NTScript : MonoBehaviour
int y = middle % 1000; int y = middle % 1000;
int radius = 350; int radius = 330;
float rSquared = radius * radius; float rSquared = radius * radius;
print(x);
Color tempColor = m.color; Color tempColor = m.color;
Material materialShader;
tempColor.a = 0f; tempColor.a = 0f;
//Material test = (Material)Resources.Load("test", typeof(Material)); ;
m = new Material(Shader.Find("Unlit/camshader"));
rend.material.SetTexture("_MainTex", tex);
for (int u = x - radius; u < x + radius + 1; u++) if (x > 140 && x < 500 && y > 140 && y < 340)
for (int v = y - radius; v < y + radius + 1; v++) {
if (((x - u) * (x - u) + (y - v) * (y - v)) * 5.5 > rSquared) for (int u = x - radius; u < x + radius + 1; u++)
tex.SetPixel(u, v, tempColor); for (int v = y - radius; v < y + radius + 1; v++)
if (((x - u) * (x - u) + (y - v) * (y - v)) * 5.6 > rSquared)
tex.SetPixel(u, v, Color.white);
}
else
{
Color[] cols = tex.GetPixels();
for (int j = 0; j < cols.Length; j++)
cols[j] = tempColor;
tex.SetPixels(cols);
}
/* Material unlit; //rend.GetMaterials(test.SetTexture("_MainText" , tex));
unlit = new Material(Shader.Find("Unlit/camshader")); //rend.material.SetTexture("_MainTex", tex);
this.GetComponent<Renderer>().material = unlit;
for (x=0; x < tex.height; x++) /*else
{
for(y =0; y<tex.width; y++)
{ {
if(tex.GetPixel(x,y) == Color.white) Color[] cols = tex.GetPixels();
{ for (int j = 0; j < cols.Length; j++)
tex.SetPixel(x, y, unlit.color); cols[j] = tempColor;
tex.SetPixels(cols);
} }*/
}
}
//this.GetComponent<Renderer>().material = unlit;*/ /* Material unlit;
unlit = new Material(Shader.Find("Unlit/camshader"));
tex.Apply(); this.GetComponent<Renderer>().material = unlit;
for (x=0; x < tex.height; x++)
{
for(y =0; y<tex.width; y++)
{
if(tex.GetPixel(x,y) == Color.white)
{
tex.SetPixel(x, y, unlit.color);
}
}
}
//this.GetComponent<Renderer>().material = unlit;*/
tex.Apply();
} }
} }
\ No newline at end of file
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
Shader "Unlit/camshader" Shader "Unlit/camshader"
{ {
Properties Properties
{ {
_Color("Main Color", Color) = (1,1,1,1) _Color("Main Color", Color) = (1,1,1,1)
_MainTex("Albedo Texture", 2D) = "white" {} _MainTex("Albedo Texture", 2D) = "white" {}
_Transparency("Transparency", Range(0.0,0.5)) = 0.25 _Transparency("Transparency", Range(0.0,0.5)) = 0.25
} }
SubShader SubShader
{
Tags {"Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
Zwrite On
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off
Pass
{ {
Tags {"Queue" = "Transparent" "RenderType" = "Transparent" }
CGPROGRAM LOD 100
#pragma vertex vert Zwrite On
Blend SrcAlpha OneMinusSrcAlpha
#pragma fragment frag Lighting Off
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
float4 _Color;
float4 _Transparency;
struct appdata Pass
{ {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f CGPROGRAM
{ #pragma vertex vert
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
half4 color : COLOR;
};
sampler2D _MainTex; #pragma fragment frag
float4 _MainTex_ST; // make fog work
#pragma multi_compile_fog
v2f vert (appdata v) #include "UnityCG.cginc"
{ float4 _Color;
v2f o; float4 _Transparency;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o; struct appdata
} {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
fixed4 frag (v2f i) : SV_Target struct v2f
{ {
// sample the texture float2 uv : TEXCOORD0;
fixed4 col = tex2D(_MainTex, i.uv); UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
// apply fog // apply fog
UNITY_APPLY_FOG(i.fogCoord, col);
//col.rgb *= col.a; //col.rgb *= col.a;
if ((i.col.r == 1) && (i.col.g == 1) && (i.col.b == 1)) { if ((col.r == 1) && (col.g == 1) && (col.b == 1)) {
i.col.a = _Transparency; col.a = _Transparency;
} }
return col * i.color; else {
col.a = 1;
}
return col;
} }
ENDCG ENDCG
} }
} }
} }
...@@ -401,201 +401,10 @@ Transform: ...@@ -401,201 +401,10 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1721690122} m_GameObject: {fileID: 1721690122}
m_LocalRotation: {x: -0.7137688, y: 0.038923725, z: 0.0330355, w: 0.6985182} m_LocalRotation: {x: -0.7147604, y: 0.009926202, z: 0.00466171, w: 0.6992835}
m_LocalPosition: {x: 2.34, y: 4.67, z: 8.19} m_LocalPosition: {x: 2.34, y: 4.67, z: 8.19}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1.3033, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 2 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: -91.325, y: -18.195007, z: 24.028} m_LocalEulerAnglesHint: {x: -91.324, y: -18.195007, z: 19.376999}
--- !u!1 &1910093856
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1910093860}
- component: {fileID: 1910093859}
- component: {fileID: 1910093858}
- component: {fileID: 1910093857}
m_Layer: 0
m_Name: Plane (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!64 &1910093857
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1910093856}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 4
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &1910093858
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1910093856}
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_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 58a37150f4196c94fb88b321f1cb2532, 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: 1
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
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1910093859
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1910093856}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1910093860
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1910093856}
m_LocalRotation: {x: -0.71133536, y: -0, z: -0, w: 0.7028527}
m_LocalPosition: {x: 1.65, y: 7.9664736, z: 14.17}
m_LocalScale: {x: 1, y: 1, z: 5.2784}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: -90.688, y: 0, z: 0}
--- !u!1 &2077642783
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2077642787}
- component: {fileID: 2077642786}
- component: {fileID: 2077642785}
- component: {fileID: 2077642784}
m_Layer: 0
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!65 &2077642784
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2077642783}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &2077642785
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2077642783}
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_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 58a37150f4196c94fb88b321f1cb2532, 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: 1
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
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &2077642786
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2077642783}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &2077642787
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2077642783}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.04, y: 7.9665, z: 6.63}
m_LocalScale: {x: 1, y: 51.875267, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 
Microsoft Visual Studio Solution File, Format Version 11.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2010 # Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{5B10DC16-4932-7CE4-E40E-C84BF617406C}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{5B10DC16-4932-7CE4-E40E-C84BF617406C}"
EndProject EndProject
Global Global
......
No preview for this file type
...@@ -19,9 +19,9 @@ MonoBehaviour: ...@@ -19,9 +19,9 @@ MonoBehaviour:
width: 1920 width: 1920
height: 997 height: 997
m_ShowMode: 4 m_ShowMode: 4
m_Title: Hierarchy m_Title: Game
m_RootView: {fileID: 6} m_RootView: {fileID: 6}
m_MinSize: {x: 875, y: 696} m_MinSize: {x: 875, y: 542}
m_MaxSize: {x: 10000, y: 10000} m_MaxSize: {x: 10000, y: 10000}
m_Maximized: 1 m_Maximized: 1
--- !u!114 &2 --- !u!114 &2
...@@ -45,10 +45,10 @@ MonoBehaviour: ...@@ -45,10 +45,10 @@ MonoBehaviour:
y: 30 y: 30
width: 1920 width: 1920
height: 947 height: 947
m_MinSize: {x: 934, y: 646} m_MinSize: {x: 678, y: 492}
m_MaxSize: {x: 14002, y: 14042} m_MaxSize: {x: 14001, y: 14042}
vertical: 0 vertical: 0
controlID: 110 controlID: 121
--- !u!114 &3 --- !u!114 &3
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 52 m_ObjectHideFlags: 52
...@@ -68,8 +68,8 @@ MonoBehaviour: ...@@ -68,8 +68,8 @@ MonoBehaviour:
y: 0 y: 0
width: 456 width: 456
height: 947 height: 947
m_MinSize: {x: 276, y: 71} m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4001, y: 4021} m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 14} m_ActualView: {fileID: 14}
m_Panes: m_Panes:
- {fileID: 14} - {fileID: 14}
...@@ -150,7 +150,7 @@ MonoBehaviour: ...@@ -150,7 +150,7 @@ MonoBehaviour:
y: 0 y: 0
width: 1920 width: 1920
height: 997 height: 997
m_MinSize: {x: 875, y: 696} m_MinSize: {x: 875, y: 542}
m_MaxSize: {x: 10000, y: 10000} m_MaxSize: {x: 10000, y: 10000}
m_UseTopView: 1 m_UseTopView: 1
m_TopViewHeight: 30 m_TopViewHeight: 30
...@@ -223,10 +223,10 @@ MonoBehaviour: ...@@ -223,10 +223,10 @@ MonoBehaviour:
y: 0 y: 0
width: 1464 width: 1464
height: 947 height: 947
m_MinSize: {x: 658, y: 646} m_MinSize: {x: 403, y: 492}
m_MaxSize: {x: 10001, y: 14042} m_MaxSize: {x: 10001, y: 14042}
vertical: 1 vertical: 1
controlID: 111 controlID: 56
--- !u!114 &10 --- !u!114 &10
MonoBehaviour: