ãUnityãã«ã¡ã©ï¼ã¤ã§UI解å度ãç¶æãã3D解å度ã ããä¸ããæ¹æ³
æããã¢ãã¤ã«ç«¯æ«ã®è§£å度ã¯çæ°ã®æ²æ±°ã¨ããè¨ããããã®å°ããªé¢ç©ã«ãã«HDã¨ãã®ãã£ã¹ãã¬ã¤ãç©ãã§ãã¾ãã
æ®ã£ãåçã綺éºã«è¦ããªãè¯ãã®ããããã¾ãããã1ãã¬ã¼ã 16msã¨ã33msã§æç»ããªãã¨ãããªãã²ã¼ã ã§ã¯ããªãè¾ããã®ãããã¾ãã
æ£ç´ãAndroidã®è§£å度åæ¦ããªããã°ããã£ã¨ã·ã§ã¼ãã¼ãªãããªã²ã¼ã ãä¸ã®ä¸ã«æº¢ãã¦ããã¨æãããã§ãã
ã¨ã¯ããä¸ã®æµãã§ãã®ã§ãæã
ã¨ã³ã¸ãã¢ã¯å·¥å¤«ãåããã¦ãããªãããªè¦ãç®ãåºããããæ¥ã
éé²ããããã§ããã¾ãã
ä¸è¨ãè¸ã¾ãã¦è¨ããããã¨ã¯ã
ã²ã¼ã ã®è§£å度è½ã¨ãã¦ãè¯ãããï¼
ã¨ãããã¨ã§ãã
ããããUI解å度ã720pã¾ã§è½ã¨ãã¦ãã¾ãã¨é端ã«ã¦ã¼ã¶ã¼ã«ãã¬ã¦ãã¾ãã¾ãã
UIã¯çµæ§è§£å度ã®å£åãç®ç«ã¤ãã§ãããã
ãããã3D空éå´ã®è§£å度ãè½ã¨ãã¦ãã»ã¨ãã©ç®ç«ããããã£ã«ã¬ã¼ãã稼ãã¦ç¾å³ããã®ã§ãã
ç§ã®å°æ¬ããã¨ã³ã¸ãã¢ã®ï¼äººãUnityã®å®åãããUnity 2017 Tokyoã§åããã¨ããã£ããã£ã¦ãã¾ãã
ãUnite 2017 Tokyoãã¹ãã¼ããã©ã³ã§ã©ãã¾ã§ã§ããï¼3Dã²ã¼ã ãããããåãããã¯ããã¯è¬åº§
3Då´ã®è§£å度ã ããä¸ãã
ãã¦ããã£ã¨æ¬é¡ã§ãã
ãããããã¨ã¯ããUI解å度ã¯é«ããã3D解å度ã¯ä½ããã¬ã³ããªã³ã°ã§ãã
ç°¡åã«è¨ãã¨3Dæç»ãèªåã§ç¨æããRenderTextureã«æç»ãã¦ã3Dæç»ãçµãã£ããBack Bufferã«Blitããã°è¯ããã¨ã«ãªãã¾ãã
Googleå
çã«èãã¦ã¿ãã¨ã以ä¸ã®ãããªè¨äºãããããã¾ããã
wordpress.notargs.com
ãã®è¨äºã®ä¸ã§ã¯ãBack Bufferã«Blitããç¨ã®ã«ã¡ã©ãç¨æãã¦ããã®ã«ã¡ã©ã«CommandBufferãAddãããã¨ã§RenderTextureãBackBufferã«æ¸ãè¾¼ãã§ãã¾ãã
ããã¯ãåä¸ã«ã¡ã©ã§ã®CommandBufferã§ã¯AfterImageEffects, AfterEveryThingã§ã®SetRenderTargetã§Back Bufferãæå®åºæ¥ãªãããã ã¨èªèãã¦ãã¾ãããäºå®ç§ããã®è¨äºãåèã«ãããã試ããã®ã§ã§ããæå®åºæ¥ãã以åã®è¨äºã§ã¯ãã®æ¹å¼ã§å®è£
ãã¦ãã¾ãã
appleorbit.hatenablog.com
ãããããããã§ãï¼
æ¬å½ã«å¶ç¶ã§ã¯ããã®ã§ããã以ä¸ã®è¨äºãã¿ã¤ãã¾ããã
Unity 5: AfterImageEffects and AfterEverything Traps – Updated My Journal.
å ¨CameraEventå ±éã§ãSetRenderTarget( -1 )ã¨æå®ããã¨Back Bufferãã»ãããããï¼RenderTargetIdentifer( int nameID )ã§ãããªã£ã¦ããï¼ï¼
æ¬å½ã«ãã®ããã°ã®èè
æ§ã«ã¯æè¬ã®å¿µããããã¾ããã
ã¨ããããã§ãæ¸ãã¦ã¿ã¾ããã
以ä¸ã®ã³ã¼ãã§ã3D解å度ã ãã1ã¤ã®ã«ã¡ã©ã§ä¸ãããã¨ãã§ãã¾ãã
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; /// <summary> /// 解å度ãå¤æ´ããã³ã³ãã¼ãã³ã /// </summary> [RequireComponent(typeof(Camera))] public class ResolutionConverter : MonoBehaviour { /// <summary> /// 解å度 /// </summary> public enum Resolution { None, HD, FULLHD } /// <summary> /// 解å度è¨å® /// </summary> [SerializeField] private Resolution m_Resolution = Resolution.None; /// <summary> /// ã¿ã¼ã²ããã«ã¡ã© /// </summary> private Camera m_Camera; /// <summary> /// ãã¬ã¼ã ãããã¡ /// </summary> private RenderTexture m_FrameBuffer; /// <summary> /// ã³ãã³ããããã¡ /// </summary> private CommandBuffer m_CommandBuffer; /// <summary> /// åæå /// </summary> private void Awake() { m_Camera = GetComponent<Camera> (); Apply (m_Resolution); } /// <summary> /// é©ç¨ãã /// </summary> public void Apply(Resolution resolution) { m_Resolution = resolution; if (resolution == Resolution.None) { return; } var size = GetResolutionSize (resolution); size = FitScreenAspect (Screen.width, Screen.height, size.x, size.y); UpdateFrameBuffer (size.x, size.y, 24); UpdateCameraTarget (); AddCommand (); } /// <summary> /// ãã¬ã¼ã ãããã¡ã®æ´æ° /// </summary> private void UpdateFrameBuffer(int width, int height, int depth, RenderTextureFormat format = RenderTextureFormat.Default) { if (m_FrameBuffer != null) { m_FrameBuffer.Release (); Destroy (m_FrameBuffer); } m_FrameBuffer = new RenderTexture (width, height, depth, format); m_FrameBuffer.useMipMap = false; m_FrameBuffer.Create (); } /// <summary> /// ã«ã¡ã©ã®æç»å ãæ´æ° /// </summary> private void UpdateCameraTarget() { if (m_FrameBuffer != null) { m_Camera.SetTargetBuffers (m_FrameBuffer.colorBuffer, m_FrameBuffer.depthBuffer); } else { m_Camera.SetTargetBuffers (Display.main.colorBuffer, Display.main.depthBuffer); } } /// <summary> /// 解å度ã®å®ãµã¤ãºãåå¾ /// </summary> private Vector2Int GetResolutionSize(Resolution resolution) { bool isPortrait = Screen.height > Screen.width; switch(resolution){ case Resolution.HD: if (isPortrait) { return new Vector2Int (720, 1280); } return new Vector2Int (1280, 720); case Resolution.FULLHD: if (isPortrait) { return new Vector2Int (1080, 1920); } return new Vector2Int (1920, 1080); } return new Vector2Int (Screen.width, Screen.height); } /// <summary> /// 解å度ã®è¨ç® /// </summary> private static Vector2Int FitScreenAspect(int width, int height, int maxWidth, int maxHeight) { // 解å度以ä¸ãªãä½ãããªã if (width <= maxWidth && height <= maxHeight) { return new Vector2Int (width, height); } if (width > height) { float aspect = height / (float)width; int w = Mathf.Min (width, maxWidth); int h = Mathf.RoundToInt (w * aspect); return new Vector2Int (w, h); } { float aspect = width / (float)height; int h = Mathf.Min (height, maxHeight); int w = Mathf.RoundToInt (height * aspect); return new Vector2Int (w, h); } } /// <summary> /// ã³ãã³ãã追å ãã /// </summary> private void AddCommand() { RemoveCommand (); // ã«ã©ã¼ãããã¡ãããã¯ãããã¡(ç»é¢)ã«æãããã³ãã³ã { m_CommandBuffer = new CommandBuffer (); m_CommandBuffer.name = "blit to Back buffer"; m_CommandBuffer.SetRenderTarget (-1); m_CommandBuffer.Blit (m_FrameBuffer, BuiltinRenderTextureType.CurrentActive); m_Camera.AddCommandBuffer (CameraEvent.AfterEverything, m_CommandBuffer); } } /// <summary> /// ã³ãã³ããç ´æ£ãã /// </summary> private void RemoveCommand() { if (m_CommandBuffer == null) { return; } if (m_Camera == null) { return; } m_Camera.RemoveCommandBuffer (CameraEvent.AfterEverything, m_CommandBuffer); m_CommandBuffer = null; } }
å人çã«æè¿æããã³ã·ã§ã³ã®ä¸ãã£ãå 容ã§ããã