ABOUT PORTFOLIO GAMES DEVLOG DOCS TOOLS CONTACT
HOME > DOCS > Shader / URP > 뷰 벡터와 노멀 내적을 활용한 프레넬(Fresnel) 림라이트 HLSL 셰이더Fresnel Rim Light HLSL Shader Using View and Normal Dot Product
Shader / URP Beginner Unity 2021.3+ / Unity 6 (URP)

뷰 벡터와 노멀 내적을 활용한 프레넬(Fresnel) 림라이트 HLSL 셰이더Fresnel Rim Light HLSL Shader Using View and Normal Dot Product

시선 방향(ViewDir)과 표면 노멀(Normal)의 각도 차이를 계산해 캐릭터 외곽선을 강조하는 경량 프레넬 림라이트 구현.A lightweight Fresnel rim lighting implementation that highlights character silhouettes by computing the angle between view direction and surface normal.

#Shader #URP #HLSL #Fresnel #Lighting
핵심 개념프레넬 림라이트는 카메라 시선 벡터($V$)와 표면 법선 벡터($N$)의 내적값($V \cdot N$)을 이용합니다. 시선과 노멀이 수직에 가까울수록(표면 외곽선일수록) 내적값이 0에 수렴하므로, 1.0 - saturate(dot(V, N))을 취하고 거듭제곱(pow)을 적용하면 외곽 테두리 조명을 조절할 수 있습니다.
Core ConceptFresnel rim lighting relies on the dot product ($V \cdot N$) between the camera view vector ($V$) and the surface normal vector ($N$). As the surface normal becomes perpendicular to the view direction near the silhouette edge, the dot product approaches 0; evaluating 1.0 - saturate(dot(V, N)) and raising it to a power (pow) controls the rim width and falloff.

1. 프레넬 림라이트 서브패스 구현1. Fresnel Rim Light Fragment Implementation

RimLightFresnel.hlsl
// 프래그먼트 셰이더 내부 림라이트 연산 로직
float3 viewDirWS = normalize(_WorldSpaceCameraPos - input.positionWS);
float3 normalWS = normalize(input.normalWS);

// 1. 프레넬 인자 계산
float NdotV = saturate(dot(normalWS, viewDirWS));
float rim = 1.0 - NdotV;
rim = pow(rim, _RimPower); // 거듭제곱으로 림의 폭과 감쇠 조절

// 2. 최종 색상 합성
half3 rimColor = _RimColor.rgb * rim * _RimIntensity;
half3 finalColor = baseColor.rgb + rimColor;
RimLightFresnel.hlsl
// Rim light calculation inside the fragment shader
float3 viewDirWS = normalize(_WorldSpaceCameraPos - input.positionWS);
float3 normalWS = normalize(input.normalWS);

// 1. Compute Fresnel factor
float NdotV = saturate(dot(normalWS, viewDirWS));
float rim = 1.0 - NdotV;
rim = pow(rim, _RimPower); // Control rim width and falloff with exponent

// 2. Composite final color
half3 rimColor = _RimColor.rgb * rim * _RimIntensity;
half3 finalColor = baseColor.rgb + rimColor;

2. 실무 적용 및 주의사항2. Practical Considerations and Caveats

  • 주 광원 방향 마스킹: 모든 외곽선에 균일하게 림라이트가 들어가면 인위적으로 보일 수 있으므로, saturate(dot(normalWS, mainLight.direction))을 곱해 빛을 받는 방향의 외곽선에만 림라이트가 맺히도록 제한하는 것이 자연스럽습니다.
  • 플랫 셰이딩 메시 주의: 로우폴리(Low-Poly) 플랫 노멀 메시에서는 폴리곤 면 단위로 법선이 일정해 프레넬 그라데이션이 끊어져 보이므로 스무스 노멀(Smooth Normal)이 적용된 캐릭터 메시에 적합합니다.
  • Masking by Main Light Direction: Applying rim lighting uniformly around the entire silhouette can look artificial; multiplying the rim factor by saturate(dot(normalWS, mainLight.direction)) restricts the highlight to the light-facing side.
  • Flat-Shaded Mesh Limitation: On low-poly meshes with flat face normals, the normal remains constant across each triangle, causing discontinuous Fresnel bands; smooth vertex normals are recommended.

시선 벡터와 법선 벡터의 내적 기반 프레넬 연산은 적은 GPU 비용으로 어두운 배경에서 캐릭터 실루엣을 분리하고 강조할 때 유용합니다.

Dot-product Fresnel rim lighting provides a low-cost way to separate character silhouettes from dark backgrounds in real-time shaders.

참고자료 & 관련 링크