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
guid: 97443dc830478e445aea6c16fce06c35
guid: 83c6e35c9ac2299488f3dcc25c0ec81b
PluginImporter:
externalObjects: {}
serializedVersion: 2
......
......@@ -17,12 +17,14 @@ public class NTScript : MonoBehaviour
[DllImport("FancyLibrary", EntryPoint = "Coordinates")]
private static extern int Coordinates();
MeshRenderer rend;
void Start()
{
Initialize();
Debug.Log("done");
m = new Material(Shader.Find("Transparent/Diffuse"));
rend = GetComponent<MeshRenderer>();
}
void Update()
......@@ -49,45 +51,72 @@ public class NTScript : MonoBehaviour
int y = middle % 1000;
int radius = 350;
int radius = 330;
float rSquared = radius * radius;
print(x);
Color tempColor = m.color;
Material materialShader;
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++)
for (int v = y - radius; v < y + radius + 1; v++)
if (((x - u) * (x - u) + (y - v) * (y - v)) * 5.5 > rSquared)
tex.SetPixel(u, v, tempColor);
if (x > 140 && x < 500 && y > 140 && y < 340)
{
for (int u = x - radius; u < x + radius + 1; u++)
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;
unlit = new Material(Shader.Find("Unlit/camshader"));
this.GetComponent<Renderer>().material = unlit;
//rend.GetMaterials(test.SetTexture("_MainText" , tex));
//rend.material.SetTexture("_MainTex", tex);
for (x=0; x < tex.height; x++)
{
for(y =0; y<tex.width; y++)
/*else
{
if(tex.GetPixel(x,y) == Color.white)
{
tex.SetPixel(x, y, unlit.color);
}
}
}
//this.GetComponent<Renderer>().material = unlit;*/
tex.Apply();
Color[] cols = tex.GetPixels();
for (int j = 0; j < cols.Length; j++)
cols[j] = tempColor;
tex.SetPixels(cols);
}*/
/* Material unlit;
unlit = new Material(Shader.Find("Unlit/camshader"));
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"
{
Properties
{
_Color("Main Color", Color) = (1,1,1,1)
_Color("Main Color", Color) = (1,1,1,1)
_MainTex("Albedo Texture", 2D) = "white" {}
_Transparency("Transparency", Range(0.0,0.5)) = 0.25
}
SubShader
{
Tags {"Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
Zwrite On
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
float4 _Color;
float4 _Transparency;
Tags {"Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 100
Zwrite On
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off
struct appdata
Pass
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
half4 color : COLOR;
};
CGPROGRAM
#pragma vertex vert
sampler2D _MainTex;
float4 _MainTex_ST;
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
#include "UnityCG.cginc"
float4 _Color;
float4 _Transparency;
return o;
}
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
struct v2f
{
float2 uv : TEXCOORD0;
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
UNITY_APPLY_FOG(i.fogCoord, col);
//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
}
}
}
}
......@@ -401,201 +401,10 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
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_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 1.3033, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: -91.325, y: -18.195007, z: 24.028}
--- !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}
m_LocalEulerAnglesHint: {x: -91.324, y: -18.195007, z: 19.376999}

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assembly-CSharp", "Assembly-CSharp.csproj", "{5B10DC16-4932-7CE4-E40E-C84BF617406C}"
EndProject
Global
......
No preview for this file type
......@@ -19,9 +19,9 @@ MonoBehaviour:
width: 1920
height: 997
m_ShowMode: 4
m_Title: Hierarchy
m_Title: Game
m_RootView: {fileID: 6}
m_MinSize: {x: 875, y: 696}
m_MinSize: {x: 875, y: 542}
m_MaxSize: {x: 10000, y: 10000}
m_Maximized: 1
--- !u!114 &2
......@@ -45,10 +45,10 @@ MonoBehaviour:
y: 30
width: 1920
height: 947
m_MinSize: {x: 934, y: 646}
m_MaxSize: {x: 14002, y: 14042}
m_MinSize: {x: 678, y: 492}
m_MaxSize: {x: 14001, y: 14042}
vertical: 0
controlID: 110
controlID: 121
--- !u!114 &3
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -68,8 +68,8 @@ MonoBehaviour:
y: 0
width: 456
height: 947
m_MinSize: {x: 276, y: 71}
m_MaxSize: {x: 4001, y: 4021}
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 14}
m_Panes:
- {fileID: 14}
......@@ -150,7 +150,7 @@ MonoBehaviour:
y: 0
width: 1920
height: 997
m_MinSize: {x: 875, y: 696}
m_MinSize: {x: 875, y: 542}
m_MaxSize: {x: 10000, y: 10000}
m_UseTopView: 1
m_TopViewHeight: 30
......@@ -223,10 +223,10 @@ MonoBehaviour:
y: 0
width: 1464
height: 947
m_MinSize: {x: 658, y: 646}
m_MinSize: {x: 403, y: 492}
m_MaxSize: {x: 10001, y: 14042}
vertical: 1
controlID: 111
controlID: 56
--- !u!114 &10
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -248,10 +248,10 @@ MonoBehaviour:
y: 0
width: 1464
height: 561
m_MinSize: {x: 658, y: 375}
m_MinSize: {x: 403, y: 221}
m_MaxSize: {x: 8003, y: 4021}
vertical: 0
controlID: 112
controlID: 57
--- !u!114 &11
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -262,7 +262,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 1
m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0}
m_Name: AssetStoreWindow
m_Name: SceneView
m_EditorClassIdentifier:
m_Children: []
m_Position:
......@@ -271,15 +271,15 @@ MonoBehaviour:
y: 0
width: 1101
height: 561
m_MinSize: {x: 457, y: 375}
m_MinSize: {x: 202, y: 221}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 12}
m_ActualView: {fileID: 16}
m_Panes:
- {fileID: 16}
- {fileID: 17}
- {fileID: 12}
m_Selected: 2
m_LastSelected: 0
m_Selected: 0
m_LastSelected: 1
--- !u!114 &12
MonoBehaviour:
m_ObjectHideFlags: 52
......@@ -358,9 +358,9 @@ MonoBehaviour:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 623a0000
m_LastClickedID: 14946
m_ExpandedIDs: 00000000623a000000ca9a3b
m_SelectedIDs: 4c3a0000
m_LastClickedID: 14924
m_ExpandedIDs: 000000004c3a000000ca9a3b
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
......@@ -388,7 +388,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 00000000623a0000
m_ExpandedIDs: 000000004c3a0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
......@@ -503,8 +503,8 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: -32000
y: -31970