'전체 글'에 해당되는 글 1801건

  1. 2019.04.02 인벤토리 만들기 (제너릭)
  2. 2019.04.02 referencesource microsoft
  3. 2019.04.01 IEnumerator, IEnumerable 상속받은 Inventory 구현 (인덱서)
  4. 2019.04.01 C#. 쓰레드(Thread)
  5. 2019.03.31 Unity Shader Study Day-01
  6. 2019.03.29 이것이 자바다 - 1.1 프로그래밍 언어란?

인벤토리 만들기 (제너릭)

Unity3D/C# 2019. 4. 2. 19:07
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_07
{
    class Program
    {
        static void Main(string[] args)
        {
            var app = new App();
            app.Start();
            Console.ReadKey();
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_07
{
    public class App
    {
        //생성자 
        public App()
        {
 
        }
 
        //실행 메서드 
        public void Start()
        {
            var inventory = new Inventory<Equipment>();
 
            //var item = new Equipment("장검", 1);
            //var item2 = new Equipment("장검", 100);
 
            bool isAdded = false;
            inventory.AddItem(new Equipment("장검"1), out isAdded);
            inventory.AddItem(new Equipment("장검"100), out isAdded);
            inventory.AddItem(new Equipment("장검"1), out isAdded);
            inventory.AddItem(new Equipment("장검"1), out isAdded);
            inventory.AddItem(new Equipment("장검"1), out isAdded);
            inventory.AddItem(new Equipment("장검"1), out isAdded);
            inventory.AddItem(new Equipment("장검"1), out isAdded);
            inventory.DisplayItems();
 
            Console.WriteLine();
            inventory.DisplayItems();
 
            var item3 = inventory.GetItem("장검"11);
 
            Console.WriteLine("{0} x{1}개를 꺼냈습니다."item3.name, item3.stack);
 
            Console.WriteLine();
            inventory.DisplayItems();
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_07
{
    //모든 아이템들의 기본 클래스 
    public class Item
    {
        //맴버변수 이름 선언 
        public string name;
        public int stack;
 
        public Item()
        {
 
        }
 
        public Item(string name, int stack) {
            this.name = name;
            this.stack = stack;
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_07
{
    //장비 클래스 
    public class Equipment : Item
    {
        public Equipment() : base()
        {
 
        }
 
        public Equipment(string name, int stack) : base(name, stack)
        {
            Console.WriteLine("{0}이 {1}개 생성되었습니다.", name, stack);
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_07
{
    //약초 클래스 
    public class Herb : Item
    {
        public Herb() : base()
        {
 
        }
        public Herb(string name, int stack) : base(name, stack)
        {
            Console.WriteLine("{0}이 {1}개 생성되었습니다.", name, stack);
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Study_07
{
    public class Inventory<T> where T : Item, new()
    {
        private List<T> items;
 
        public Inventory()
        {
            this.items = new List<T>();
        }
 
        public void AddItem(T item, out bool result)
        {
            if (item == null)
            {
                result = false;
                return;
            }
            else
            {
                Item foundItem = null;
                foreach (var element in this.items)
                {
                    if (element.name.Equals(item.name))
                    {
                        foundItem = element;
                    }
                }
 
                if (foundItem != null)
                {
                    foundItem.stack += item.stack;
                    result = true;
                }
                else
                {
                    result = true;
                    this.items.Add(item);
                }
            }
        }
 
        public T GetItem(string name, int stack = 1
        {
            Item foundItem = null;
            Item rtnItem = null;
 
            foreach (var item in this.items)
            {
                if (item.name == name)
                {
                    foundItem = item;
                }
            }
 
            if (foundItem != null)
            {
                var getStack = 0;
                var remainStack = foundItem.stack;
 
                if (stack >= foundItem.stack)
                {
                    getStack = foundItem.stack;
                    remainStack = 0;
                }
                else {
                    getStack = stack;
                    remainStack = foundItem.stack - getStack;
                    foundItem.stack -= getStack;
                }
 
                rtnItem = new T();
                rtnItem.name = foundItem.name;
                rtnItem.stack = getStack;
 
                if (remainStack <= 0)
                {
                    this.RemoveItem(foundItem.name);
                }
            }
 
            return rtnItem as T;
        }
 
        public bool RemoveItem(string name)
        {
            foreach (var element in items)
            {
                if (element.name.Equals(name))
                {
                    this.items.Remove(element);
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;
        }
 
        public T FindItem(string name)
        {
            foreach (var element in this.items)
            {
                if (element.name == name)
                {
                    return element as T;
                }
            }
            return default (T);
        }
 
        public void UpdateItem(ref T item, string name, int stack)
        {
            if (item == null) {
                Console.WriteLine("업데이트 실패");
                return;
            }
            
            item.name = name;
            item.stack = stack;
        }
 
        public void DisplayItems()
        {
            if (items.Count <= 0)
            {
                Console.WriteLine("인벤토리에 아이템이 없습니다.");
            }
            else
            {
                foreach (var item in this.items)
                {
                    Console.WriteLine("-> {0} x{1}"item.name, item.stack);
                }
            }
        }
    }
}
 
 
 
반응형

'Unity3D > C#' 카테고리의 다른 글

(C#) 타입 비교  (0) 2019.04.05
(C#) Array to Dictionary (Linq)  (0) 2019.04.05
referencesource microsoft  (0) 2019.04.02
IEnumerator, IEnumerable 상속받은 Inventory 구현 (인덱서)  (0) 2019.04.01
C#. 쓰레드(Thread)  (0) 2019.04.01
:

referencesource microsoft

Unity3D/C# 2019. 4. 2. 14:09
반응형

https://referencesource.microsoft.com/

반응형

'Unity3D > C#' 카테고리의 다른 글

(C#) Array to Dictionary (Linq)  (0) 2019.04.05
인벤토리 만들기 (제너릭)  (0) 2019.04.02
IEnumerator, IEnumerable 상속받은 Inventory 구현 (인덱서)  (0) 2019.04.01
C#. 쓰레드(Thread)  (0) 2019.04.01
컬렉션(C#)  (0) 2019.03.28
:

IEnumerator, IEnumerable 상속받은 Inventory 구현 (인덱서)

Unity3D/C# 2019. 4. 1. 23:11
반응형

아이템 추가 하기

출력하기

꺼내기 

foreach가능 하게 만들기 

인덱서 구현 하기 

null값 제거하고 순서 정렬하기 

배열길이 자동증가 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
 
namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var app = new App();
            app.Start();
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
 
namespace ConsoleApp9
{
    class App
    {
        public void Start()
        {
            var inventory = new Inventory();
            inventory[0= new Item("도끼");
            inventory.AddItem(new Item("장검"));
            inventory.AddItem(new Item("단검"));
            inventory[6= new Item("가죽옷");
 
            inventory.DisplayItems();
 
            var searchName = "단검";
            var foundItem = inventory.GetItem(searchName);
            if (foundItem != null)
            {
                Console.WriteLine("{0}을 찾았습니다.", foundItem.itemName);
            }
            else
            {
                Console.WriteLine("{0}은 찾을수 없습니다.", searchName);
            }
            inventory.Arrange();
 
            inventory.DisplayItems();
 
            inventory.AddItem(new Item("단검"));
 
            Console.WriteLine();
            Console.WriteLine();
            inventory.DisplayItems();
 
            inventory[9= new Item("판금갑옷");
            Console.WriteLine();
            Console.WriteLine();
            inventory.Arrange();
            inventory.DisplayItems();
 
 
            inventory.AddItem(new Item("초급용 지팡이"));
            Console.WriteLine();
            Console.WriteLine();
            inventory.DisplayItems();
 
            Console.WriteLine();
            Console.WriteLine();
            foreach (Item item in inventory)
            {
                if (item != null)
                {
                    Console.WriteLine(item.itemName);
                }
               
            }
 
            Console.ReadKey();
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections;
using System.Collections.Generic;
 
namespace ConsoleApp9
{
    public class Inventory : IEnumerator, IEnumerable
    {
 
        private Item[] items = new Item[5];
        private int nextIndex = 0;
        private int position = -1;
 
        public Item this[int index]
        {
            get
            {
                nextIndex = index;
                    
                return this.items[nextIndex];
            }
            set
            {
                nextIndex = index;
                if (this.nextIndex > this.items.Length)
                {
                    Array.Resize<Item>(ref this.items, this.items.Length * 2);
                }
                this.items[nextIndex++= value;
            }
        }
 
        public int Length
        {
            get
            {
                return this.items.Length;
            }
        }
 
        public Item GetItem(string searchName)
        {
            Item foundItem = null;
            for (int i = 0; i < this.items.Length; i++)
            {
                var item = this.items[i];
                if (item != null)
                {
                    if (item.itemName == searchName)
                    {
                        foundItem = item;
                        this.items[i] = null;
                        break;
                    }
                }
            }
            return foundItem;
        }
 
        public void AddItem(Item item)
        {
            if (this.nextIndex > this.items.Length)
            {
                Array.Resize<Item>(ref this.items, this.items.Length * 2);
            }
 
            this.items[this.nextIndex++= item;
        }
 
 
        #region 인터페이스 구현 시작 
        public IEnumerator GetEnumerator()
        {
            return (IEnumerator)this;
        }
 
        public bool MoveNext()
        {
            this.position++;
            return (this.position < this.items.Length);
        }
 
        public void Reset()
        {
            this.position = 0;
        }
 
        public object Current
        {
            get
            {
                return this.items[this.position];
            }
        }
        #endregion 인터페이스 구현 끝 
 
        public void DisplayItems()
        {
            foreach (Item item in this.items)
            {
                if (item == null)
                {
                    Console.WriteLine("---> {0}", item);
                }
                else
                {
                    Console.WriteLine("---> {0}, {1}", item, item.itemName);
                }
            }
        }
 
        public void Arrange()
        {
            Item[] arrTemp = new Item[this.items.Length];
            int tempIdx = 0;
 
            for (int i = 0; i < this.items.Length; i++)
            {
                if (this.items[i] != null)
                {
                    arrTemp[tempIdx++= this.items[i];
                }
            }
            this.nextIndex = tempIdx;
            this.items = arrTemp;
        }
    }
}
 
 
 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
 
namespace ConsoleApp9
{
    public class Item
    {
        public string itemName;
 
        public Item(string itemName)
        {
            this.itemName = itemName;
        }
    }
}
 
 
 

 

반응형

'Unity3D > C#' 카테고리의 다른 글

인벤토리 만들기 (제너릭)  (0) 2019.04.02
referencesource microsoft  (0) 2019.04.02
C#. 쓰레드(Thread)  (0) 2019.04.01
컬렉션(C#)  (0) 2019.03.28
2019.03.26 과제 (와우 케릭터 만들기 C#콘솔)  (0) 2019.03.27
:

C#. 쓰레드(Thread)

Unity3D/C# 2019. 4. 1. 19:04
반응형

프로세스(Process) 와 쓰레드 (Thread)
프로세스는 실행 파일이 실행되어 메모리에 적재된 인스턴스입니다. 
운영체제는 여러가지 프로세스를 동시에 실행할 수 있는 능력을 갖추고 있습니다. 
쓰레드는 운영체제가 CPU 시간을 할당하는 기본 단위인데, 프로세스는 하나 이상의 쓰레드로 구성됩니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
 
namespace Thread_Test_00
{
    class Program
    {
        static void Main(string[] args)
        {
            Account account = new Account();
            Thread ATM = new Thread(new ThreadStart(account.Withdraw3));
            Thread Phone = new Thread(new ThreadStart(account.Withdraw3));
            Thread Internet = new Thread(new ThreadStart(account.Withdraw3));
 
            Console.WriteLine("ATM");
            ATM.Start();
            Console.WriteLine("Phone");
            Phone.Start();
            Console.WriteLine("Internet");
            Internet.Start();
 
            Console.ReadKey();
 
        }
    }
}
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
 
namespace Thread_Test_00
{
    public class Account
    {
        private readonly object lockObj = new object();
        private bool isLocked = false;  //다른쓰레드가 공유자원을 사용하고 있는지 판별
        public int Money { get; set; }
 
        public Account()
        {
            this.Money = 1000;
        }
 
        public void Withdraw()
        {
            lock (this.lockObj)
            {
                if (this.Money <= 0)
                {
                    Console.WriteLine("잔액이 모자랍니다.");
                }
                else
                {
                    this.Money -= 1000;
                }
            }
        }//withdraw
 
        public void Withdraw2()
        {
            Monitor.Enter(this.lockObj);
            try
            {
                if (this.Money <= 0)
                {
                    Console.WriteLine("잔액이 모자랍니다.");
                }
                else
                {
                    this.Money -= 1000;
                }
            }
            finally
            {
                Monitor.Exit(this.lockObj);
            }
        }//withdraw2
 
        public void Withdraw3()
        {
            lock (this.lockObj)
            {
                while (this.isLocked)
                    Monitor.Wait(this.lockObj);
 
                this.isLocked = true;
 
                if (this.Money <= 0)
                {
                    Console.WriteLine("잔액이 모자랍니다.");
                }
                else
                {
                    this.Money -= 1000;
                }
 
                this.isLocked = false;  //다른 쓰레드를 깨움 
                //깨어난 쓰레드들은 while의 조건검사를 통해 wait()을 호출할지를 결정함 
 
                Monitor.Pulse(this.lockObj);
            }
        }//withdraw3 
    }
}
 
 
 
 

참고: https://bit.ly/2OmVlHh

반응형

'Unity3D > C#' 카테고리의 다른 글

referencesource microsoft  (0) 2019.04.02
IEnumerator, IEnumerable 상속받은 Inventory 구현 (인덱서)  (0) 2019.04.01
컬렉션(C#)  (0) 2019.03.28
2019.03.26 과제 (와우 케릭터 만들기 C#콘솔)  (0) 2019.03.27
enum과 비트마스크  (0) 2019.03.26
:

Unity Shader Study Day-01

Graphics Programming 2019. 3. 31. 20:35
반응형

https://ko.wikipedia.org/wiki/%EC%85%B0%EC%9D%B4%EB%8D%94

Shader(셰이더)란 무엇인가? 
컴퓨터 그래픽스 분야에서 셰이더(shader)는 소프트웨어 명령의 집합으로 주로 그래픽 하드웨어의 렌더링 효과를 계산하는 쓰인다.
셰이더는 그래픽 처리장치 (GPU)의 프로그래밍이 가능한 렌더링 파이프라인을 프로그래밍하는데 쓰인다.
셰이더는 3차원 모델링에서 광원과 그림자를 만드는 일반적으로 사용됨

 

 

https://thebookofshaders.com/01/?lan=kr

 

The Book of Shaders

Gentle step-by-step guide through the abstract and complex universe of Fragment Shaders.

thebookofshaders.com

셰이더는 명령어들의 집합이다.
이 명령어들은 스크린위에 낱개의 픽셀마다 실행되고 이 실행이 모두 한번에 일어난다는점이다.
명령어들은 스크린위에 필셀의 위치마다 연산이 달라진다는 말이다 
셋들 자체가 스크린 픽셀 위치를 받고 색을 출력하는 하나의 프로그램이자 함수.
컴파일된 이프로그램은 아주 빠름


"픽셀의 위치를 연산하여 스크린에 색을 출력하는 명령어"


"구텐베르크의 인쇄기술과 같다"


 

 

 

[Unity 2019.1.0b6]


Shader
└ Standard Surface Shader 
└ Unlit Shader 
└ Image Effect Shader
└ Compute Shader 
└ Shader Variant Collection 

http://blog.naver.com/PostView.nhn?blogId=heartybrain1&logNo=221171500861

[Unlit Shader]

Unity의 Unlit Shader는 라이트의 영향을 받지 않는 쉐이더
기본 Standard 쉐이더를 사용하는 오브젝트는 씬의 라이트와 엠비언트에 영향을 받는다.

엠비언트?

http://rapapa.net/?p=2525

3D화면에서 빨간색 공이 제대로 그려지려면 공이 가지는 본래 색과 함께 빛의 영향력을 추가로 적용해서 최종적인 색깔이 나오게 된다.

3D Graphics에서 물체가 가지는 최종적인 색상을 이야기 할때 4가지로 구분한다.
Ambient Color
Diffuse Color
Specular Color
Emissive Color


Ambient Color는 환경에 산란하여 물체가 발하는 평균 색상 혹은 고정 색상이다.
그러므로 물체에 비치는 특정 및에 의해서 영향을 받지 않고 모든 버텍스에 댈해서 동일한 강도를 가진다.
이 색상은 물체의 모든 면에 닿는 강도가 같고 방향이 없다. 그래서 Ambient Color만 적용하여 렌더링한 물체는 Flat한 2D Object처럼 보이게 된다.
그래서 Ambient Color를 물체가 빛을 받지 않는 영역인 어두운 쪽의 색상이라고 한다.



http://developer.download.nvidia.com/CgTutorial/cg_tutorial_chapter03.html


이 장에서는 일련의 간단한 버텍스 및 프래그먼트 프로그램을 통해 Cg 개념을 계속 제시합니다. 이 장에는 다음 세 단원이 있습니다. "매개 변수"는 Cg 프로그램이 매개 변수를 처리하는 방법을 설명합니다. "텍스처 샘플러"에서는 프래그먼트 프로그램이 텍스처에 액세스하는 방법을 설명합니다. "수학 표현식"은 수학 표현식이 새로운 정점 및 단편 값을 계산하는 방법을 보여줍니다.

 

 

The Cg Tutorial - Chapter 3. Parameters, Textures, and Expressions

Unary operators: negation, increment, decrement, positive, negative, indirection, address, cast

developer.download.nvidia.com

매개 변수 2 장의 C2E1v_green 및 C2E2f_passthrough 예제는 매우 기본입니다.

이제 추가 매개 변수를 소개하기 위해 이러한 예제를 확장 할 것입니다.

 

3.1.1 균일 매개 변수 C2E1v_green (2 장의 38 페이지 참조)은 항상 정점 색상에 녹색을 지정합니다.

C2E1v_green 프로그램의 이름을 변경하고 OUT.color의 값을 할당하는 선을 변경하면 잠재적으로 원하는 모든 색상에 대해 다른 정점 프로그램을 만들 수 있습니다.

예를 들어, 적절한 라인을 변경하면 핫 핑크 쉐이더가 생성됩니다.   

OUT.color = float4 (1.0, 0.41, 0.70, 1.0);

// RGBA 핫 핑크 세상은 다채 롭기 때문에 햇볕 아래 모든 색상에 대해 다른 Cg 프로그램을 작성하고 싶지는 않을 것입니다.

대신, 현재 요청한 색상을 나타내는 매개 변수를 전달하여 프로그램을 일반화 할 수 있습니다.

예제 3-1의 C3E1v_anyColor 정점 프로그램은 응용 프로그램이 특정 상수 색상이 아닌 임의의 색상에 지정할 수있는 constantColor 매개 변수를 제공합니다.

예제 3-1. C3E1v_anyColor 정점 프로그램

 

 

 

 

SubShader, Tags, Pass

CGPROGRAM / ENDCG

Vertex Shader function 
#pragma vertex vert 

Pixel Shader function 
#pragma fragment frag 

Demo - output red from Pixel Shader 
return float4(1,0,0,1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Shader "Unlit/TestShader"
{
    SubShader
    {
        Tags { "RenderType"="Opaque" }  
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vs_main    //vertex shader main
            #pragma fragment ps_main    //pixel shader main
 
            #include "UnityCG.cginc"
 
            struct appdata
            {
                float4 vertex : POSITION;
            };
 
            struct v2f
            {
                float4 vertex : SV_POSITION;
            };
 
            v2f vs_main (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                return o;
            }
 
            fixed4 ps_main (v2f i) : SV_Target
            {
                return float4(1,1,0,1);
            }
            ENDCG
        }
    }
}
 
 
 

OpenGL Pipeline

Vertex Shader 

Fragment Shader 

 

Data Type

Scalar Types
float - floating point(32bits)
int - integer 
bool -true/false
half - floating point (16bits)
fixed - fixed point (11bits)

Vector types (also for color)
float4 - xyzw, rgba
float3 - xyz, rgb
float2 - xy, rg
int2/3/4, half2/3/4 ...etc

Matrix Types
float4x4 - translate, rotate, scale, projection
float4x3 - without projection
float 3x3 - without projection, translate

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Test : MonoBehaviour
{
    public Material mat;
 
    // Start is called before the first frame update
    void Start()
    {
        
    }
 
    // Update is called once per frame
    void Update()
    {
        if (mat != null)
        {
            mat.SetFloat("test"Time.time);
        }
    }
}
 
 
 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Unity ShaderLab Property
 
//float property
 
Properties
{
    my_var("My Lovely Variable"float= 0
}
 
//Slider in Inspector 
 
Properties
{
    my_var("My Lovely Variable", range(0,1)) = 0
}
 
 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Shader "Unlit/TestShader"
{
    Properties
    {
        test("my testing"float= 0;
    }
 
    SubShader
    {
        Tags { "RenderType"="Opaque" }  
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vs_main    //vertex shader main
            #pragma fragment ps_main    //pixel shader main
 
            #include "UnityCG.cginc"
 
            struct appdata
            {
                float4 vertex : POSITION;
            };
 
            struct v2f
            {
                float4 vertex : SV_POSITION;
            };
 
            v2f vs_main (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                return o;
            }
 
            float test;
 
            fixed4 ps_main (v2f i) : SV_Target
            {
                return float4(test, 000.1);
            }
            ENDCG
        }
    }
}
 
 
 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Shader "Unlit/TestShader"
{
    Properties
    {
        test("my testing"float= 0
    }
 
    SubShader
    {
        Tags { "RenderType"="Opaque" }  
 
        Pass
        {
            CGPROGRAM
            #pragma vertex vs_main    //vertex shader main
            #pragma fragment ps_main    //pixel shader main
 
            #include "UnityCG.cginc"
 
            struct appdata
            {
                float4 vertex : POSITION;
            };
 
            struct v2f
            {
                float4 vertex : SV_POSITION;
            };
 
            v2f vs_main (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                return o;
            }
 
            float test;
 
            fixed4 ps_main (v2f i) : SV_Target
            {
                return float4(test, 000.1);
            }
            ENDCG
        }
    }
}
 
 
 

반응형

'Graphics Programming' 카테고리의 다른 글

셰이더 시맨틱  (0) 2019.04.27
Shader - Always Visible - [Tutorial][C#]  (0) 2019.04.25
[pdf] Cg-3.1_April2012_ReferenceManual  (0) 2019.04.02
[pdf] CgUsersManual  (0) 2019.04.02
:

이것이 자바다 - 1.1 프로그래밍 언어란?

ETC 2019. 3. 29. 22:22
반응형

https://docs.oracle.com/javase/8/docs/api/

 

Java Platform SE 8

 

docs.oracle.com

 

프로그래밍 언어란?

자바란?

자바개발 환경 구축

자바 프로그램 개발 순서

주석과 실행문

이클립스 설치 

풀인원 설치와 실행 [확인문제]

 

풀인원 : 자바개발 환경 구축에서 생겨나는 다양한 문제를 해결하기 위해 하나의 파일로 제공하는것

(자바개발 환경 구축 + 이클립스 설치)

 

 

프로그래밍 언어 : 소스파일을 작성할때 사용되는 언어 

프로그래밍 언어 작성 -> 컴파일러 -> 기계어 -> 실행 

 

자바란?

1995년 썬마이크로 시스템즈 (썬) 에서 최초로 발표한 언어

- 가전제품에 사용할 목적인 Oak(오우크)언어에서 시작 

- 인터넷 프로그래밍 언어 (네트워크 프로그래밍 언어)로 발전하면서 Java 이름으로 변경 

2010년 오라클에서 인수하여 Java개발, 관리, 배포를 주관하고 있다.

 

자바의 특징 

이식성이 높은 언어다

 

소스코드 파일 -> 컴파일 -> 클래스 파일 -> 실행 (MS윈도우, 리눅스, 맥)

 

객체지향언어이다.

OOP(Object Oriented Programming)란?

- 부품 객체를 먼저 만들고 이것들을 조합해서 전체 프로그램을 완성하는 기법 

자바는 처음부터 OOP 개발용 언어로 설계되었다.

- 캡슐화, 상속, 다형성 기능을 완벽 하게 지원 

 

자바 8

함수적 스타일 코딩을 지원한다.

함수적 스타일 코딩 방식인 람다식 (Lambda Expressions)을 지원

- 코드를 간결하게 작성할 수 있다.

- 컬렉션 요소를 필터링, 매핑, 그룹핑, 집계 처리시 주로 사용.

 

메모리를 자동으로 관리 (GC)

- 사용하지 않는 객체를 자동으로 메모리에서 제거 

- 메모리 관리보다 핵심 기능 코드에 집중할수 있도록 해줌

 

다양한 애플리케이션을 개발할수 있다.

- 콘솔프로그램, UI애플리케이션, 서버애플리케이션, 모바일 앱 등을 개발 할수있다.

- 다양한 애플리케이션을 위한 개발도구와 API를 에디션 형태로 구분 

 

Java SE(Standard Edition) 기본 에디션 

- 자바 프로그램을 실행 시키는 JVM정의 

- 자바 프로그램들이 공통으로 사용하는 개발 도구와 API정의

- 구현체 JDK (Java Development Kit)

 

Java EE(Enterprise Edition) - 서버 애플리케이션 개발 에디션 

- 웹 애플리케이션, 웹 서비스, 분산 컴포넌트를 위한 개발도구와 API정의 

- 구현체 : WAS (Web Application Sever) -Tomcat, WEbLogic, Jeus, Jboss 등

 

Java ME(Micro Edition)

- 임베디드 또는 모바일 장비를 위한 개발도구와 API정의 

 

멀티 스레드 (Multi-Thread)를 쉽게 구현할 수 있다.

- 동시에 여러작업을 할 경우 

- 대용량 작업을 빨리 처리할 경우 

- 운영체제 별로 멀티 스레드를 이용하는 API가 다름 -> Java API로 일관된 생성 및 관리 

 

 

동적 로딩(Dynamic Loading)을 지원한다.

- 미리 객체를 만들어 놓지 않고  필요한 시점에서 동적으로 로딩해서 객체를 생성

- 유지보수시 특정 객체만 쉽게 수정 및 교체 하여 사용할수 있음.

 

막강한 오픈소스 라이브러리가 풍부하다.

 

자바 개발 도구 (JDK)설치

- Java SE 구현체의 종류 

- JDK (Java Development Kit) = JRE + 개발도구  (자바 프로그램을 개발하고 실행하기 위해 반드시 설치 )

- JRE (Java Runtime Environment) = JVM + 표준 클래스 라이브러리 (자바 프로그램을 실행만 할 경우 )

 

JDK설치 

- 설치 파일 다운로드 : https://www.oracle.com/technetwork/java/javase/overview/index.html

 

Java SE | Oracle Technology Network | Oracle

General FAQs Java Platform, Standard Edition (Java SE) lets you develop and deploy Java applications on desktops and servers. Java offers the rich user interface, performance, versatility, portability, and security that t

www.oracle.com

브라우저에서 돌아가는 Java Applet (자바 애플릿) 이라는것이 실행하기 위해서 필요함.

환경변수 생성 및 수정 

1 : 로그인한 사람들이 사용할 환경변수, 2: 해당 PC를 사용하는 모든 사용자 

 

 

반응형
: