TA Rio
2020. 5. 24. 10:48
|
|
|
|
|
유니티는 프레임 디버거를 이용하여 매 프레임마다 그려지는 게임오브젝트의 순서를 눈으로 확인할수 있다.
|
|
|
|
어떤것부터 그리는지 알수없다.
|
|
|
|
그려지는 순서에 따라 오브젝트가 가려질수 있다.
|
|
|
|
|
|
|
|
불투명 오브젝트를 먼저 그린다.
|
|
|
|
반투명 오베즉트는 나중에 그린다.
|
|
|
|
반투명 오브젝트끼리는 뒤에서부터 그린다.
|
|
|
|
알파 소팅을 써봤자 완벽하게 앞뒤를 제대로 판정할수 없으니, 알파를 썼을때 문제는 일어난다.
|
|
|
|
알파 블렌딩을 사용하였을때에는 Zwrite를 하지 않는다.
|
|
|
|
이문제를 해결하기 위하여 고민이 필요하다.
|
|
|
|
|
|
|
|
|
|
|
z Buffer
|
앞뒤 판정을 위해서 각 픽셀마다 기준으로 가장 가까운 오브젝트의 깊이값이 저장되어있는 데이터
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OverDraw
|
그려진 이미지위에 덧그려지는 것
|
|
|
|
|
|
|
|
|
|
|
Alpha sorting
|
멀리 있는것부터 차례대로 그리는 것
|
|
|
|
|
|
|
Deferred Rendering
|
반투명을 처리할수 없다.(할수있지만 어렵다?)
|
|
|
|
|
|
|
Foward Rendering
|
|
|
|
|
|
|
|
Opaque
|
불투명
|
|
|
|
|
|
|
Transparent
|
반투명
|
|
|
|
|
|
|
|
|
|
|
알파 구현1
|
Shader "Custom/108_alpha" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} }
|
이미지는 옵션을 clamp 두는것이 좋다. 그래야 반복되는 부분의 끝부분이 보인다던가 하는 문제를 해결할수 있다.
|
|
|
SubShader { Tags { "RenderType"="Transparent" "Queue"= "Transparent"} cull off
CGPROGRAM #pragma surface surf Lambert alpha:fade
|
cull off 양면구현
|
|
|
sampler2D _MainTex;
struct Input { float2 uv_MainTex; };
|
|
|
|
void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG
|
|
|
|
} FallBack "Legacy Shaders/Transparent/VertexLit" //"Diffuse" }
|
Diffuse로 놓으면 폴리곤 형태 그대로의 그림자가 나오게 된다. 이부분은 그림자를 끄는것이고 이를 사실 완전한 구현이라 할수없다. 그래서 AlphaTest(Cutout) 쉐이더를 사용한다.
Legacy Shaders/Transparent/Diffuse 이렇게해도 결과는 같다.
|
|
|
|
|
|
알파 구현2 (알파된 오브젝트 그림자 구현)
|
Shader "Custom/109_alpha_cutout" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Cutoff ("Alpha cutoff", Range(0,1))=0.5 }
|
|
하나는 알파테스트이고, 하나는 그냥 트랜스파렌트이다. 둘다 적용이 가능하다.
|
|
SubShader {
Tags { "RenderType"="TransparentCutout" "Queue"= "AlphaTest"} cull off
CGPROGRAM #pragma surface surf Lambert alphatest:_Cutoff
|
SubShader { Tags { "RenderType"="Transparent" "Queue"= "Transparent"}
cull off
CGPROGRAM #pragma surface surf Lambert alpha:fade
|
|
|
sampler2D _MainTex;
struct Input { float2 uv_MainTex; };
|
|
|
|
void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } FallBack "Legacy Shaders/Transparent/Cutout/VertexLit"
|
void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } FallBack "Legacy Shaders/Transparent/Cutout/VertexLit"
|
|
유니티 쉐이더 스타트업 자료(정종필저)