콘텐츠 개발 기법 - URP 환경에서 Bloom 및 Volume 포함한 화면 캡처

Published: Sep 6, 2023 by BeatChoi

화면 캡처 :: Screen Capture

일반적으로 URP환경에서 Bloom 등의 Volume 이펙트들이 함께 캡처되지 않는 현상이 일어납니다.
두가지 원인이 있는데 첫번째는 저장할 Texture 및 Texture2D의 크기가 작아 모든 텍스쳐를 저장할 수 없는 경우와
두번째는 Linear color space의 픽셀을 텍스쳐에 저장 할 수 없는 경우가 있습니다.
이번 포스팅에서는 URP 환경에서 해당 이펙트들을 함께 캡쳐하는 방법을 알아봅니다.

유니티3D 에디터에서

스크립트 작성

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using UnityEngine.UI;
using System.IO;
.
.
.
    public RawImage PhotoDownload;
.
.
.
    public void TakeScreenShot()
    {
        StartCoroutine(TakeScreenShotCo());
    }

    IEnumerator TakeScreenShotCo()
    {
        Directory.CreateDirectory(Application.persistentDataPath + "/Photos");

        RenderTexture renderTexture = new RenderTexture((int)Screen.width, (int)Screen.height, 24, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.sRGB);
        Texture2D texture = new Texture2D ((int)Screen.width, (int)Screen.height, TextureFormat.RGBAFloat, false, true);

        yield return new WaitForEndOfFrame();
        Camera.main.targetTexture = renderTexture;
        Camera.main.Render();
        RenderTexture.active = renderTexture;
        texture.ReadPixels (new Rect(0, 0, (int)Screen.width, (int)Screen.height), 0, 0);
        texture.Apply ();
        PhotoDownload.texture = texture;

        Camera.main.targetTexture = null;
        RenderTexture.active = null;
    }

    public void SavePhoto()
    {
        byte[] bytes;
        string fileExt;

        Texture2D texture = new Texture2D((int)Screen.width, (int)Screen.height, TextureFormat.RGBAFloat, false, true);
        texture = (Texture2D)PhotoDownload.mainTexture;

        Color[] pixels = texture.GetPixels();
        for (int p = 0; p < pixels.Length; p++)
        {
            pixels[p] = pixels[p].gamma;
        }
        texture.SetPixels(pixels);

        bytes = texture.EncodeToJPG();
        fileExt = ".jpg";

        Camera.main.targetTexture = null;
        RenderTexture.active = null;
        string filename = System.DateTime.Now.ToString(("yyyyMMddHHmmss")) + fileExt;
        File.WriteAllBytes(Application.persistentDataPath + "/Photos" + "/" + filename, bytes);
    }
  • RenderTexture 를 새로 선언하는 코드에 RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.sRGB 두개의 인자를 추가합니다.
  • Texture2D를 새로 선언하는 코드에 TextureFormat 인자를 TextureFormat.RGBAFloat으로 변경합니다. 하단 SavePhoto() 함수에도 동일하게 적용합니다.
  • 위 부분에서 텍스쳐 포맷을 변경하여 Volume이 추가된 텍스쳐를 저장할 수 있도록 합니다.
  • SavePhoto()함수 중간에
    1
    2
    3
    4
    5
    6
    
          Color[] pixels = texture.GetPixels();
          for (int p = 0; p < pixels.Length; p++)
          {
              pixels[p] = pixels[p].gamma;
          }
          texture.SetPixels(pixels);
    
  • 를 통해 각 픽셀을 수작업으로 gamma color space로 변경해 줍니다.

테스트


<01. 적용 전 캡처본>


<02. 적용 후 캡처본>

Latest Posts

콘텐츠 개발 기법 - URP 환경에서 Bloom 및 Volume 포함한 화면 캡처
콘텐츠 개발 기법 - URP 환경에서 Bloom 및 Volume 포함한 화면 캡처

화면 캡처 :: Screen Capture

일반적으로 URP환경에서 Bloom 등의 Volume 이펙트들이 함께 캡처되지 않는 현상이 일어납니다.
두가지 원인이 있는데 첫번째는 저장할 Texture 및 Texture2D의 크기가 작아 모든 텍스쳐를 저장할 수 없는 경우와
두번째는 Linear color space의 픽셀을 텍스쳐에 저장 할 수 없는 경우가 있습니다.
이번 포스팅에서는 URP 환경에서 해당 이펙트들을 함께 캡쳐하는 방법을 알아봅니다.

콘텐츠 개발 기법 - UI 안나오게 화면 캡처(Screen Capture without UI)
콘텐츠 개발 기법 - UI 안나오게 화면 캡처(Screen Capture without UI)

화면 캡처 :: Screen Capture

UI 없이 화면을 캡쳐하는 방법을 알아봅니다.
해당 방법을 통해 사진 앱에서 사진을 찍거나 게임 내에서 UI를 제거한 스크린샷을 구현할 수 있습니다.

유니티3D 에디터에서

스크립트 작성

LightshipAR SDK 활용하기 - LightshipAR VPS의 활용
LightshipAR SDK 활용하기 - LightshipAR VPS의 활용

LightshipAR SDK

이번 강좌에서는 Visual Positioning System (VPS) 기능을 활용하여 콘텐츠를 개발해 봅니다.
VPS는 GPS정보와 타겟 매핑 정보를 정합하여 해당 타겟을 인식하는 기능입니다.
따라서 객체나 환경의 변화 및 이동이 잦지 않은 타겟이 스캔 대상이 됩니다.
주로 동상, 건물 입구, 가로등 등 위치의 변경이 없는 타겟들이 좋은 타겟입니다.

해당 타겟들을 인식시키고 주변에 가상의 오브젝트들을 배치하고 해당 위치를 저장하는 방법을 알아봅니다.

공간 매핑

Niantic Wayfarer

공간을 인식시키기 위해서 먼저 공간을 매핑해야 합니다.
이 과정은 IOS 어플리케이션으로 진행을 할 수 있는데 아래 링크에서

  1. Testflight
  2. Wayfarer

어플리케이션을 다운로드 및 설치합니다.

링크 : https://testflight.apple.com/join/VXu1F2jf