ABOUT PORTFOLIO GAMES DEVLOG DOCS TOOLS CONTACT
HOME > DOCS > Shader / URP > UV 언래핑 없이 월드 좌표 기반으로 텍스처를 투영하는 트라이플래너(Triplanar) 지형 셰이더Triplanar Mapping Terrain Shader Using World-Space Projections
Shader / URP Intermediate Unity 2021.3+ / Unity 6 (URP)

UV 언래핑 없이 월드 좌표 기반으로 텍스처를 투영하는 트라이플래너(Triplanar) 지형 셰이더Triplanar Mapping Terrain Shader Using World-Space Projections

동적 지형이나 절벽, 동굴 메시에서 UV 왜곡과 늘어남을 줄이기 위해 월드 X, Y, Z 세 축에서 텍스처를 투영하고 노멀 가중치로 합성하는 셰이더.Projecting textures along the world X, Y, and Z axes and blending them by surface normal weights to prevent UV stretching on cliffs, caves, and procedural terrains.

#Shader #URP #Triplanar #Terrain #HLSL
핵심 개념급경사 절벽이나 복셀 지형 메시는 상단(Y축) 기준으로 펼친 단일 UV에서 측면 텍스처가 심하게 늘어납니다. 월드 좌표의 YZ 평면, XZ 평면, XY 평면에서 텍스처를 각각 샘플링하고, 표면 노멀의 절대값 $|N_x|, |N_y|, |N_z|$ 비율로 가중 평균을 구하면 텍스처 늘어남을 줄인 균일한 매핑을 구현할 수 있습니다.
Core ConceptSteep cliff faces and procedural voxel meshes suffer from severe texture stretching when mapped with top-down planar UVs. Sampling the texture independently across the world YZ, XZ, and XY planes and blending the results using the absolute surface normal components $|N_x|, |N_y|, |N_z|$ produces uniform texture density with minimal stretching.

1. 트라이플래너 텍스처 샘플링 HLSL1. Triplanar Texture Sampling in HLSL

TriplanarMapping.hlsl
float3 weights = abs(input.normalWS);
weights = pow(weights, _BlendSharpness);
weights /= (weights.x + weights.y + weights.z); // 가중치 정규화

// 각 축별 월드 투영 샘플링
half4 colX = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.positionWS.zy * _Tiling);
half4 colY = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.positionWS.xz * _Tiling);
half4 colZ = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.positionWS.xy * _Tiling);

half4 finalColor = colX * weights.x + colY * weights.y + colZ * weights.z;
TriplanarMapping.hlsl
float3 weights = abs(input.normalWS);
weights = pow(weights, _BlendSharpness);
weights /= (weights.x + weights.y + weights.z); // Normalize blend weights

// Sample texture projections along each world axis
half4 colX = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.positionWS.zy * _Tiling);
half4 colY = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.positionWS.xz * _Tiling);
half4 colZ = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.positionWS.xy * _Tiling);

half4 finalColor = colX * weights.x + colY * weights.y + colZ * weights.z;

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

  • 텍스처 샘플링 비용 3배 증가: 프래그먼트당 3회의 텍스처 조회가 발생하며 노멀맵까지 포함하면 6회로 늘어납니다. 원거리 지형에서는 단일 평면 매핑으로 전환하거나 꼭 필요한 절벽·지형 레이어에만 제한적으로 적용하는 것이 좋습니다.
  • 움직이는 오브젝트의 좌표계 선택: 월드 좌표(positionWS)를 기준으로 투영하면 오브젝트가 이동할 때 텍스처가 표면을 따라 미끄러지듯 흘러가므로, 이동·회전하는 프롭에는 오브젝트 로컬 좌표(positionOS)와 로컬 노멀(normalOS)을 사용해야 합니다.
  • 3x Texture Sampling Cost: Triplanar mapping performs three texture lookups per fragment (six when including normal maps). Restrict its use to steep terrain layers or fade to single-projection mapping at far LOD distances.
  • World Space vs. Object Space for Moving Props: Projecting with positionWS causes textures to swim across the surface if the mesh moves or rotates; use object-space coordinates (positionOS) and normals (normalOS) for dynamic objects.

트라이플래너 매핑은 절차적 생성 지형이나 급경사 암벽처럼 수동 UV 언래핑이 어렵거나 왜곡이 발생하는 환경에서 일관된 텍스처 밀도를 유지할 수 있는 기법입니다.

Triplanar mapping maintains uniform texel density across procedural geometry and steep rock formations where manual UV unwrapping is impractical.