ABOUT PORTFOLIO GAMES DEVLOG DOCS TOOLS CONTACT
HOME > DOCS > Unity / C# > HD-2D 스타일 연출: 3D 배경 속 2D 픽셀 빌보드(Billboard)와 URP 피사계 심도(DoF)HD-2D Rendering Setup: 2D Pixel Billboards and URP Depth of Field in 3D Environments
Unity / C# Intermediate Unity 2022.3+ / Unity 6 (URP)

HD-2D 스타일 연출: 3D 배경 속 2D 픽셀 빌보드(Billboard)와 URP 피사계 심도(DoF)HD-2D Rendering Setup: 2D Pixel Billboards and URP Depth of Field in 3D Environments

3D 지형에 실시간 조명과 그림자를 받는 2D 픽셀 캐릭터를 배치하고 URP 피사계 심도 및 블룸 설정으로 디오라마 스타일 화면을 구성하는 렌더링 아키텍처.A rendering architecture for placing 2D pixel sprites with real-time lighting and shadows onto 3D terrain, combined with URP Depth of Field and Bloom for a diorama style.

#Unity #3D #2D #HD-2D #Billboard #DepthOfField #URP
핵심 개념HD-2D는 2D 픽셀 아트 스프라이트를 3D 엔진의 PBR 조명, 실시간 그림자, 피사계 심도(Depth of Field)가 적용된 3D 환경에 결합하는 하이브리드 렌더링 기법입니다. 2D 캐릭터가 3D 그림자를 드리우면서 카메라 방향에 맞춰 정렬되도록 제어하는 빌보드 구조가 핵심입니다.
Core ConceptHD-2D is a hybrid rendering technique that combines 2D pixel art sprites with a 3D environment featuring PBR lighting, real-time shadows, and Depth of Field. The core mechanism relies on a billboard setup that aligns 2D characters toward the camera while casting 3D shadows across the terrain.

1. Y축 고정 카메라 빌보드(Billboard) 컴포넌트1. Y-Axis Locked Camera Billboard Component

HD2DBillboard.cs
using UnityEngine;

public class HD2DBillboard : MonoBehaviour
{
    [SerializeField] private bool lockX = true; // 좌우 회전만 허용하고 눕지 않도록 X축 잠금
    [SerializeField] private bool lockZ = true;

    private Camera _mainCamera;

    private void Start()
    {
        _mainCamera = Camera.main;
    }

    private void LateUpdate()
    {
        if (_mainCamera == null) return;

        // 카메라 정면을 바라보도록 회전 정렬
        Vector3 forwardDirection = _mainCamera.transform.forward;

        if (lockX) forwardDirection.y = 0f; // 캐릭터가 하늘/땅으로 눕는 현상 방지
        forwardDirection.Normalize();

        if (forwardDirection.sqrMagnitude > 0.001f)
        {
            transform.rotation = Quaternion.LookRotation(forwardDirection, Vector3.up);
        }
    }
}
HD2DBillboard.cs
using UnityEngine;

public class HD2DBillboard : MonoBehaviour
{
    [SerializeField] private bool lockX = true; // Lock X-axis to allow horizontal rotation without tilting
    [SerializeField] private bool lockZ = true;

    private Camera _mainCamera;

    private void Start()
    {
        _mainCamera = Camera.main;
    }

    private void LateUpdate()
    {
        if (_mainCamera == null) return;

        // Align rotation to face the camera forward direction
        Vector3 forwardDirection = _mainCamera.transform.forward;

        if (lockX) forwardDirection.y = 0f; // Prevent the character from tilting toward the sky or ground
        forwardDirection.Normalize();

        if (forwardDirection.sqrMagnitude > 0.001f)
        {
            transform.rotation = Quaternion.LookRotation(forwardDirection, Vector3.up);
        }
    }
}

2. 2D 스프라이트의 3D 그림자 캐스팅(Shadow Casting) 세팅2. Configuring 3D Shadow Casting on 2D Sprites

  • Cast Shadows = Two Sided: 2D SpriteRenderer의 인스펙터 Debug 모드 또는 C# 스크립트에서 SpriteRenderer.shadowCastingMode = ShadowCastingMode.TwoSided로 활성화하면 평면 2D 캐릭터가 3D 지형 바닥에 양면 기준으로 3D 그림자를 생성합니다.
  • URP Lit 머티리얼 적용: 기본 언릿 스프라이트 머티리얼 대신 URP Lit 셰이더(또는 Alpha-test 지원 커스텀 PBR 셰이더)를 연결해야 3D 포인트 라이트 및 광원에 실시간으로 명암이 반영됩니다.
  • Cast Shadows = Two Sided: Enabling SpriteRenderer.shadowCastingMode = ShadowCastingMode.TwoSided via the Inspector Debug mode or C# script allows flat 2D sprites to cast two-sided 3D shadows onto the terrain.
  • Apply URP Lit Material: Replace the default unlit sprite material with a URP Lit shader (or a custom PBR shader supporting alpha testing) so that 3D point lights and light sources affect sprite shading in real time.

3. 디오라마 연출을 위한 URP Volume 포스트 프로세싱3. URP Volume Post-Processing for Diorama Styling

좌우로 밀어서 표 전체 내용을 확인하세요
볼륨 이펙트추천 세팅 파라미터시각적 효과
Depth of Field (Bokeh)Focus Distance: 10m, F-number: 1.4, Focal Length: 75mm플레이어 주변만 선명하고 상하단 원경이 부드럽게 흐려져 미니어처 디오라마 느낌 부여 (틸트시프트)
BloomThreshold: 0.9, Intensity: 1.2, Scatter: 0.7횃불, 발광 이펙트, 창문 채광 등이 도트 외곽선 주변으로 번지는 입체적인 조명 분위기 연출
Color AdjustmentsPost Exposure: +0.2, Contrast: 15, Saturation: 20명암 대비와 채도를 조정하여 3D 배경과 레트로 도트 색감의 톤을 정렬
Swipe horizontally to view the full table
Volume OverrideRecommended ParametersVisual Effect
Depth of Field (Bokeh)Focus Distance: 10m, F-number: 1.4, Focal Length: 75mmKeeps the area around the player sharp while softly blurring the foreground and background for a miniature tilt-shift look
BloomThreshold: 0.9, Intensity: 1.2, Scatter: 0.7Produces soft light diffusion around torches, emissive effects, and window light across pixel edges
Color AdjustmentsPost Exposure: +0.2, Contrast: 15, Saturation: 20Adjusts contrast and saturation to align the color tone between 3D environments and pixel sprites

4. 실무 적용 및 주의사항4. Practical Considerations

  • 텍스처 필터링 설정: 도트 그래픽의 외곽선이 흐려지지 않도록 스프라이트 에셋의 Filter Mode는 Point (no filter)로 설정하고 텍스처 압축(Compression)은 None으로 지정합니다.
  • 그림자 바이어스(Shadow Bias) 조정: 평면 스프라이트가 3D 조명을 받을 때 표면에 줄무늬 아티팩트(Shadow Acne)가 생기거나 그림자가 발바닥에서 떨어져 보일 수 있으므로, URP 에셋의 Depth Bias와 Normal Bias를 씬 스케일에 맞게 조정해야 합니다.
  • 알파 클리핑(Alpha Clipping) 활용: 반투명 블렌딩 머티리얼은 깊이 버퍼(Z-Buffer)에 기록되지 않아 3D 오브젝트와의 앞뒤 정렬이 어긋나거나 그림자가 정상적으로 생성되지 않을 수 있으므로 Alpha Clipping을 활성화한 셰이더를 사용하는 것이 안전합니다.
  • Texture Filtering Settings: Set the sprite asset Filter Mode to Point (no filter) and Compression to None to keep pixel edges crisp without blurring.
  • Shadow Bias Tuning: Flat sprites receiving 3D lighting can exhibit shadow acne or detached shadows at the feet, so adjust Depth Bias and Normal Bias in the URP Asset to match your scene scale.
  • Use Alpha Clipping: Transparent blended materials do not write to the depth buffer (Z-Buffer), which can cause sorting issues with 3D geometry or missing shadows; use a shader with Alpha Clipping enabled instead.

빌보드 회전 제어와 양면 그림자 설정, 그리고 URP 포스트 프로세싱 파라미터를 적절히 조합하면 2D 픽셀 스프라이트와 3D 입체 배경이 조화를 이루는 HD-2D 화면을 구성할 수 있습니다.

Combining billboard rotation constraints, two-sided shadow casting, and URP post-processing parameters lets you build a cohesive HD-2D scene where 2D pixel sprites integrate cleanly with 3D environments.