[자체 엔진] Billboard
1-1. Billboard란?
항상 카메라의 방향으로 고정되어있는 Quad를 의미합니다.
1-2. 구현 방법
VS(Text.hlsl)에서 ViewMatrix의 카메라 Right/Up (cmaera basis) 를 추출해서
Quad가 월드 Space에서 카메라를 바라보도록 재 위치 시킨다.
2. 실제 구현 (Vertex Shader)
2.1 입력 상수버퍼
cbuffer ModelBuffer : register(b0)
{
row_major float4x4 WorldMatrix;
}
cbuffer ViewProjBuffer : register(b1)
{
row_major float4x4 ViewMatrix;
row_major float4x4 ProjectionMatrix;
}
// 이건 Text Atlas로 사용하기 위한 용
cbuffer TextCharacterInfo : register(b5)
{
float4 AtlasSpriteSize; //x = width, y = height, z = 1 / width, w = 1 / height
float4 CharacterInfo[256];
}
2.2 중심 추출
Vertex Shader에서 World Matrix의 translation 부분만 읽어서 billboard의 중김점으로 사용한다.centerWS = mul(float4(0,0,0,1), WorldMatrix).xyz
float4(0,0,0,1)을 곱하면 Translation 부분만 추출할 수 있다.
2.3 카메라 축 추출
ViewMatrix에서 카메라 basis를 뽑아서 사용한다.
camRight = normalize(float3(ViewMatrix._11, ViewMatrix._21, ViewMatrix._31))
camUp = normalize(float3(ViewMatrix._12, ViewMatrix._22, ViewMatrix._32))
2.4 정점의 월드 위치 재구성 (billboard 본체)
2.3 에서 만든 카메라 basis를 이용해서 카메라를 바라보도록 정렬을 하면 된다.
float3 worldPos = centerWS + camRight * (input.position.x * ScaleXY.x) + camUp * (input.position.y * ScaleXY.y);
일반 Mesh처럼 input.position을 WorldMatrix로 회전/스케일하는 게 아니라,
카메라 Right/Up 축에 정점 오프셋을 직접 투영해서 월드 위치를 만들기 때문에
결과 쿼드 면이 항상 카메라를 향한다.
이 이후에는 다른 Mesh와 같이 View * Projection을 곱해주면 된다.
'ComputerGraphics > 자체엔진' 카테고리의 다른 글
| [자체 엔진] FXAA (0) | 2026.03.09 |
|---|---|
| [자체 엔진] Batch Line Rendering (0) | 2026.03.09 |
| [자체 엔진] Features (0) | 2026.03.09 |
| [자체 엔진] Bgario (0) | 2026.03.09 |
| [자체 엔진] DirectX 3D 게임 (Jungle Smash) (0) | 2025.12.12 |