- Normal Extrusion -
정점 쉐이더에서 들어오는 정점 데이터를 수정하는 vertex modifier 함수를 사용할 수 있습니다. 이것은 절차적 애니메이션과 법선을 따라 돌출하는 등에 사용할 수 있습니다. 따라서 표면 쉐이더 컴파일 지시문 vertex:functionName이 사용되지만, 이것은 inout appdata_full 파라미터를 취하는 함수입니다.
다음은, 메테리얼에서 지정한 양만큼 법선을 따라 정점을 움직이는 쉐이더입니다.
법선을 따라 정점을 움직여 몸이 팅팅 부은 거 같다.?
- Outline -
http://www.gamedevforever.com/18
엄밀히 말하면 시야와 오브젝트의 면이 방향이 정확히 수직인 상태의 외곽선만 보이는 것은 아닙니다. 오브젝트와 확대된 뒷면의 사이 공간이 외곽선의 역할을 하는 것이지요. 하지만 시각적으로는 매우 만족할 만한 외곽선이 탄생하게 되지요.
똑바로 안된 모습 그림자 같이 보임.
쉐이더 코드
일단 Standard Surface Shader를 생성하고, Properties에 추가
_Outline ("Outline", Range (.002, 0.03)) = .005
_OutlineColor ("Outline Color", Color) = (0,0,0,1)
ENDCG 다음 줄부터 아래 코드
Outline = 0.02 ~ 0.03 정도로 Range를 만들어준다.
OutlineColor = Color로 생성해준다.
외곽선이 예쁘게 잘 안 그려진다.
해결 방법
완성 사진
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 | Shader "Custom/Outline_Fresnel" { Properties { _MainTex ("Albedo", 2D) = "white" {} _BumpMap("BumpMap", 2D) = "bump" {} _OutlineColor("OutlineColor", Color) = (1,1,1,1) _Outline("Outline", Range(0.1, 0.4)) = 0.2 } SubShader { Tags { "RenderType"="Opaque" } Cull back CGPROGRAM #pragma surface surf Toon fixed4 _Color; sampler2D _MainTex; sampler2D _BumpMap; struct Input { float2 uv_MainTex; float2 uv_BumpMap; }; fixed4 _OutlineColor; fixed _Outline; void surf(Input In, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, In.uv_MainTex); o.Albedo = c.rgb; o.Normal = UnpackNormal(tex2D(_BumpMap, In.uv_BumpMap)); o.Alpha = c.a; } fixed4 LightingToon(SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten) { float halfLambert = dot(s.Normal, lightDir) * 0.5 + 0.5; if (halfLambert > 0.7) { halfLambert = 1; } else { halfLambert = 0.3; } fixed4 final; float rim = abs(dot(s.Normal, viewDir)); if (rim > _Outline) { rim = 1; final.rgb = s.Albedo; } else { rim = -1; final.rgb = _OutlineColor.rgb * rim; } final.rgb = final.rgb * halfLambert *_LightColor0.rgb * rim; final.a = s.Alpha; return final; } ENDCG } FallBack "Diffuse" } | cs |
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 | Shader "Custom/Outline_HalfLambert" { Properties { _MainTex ("Albedo", 2D) = "white" {} _BumpMap("BumpMap", 2D) = "bump" {} _OutlineColor("OutlineColor", Color) = (1,1,1,1) _Outline("Outline", Range(0.0005, 0.01)) = 0.01 } SubShader { Tags { "RenderType"="Opaque" } Cull front // Pass1 CGPROGRAM #pragma surface surf NoLighting vertex:vert noshadow noambient sampler2D _MainTex; sampler2D _BumpMap; struct Input { float2 uv_MainTex; float2 uv_BumpMap; }; fixed4 _OutlineColor; float _Outline; void vert(inout appdata_full v) { v.vertex.xyz += v.normal.xyz * _Outline; } void surf(Input In, inout SurfaceOutput o) { } fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) { return _OutlineColor; } ENDCG // Pass2 Cull back CGPROGRAM #pragma surface surf Toon fixed4 _Color; sampler2D _MainTex; sampler2D _BumpMap; struct Input { float2 uv_MainTex; float2 uv_BumpMap; fixed4 color : Color; }; void surf(Input In, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, In.uv_MainTex); o.Albedo = c.rgb; o.Normal = UnpackNormal(tex2D(_BumpMap, In.uv_BumpMap)); o.Alpha = c.a; } fixed4 LightingToon(SurfaceOutput s, fixed3 lightDir, fixed atten) { fixed halfLambert = dot(s.Normal, lightDir) * 0.5 + 0.5; halfLambert = ceil(halfLambert * 5) / 5; fixed4 final; final.rgb = s.Albedo * halfLambert *_LightColor0.rgb; final.a = s.Alpha; return final; } ENDCG } FallBack "Diffuse" } | cs |
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 | Shader "Custom/Outline_2Pass" { Properties { _MainTex ("Albedo", 2D) = "white" {} _BumpMap("BumpMap", 2D) = "bump" {} _OutlineColor("OutlineColor", Color) = (1,1,1,1) _Outline("Outline", Range(0.0005, 0.01)) = 0.01 } SubShader { Tags { "RenderType"="Opaque" } Cull front // Pass1 CGPROGRAM #pragma surface surf NoLighting vertex:vert noshadow noambient sampler2D _MainTex; sampler2D _BumpMap; struct Input { float2 uv_MainTex; float2 uv_BumpMap; fixed4 color : Color; }; fixed4 _OutlineColor; float _Outline; void vert(inout appdata_full v) { v.vertex.xyz += v.normal.xyz * _Outline; } void surf(Input In, inout SurfaceOutput o) { } fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten) { return _OutlineColor; } ENDCG // Pass2 Cull back CGPROGRAM #pragma surface surf Lambert fixed4 _Color; sampler2D _MainTex; sampler2D _BumpMap; struct Input { float2 uv_MainTex; float2 uv_BumpMap; fixed4 color : Color; }; void surf(Input In, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, In.uv_MainTex); o.Albedo = c.rgb; o.Normal = UnpackNormal(tex2D(_BumpMap, In.uv_BumpMap)); o.Alpha = c.a; } ENDCG } FallBack "Diffuse" } | cs |
반응형
'Programming > Shader' 카테고리의 다른 글
HLSL 사용하기 (1) | 2016.10.05 |
---|---|
[HLSL] Outline (0) | 2016.09.06 |
HLSL 함수 (0) | 2016.09.05 |
PR - NPR 렌더링 (0) | 2016.04.09 |
[Unity Shader] Reflection Probe 반사처리 (0) | 2015.10.06 |
[Unity Shader] 실수 및 에러 정리 (0) | 2015.10.01 |
[Unity Shader] Blinn-Phong-Gloss (0) | 2015.09.30 |
[Unity Shader] Parts Color Shader (0) | 2015.09.24 |