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
- Unity
- UE5
- guide
- DP
- 백준
- String
- github
- loop
- python
- 기초
- parameter
- 오류
- Unreal Engine 5
- 재귀
- Algorithm
- 파이썬
- Class
- C#
- c++
- W3Schools
- Programming
- dfs
- w3school
- Basic
- dynamic
- 프로그래밍
- Tutorial
- 문제풀이
- Material
- 시작해요 언리얼 2022
Archives
- Today
- Total
행복한 개구리
Unity Shader 21.05.15. Diffuse Warping 본문
Shader "Custom/Warp"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RampTex("RampTexture", 2D) = "white" {}
_BumpTex("BumpTexture", 2D) = "bump" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf _Warp noambient
sampler2D _MainTex;
sampler2D _RampTex;
sampler2D _BumpTex;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
o.Normal = UnpackNormal(tex2D(_BumpTex, IN.uv_BumpTex));
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 Lighting_Warp(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
{
float ndotl = saturate(dot(s.Normal, lightDir))*0.5 + 0.5;
float4 ramp = tex2D(_RampTex, float2(ndotl, 0.5));
float4 final;
final.rgb = ramp.rgb * s.Albedo;
final.a = s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
아직 반사광은 표현되지 않은 모습이다. 빛효과는 하프램버트를 이용했다.
여기서 halfVector를 사용하여 spec을 구하고 이를 ramp텍스쳐의 v좌표에 대입시킨다면 어떨까.
Shader "Custom/Warp"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_RampTex("RampTexture", 2D) = "white" {}
_BumpTex("BumpTexture", 2D) = "bump" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf _Warp noambient
sampler2D _MainTex;
sampler2D _RampTex;
sampler2D _BumpTex;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
o.Normal = UnpackNormal(tex2D(_BumpTex, IN.uv_BumpTex));
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 Lighting_Warp(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten)
{
float ndotl = saturate(dot(s.Normal, lightDir)) * 0.5 + 0.5;
float3 hVec = normalize(lightDir + viewDir);
float spec = dot(hVec, s.Normal);
float4 ramp = tex2D(_RampTex, float2(ndotl, spec));
float4 final;
final.rgb = ramp.rgb * s.Albedo;
final.a = s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
이렇게 반사광이 적절하게 생긴다.
'Unity > 복습' 카테고리의 다른 글
Unity 복습 21.05.25~26. Unity MLAgent 설치/튜토리얼 (0) | 2021.05.27 |
---|---|
Unity ML 21.05.17. 복습 - ML (0) | 2021.05.18 |
Unity Shader 21.05.14. Skybox (0) | 2021.05.15 |
Unity Shader 21.05.14. 하프벡터 빛효과 + 외곽선, 홀로그램 (0) | 2021.05.14 |
Unity Shader 21.05.13. 불 효과만들기 (0) | 2021.05.14 |