Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- loop
- dfs
- 시작해요 언리얼 2022
- Unreal Engine 5
- 오류
- github
- Basic
- parameter
- 파이썬
- String
- Unity
- w3school
- Programming
- 재귀
- Class
- 프로그래밍
- 문제풀이
- Algorithm
- 백준
- Material
- guide
- Tutorial
- W3Schools
- 기초
- C#
- DP
- dynamic
- UE5
- c++
- python
Archives
- Today
- Total
행복한 개구리
Unity Shader 21.05.14. 하프벡터 빛효과 + 외곽선, 홀로그램 본문
Shader "Custom/Skeleton"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Thickness("Thickness", Float) = 0
_Color("Color", Color) = (1,1,1,1)
_TexColor("Texture Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 200
Cull Front
CGPROGRAM
#pragma surface surf _Skeleton vertex:vert noambient
float _Thickness;
float4 _Color;
void vert(inout appdata_full v)
{
v.vertex.xyz += v.vertex.xyz * _Thickness;
}
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
}
float4 Lighting_Skeleton(SurfaceOutput s, float3 lightDir, float atten)
{
return _Color;
}
ENDCG
Cull Back
CGPROGRAM
#pragma surface surf _Skeleton
sampler2D _MainTex;
float4 _TexColor;
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;
}
float4 Lighting_Skeleton(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
{
float3 hVec = normalize(lightDir + viewDir);
float spec = dot(hVec, s.Normal);
float4 final;
final.rgb = spec * s.Albedo + _TexColor;
final.a = s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
1. 잊지 말아야 할 것은 Culling순서를 정해주는 것이다. 그렇지 않으면 외곽선은 제대로 출력되지 않는다.
2. 커스텀라이트 사용시 메서드 이름은 반드시 'Lighting + pragma에 선언한 이름'이어야한다.
3. 하프벡터를 사용하려면 커스텀라이트 메서드의 매개변수에 viewDir이라는 시선벡터를 추가해주어야한다.
4. 커스텀라이트는 float4를 반환하기때문에 return으로 값을 반환해주자.
5. atten은 빛의 감쇠를 나타낸다.
atten이 빠지면 어떨까. 비교해보았다.
Albedo와 Emission처럼 빛의 영향을 받지 않는 것처럼 보인다.
Shader "Custom/Sword"
{
Properties
{
_SwordColor("Sword Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard alpha:fade
float4 _SwordColor;
struct Input
{
float2 uv_MainTex;
float3 viewDir;
};
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
float ndotv = dot(o.Normal, IN.viewDir);
o.Albedo = _SwordColor.rgb;
o.Alpha = pow(1-ndotv,1);
}
ENDCG
}
FallBack "Diffuse"
}
홀로그램, 스켈레톤, 외곽선의 색깔은 조절할 수 있다.
'Unity > 복습' 카테고리의 다른 글
Unity Shader 21.05.15. Diffuse Warping (0) | 2021.05.15 |
---|---|
Unity Shader 21.05.14. Skybox (0) | 2021.05.15 |
Unity Shader 21.05.13. 불 효과만들기 (0) | 2021.05.14 |
Unity 복습 21.05.11. PUN2 - 로비 구현2 (0) | 2021.05.12 |
Unity 복습 21.05.10. UGUI - DailyReward (0) | 2021.05.10 |