일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 스랄 특성
- 게임
- 안드로이드
- game
- 아이폰
- 리눅스
- 소캣(Socket)
- tcp
- unity
- 어플
- 변경된 정보
- TCP 네트워크 방식의 연결
- 아이패드
- tcp네트워크
- 비행기 모드
- Collection Framework
- 명령어
- 나지보
- 벨팡
- php 홈디렉토리 변경방법
- 에셋
- 안드로이드 Application Lifecycle
- End of Darkness
- 히오스
- 컬렉션 프레임
- 포트(Port)
- 자바
- 기업의 행포
- 집 정리
- 나지보 특성
- Today
- Total
Do Something IT
Masking textures using shaders NGUI 본문
참조 : 바로가기
If you follow this blog, you know that I am having some problems with Unity3d and NGUI. Mostly it’s because I was so familiar with Flash/AS3 that I am feeling kinda lost. But I am getting better at this 2D in a 3D world thing. One of the thing that I miss the most is masks. In Flash they are very easy to use and with them you can do a plethora of effects and animations. Now with bitmap based technologies, it is not such a simple task to implement a mask.
Clipping
NGUI Panels have the option of being clipped panels, which means that only a rectangle of the panel will be shown. This is great for some cases, like when you need your masked region to be a rectangle, but for most masking cases it won’t work. Also, it doesn’t allow nested clipping which is a bummer.
Using another camera
Also, this guy created a shader that allows you to do similar masking as in Flash. It looks good, and it does the desired effect, but there is one drawback, for every mask, you need a new camera… That makes it very hard to manage in a large project or if you have multiple masks. I would use clipping more than this technique because it is easier to deal with.
Transparency shader
Now, this is the technique I devised that allows you to have multiple textures masked at the same time each with their own masks. This is really good if you load images (thumbnails) from a server and need them to be masked.
To do it we need to create a new shader. We start that by taking the Unlit – Transparent Colored shader and we will add two lines of code to it. First we will give it another texture for input. Secondly, we will take the output of the shader, use its rgb colors, but use the alpha of the new input texture we added. Here is the code :
So that is the shader, but now we have to use it. This is actually what I found to be the most difficult part because there is a lot of documentation about how to make shaders, but not how to use them. So in the next chunk of code, we will create a texture in NGUI, give it a shader. After that we will feed the shader the textures it need to calculate the mask.
In this testRed is the image we want to mask and testAlpha is the alpha channel we want our previous image to use.
So here you have it, I will add pictures later to illustrate it better, but for now that’s how it is. Note that with this technique you can’t really animate or nest the masks, but you can have a lot of them at the same time.
UPDATE : If you are using a version of NGUI that is higher than 2.64, you should probably use this shader instead.
'Unity3D' 카테고리의 다른 글
[유니티 C#]TimeScale 과 독립적으로 작동하는 ParticleSystem (6) | 2014.10.01 |
---|---|
[유니티 c#] TimeScale 과 독립적으로 작동하는 Animation (0) | 2014.10.01 |
FlyingMover (0) | 2014.04.28 |
ScriptableObject 에 데이터가 저장이 제대로 되지 않는 경우 (0) | 2014.04.11 |
[유니티]Coroutine (0) | 2014.03.17 |