ã¯ããã«
ãããããï¼@korinVRï¼ã VRChat ã§è¡ããã以ä¸ã®ãããªã¤ãã³ããä¼ç»ãã¦ããã¾ããã
8/2ï¼æ¥ï¼13:00ï½15:00ã«VRChatã§å²ãä¼ãããã¾ããä»åã®ã¹ãã·ã£ã«ã²ã¹ãã¯ãå¹ã¿Tipsã https://t.co/mZ2BmIxFST ã®å¹ãã @hecomi ã§ãï¼ãXRãUnityã®è©±é¡ã§ããããéè«ãããæ¹ã©ãªãã§ã大æè¿ã§ããå½æ¥ ID: korinVR ã«ãã¬ã³ãç³è«ã»joinãã¦ãã ããã #å¹ãããå²ãä¼ pic.twitter.com/9FZJdljx5e
— ããã / korinVR (@korinVR) 2020å¹´7æ27æ¥
以åç°¡å㪠Avatar ãä½ã£ã¦ã¿ãã ã㧠VRChat ã§ã¯ãã¾ãæ´»åã§ãã¦ããªãã£ãã®ã§ãããä»åã®ã¤ãã³ãç¨ã«ãªã«ãã¯ã¼ã«ããä½ããããªã¨æããuRaymarching ã使ã£ãã¯ã¼ã«ãã®ä½æã«åãçµãã§ã¿ã¾ããã幸ããç¹ã« uRaymarching ã®æ´æ°ã¯ããã«ãã®ã¾ã¾åºåããã·ã§ã¼ãã VRChat ã§ä½¿ããã¨ãåºæ¥ã¾ãããæ¬è¨äºã¯ä½ã£ã¦ã¿ããã¢ã®å 容ã«ã¤ãã¦ç´¹ä»ãããã¨æãã¾ãã
ãã¢
ãã¥ã¼ãã ãã§åºæ¥ãã¯ã¼ã«ããä½ã£ã¦ã¿ã¾ããã
VRChat ã§ãã¥ã¼ãããªã´ã³ã ã使ã£ã¦åãã¦ã®ã¯ã¼ã«ãä½ã£ã¦ã¿ã #MadeWithUdon #VRChat pic.twitter.com/7sx8fseYX8
— å¹ (@hecomi) 2020å¹´7æ27æ¥
ãã®ååé¨ã®ã¡ã¿ãã¼ã«ã®ç´¹ä»ããã¾ãã
uRaymarching ã«ã¤ãã¦
è·é¢é¢æ°ãè¨è¿°ããã ãã§ä»ã®ããªã´ã³ã®ãªãã¸ã§ã¯ããã©ã¤ãã£ã³ã°ã¨æ´åã®åããã¬ã¤ãã¼ãã³ã°ã«ãããªãã¸ã§ã¯ããåºããã¨ã®ã§ãã Unity ã®ã¢ã»ããã§ããHDRP ã¯æªã ã§ãããForward / Deferred / URP ã«å¯¾å¿ãã¦ãã¦ãVR ã«ãå¡ã対å¿ãã¦ãã¾ããã·ã§ã¼ãã ãã§å®çµããã®ã§ VRChat ã§ããã®ã¾ã¾ä½¿ãã¾ãï¼ãã ãã¬ã¤ãã¼ãã³ã°ã¯å¾¡åç¥ã®éãéãã®ã§ç¨æ³ã»å®¹éã«ã¯æ³¨æãå¿ è¦ã§ãï¼ã
é VR ç解説
ãã¢ã®å 容ã¯ã以ä¸ã® GitHub ã«ããã¦ãã uRaymarching ã®ãã¢ã®ç§»æ¤ã«ãªãã¾ãã
ã¾ãã¯ãã¡ãã® Examples ã®è§£èª¬ããè¦ã¦ããã¾ãããã
è¨å®ã¨è·é¢é¢æ°
uRaymarching ã® Conditions > World Space ã«ãã§ãã¯ãå ¥ãã¦ãè·é¢é¢æ°ã«ã¯ã¼ã«ã座æ¨ãå ¥ã£ã¦ããããã«ãã¾ãã
ãã®ä¸ã§æ¬¡ã®ãããªè·é¢é¢æ°ãè¨è¿°ãã¾ãï¼
float4x4 _Cube; float4x4 _Sphere; float4x4 _Torus; float4x4 _Plane; float _Smooth; inline float DistanceFunction(float3 wpos) { float4 cPos = mul(_Cube, float4(wpos, 1.0)); float4 sPos = mul(_Sphere, float4(wpos, 1.0)); float4 tPos = mul(_Torus, float4(wpos, 1.0)); float4 pPos = mul(_Plane, float4(wpos, 1.0)); float s = Sphere(sPos, 0.5); float c = Box(cPos, 0.5); float t = Torus(tPos, float2(0.5, 0.2)); float p = Plane(pPos, float3(0, 1, 0)); float sc = SmoothMin(s, c, _Smooth); float tp = SmoothMin(t, p, _Smooth); return SmoothMin(sc, tp, _Smooth); }
å¹¾ã¤ã uRaymarching ä»å±ã®é¢æ°ã使ã£ã¦ãã¾ã£ã¦ãã¦èªã¿ã¥ããããããã¾ããã...ãåããªããã£ãã®è·é¢é¢æ°ï¼Sphere
ã Box
ãªã©ï¼ã SmoothMin
ï¼æ»ããã«çµåï¼ã§åæãã¦ãã¾ãããªãã¸ã§ã¯ãããããã®ãã©ã³ã¹ãã©ã¼ã ã®éè¡åã float4x4
㧠C# å´ããä¸ãã¦ãã¾ããã¤ã¾ããDistanceFunction()
ã«ã¯ã¯ã¼ã«ãåº§æ¨ wpos
ãå
¥ã£ã¦ãã¦ããã®ã§ãããããã«ãã®éè¡åããããã¨åããªã´ã³ã®ãã¼ã«ã«åº§æ¨ã¸ã¨å¤æããããã®ãã¼ã«ã«åº§æ¨ãè·é¢é¢æ°ã«ããããã¨ã§ C# å´ããä¸ããä½ç½®ã§ç§»åã»å転å¯è½ãªã¬ã¤ãã¼ãã³ã°ã®ãªãã¸ã§ã¯ããè¨è¿°ã§ãã¾ãã
ãã©ã³ã¹ãã©ã¼ã ã®åã渡ã
ãã® C# å´ã®ã¹ã¯ãªããã¯ä»¥ä¸ã®ããã«ãªãã¾ãï¼
using UnityEngine; [ExecuteInEditMode] public class TransformProvider : MonoBehaviour { [System.Serializable] public class NameTransformPair { public string name; public Transform transform; } [SerializeField] NameTransformPair[] pairs; void Update() { var renderer = GetComponent<Renderer>(); if (!renderer) return; var material = renderer.sharedMaterial; if (!material) return; foreach (var pair in pairs) { var pos = pair.transform.position; var rot = pair.transform.rotation; var mat = Matrix4x4.TRS(pos, rot, Vector3.one); var invMat = Matrix4x4.Inverse(mat); material.SetMatrix(pair.name, invMat); } } }
ã·ã§ã¼ãå´ã«æ¸¡ããã¼ã¯ã¼ãåã¨ã渡ã座æ¨ã® Transform
ããã¢ã«ãã¦ç»é²ãããã® Transform
ãã Matrix4x4
ãåãåºãã¦éè¡åã«ãããã®ã Material.SetMatrix()
ããå½¢ã«ãªãã¾ããã¤ã³ã¹ãã¯ã¿ã§ã¯æ¬¡ã®ããã«ç»é²ãã¾ãã
ããã§æºåã¯åºæ¥ã¾ããããã®ä¸ã§ã¬ã³ããªã³ã°ããæ¹æ³ã¯ 2 éãããã¾ãã
ã¬ã³ããªã³ã°â ï¼åä¸ã®ãã¥ã¼ãã§æç»
ãã¥ã¼ãããªã´ã³ã 1 ã¤ç¨æããããã«ä¸è¨ã·ã§ã¼ãããçæãããããªã¢ã«ãæå®ãã¾ããCube ã Sphere ãªã©ã¯ Renderer
ã³ã³ãã¼ãã³ããæããªãåãªã Transform
ãæä¾ããã ãã®ãã±ã¼ã¿ã¨ãã¦æ±ãã¾ããããã§æ¬¡ã®ããã«ãªãã¾ãã
ã¬ã³ããªã³ã°â¡ï¼è¤æ°ã®ãã¥ã¼ãã§æç»
ãã 1 ã¤ã®æ¹æ³ã¯ãå Cube ã Sphere ã²ã¼ã ãªãã¸ã§ã¯ãã Transform
ã®æä¾ã®ãã±ã¼ã¿ã¨ãã¦ä½¿ãã¨åæã«ãRenderer
ã§æç»ãããã«è¡ãæ¹æ³ã§ããåãã¥ã¼ãããªã´ã³ã¯ãªã¼ãã¼ã©ãããã¾ãããSmoothMin
ã«ãã£ã¦ãªã¼ãã¼ã©ããããããã«è§£æ±ºããã¾ãã
ã¡ãªããã»ãã¡ãªãã
â¡ã®æ¹æ³ã¯æç»ã¨ãªã¢ãéå®ãããã®ã§ãå°ãããã®ããããããããããªå ´åã¯ééã®ãã¯ã»ã«ã®ã¬ã³ããªã³ã°ãèµ°ããªãã®ã§è»½ããªãã¾ãããã ããããããªã¼ãã¼ã©ãããã¦ãã¤ã«ã¡ã©ãè¿ãå ´åã¯éè¤ãã¦ãã¯ã»ã«ã·ã§ã¼ããèµ·åãããã®ã§éããªãã¾ãã
â ã®æ¹æ³ã¯ããããã®ãã¯ã»ã«ã·ã§ã¼ããèµ·åããã¦ãã¾ãã¾ããå®å®ãã¦ã·ã³ãã«ã§ããã¾ããã©ã¤ãã£ã³ã°å¨ãã§ã©ã¤ãããã¼ãã®å½±é¿ãªã©ãèæ ®ãããå ´åãæ´åãåãã¾ããâ ã®æ¹æ³ã ã¨åããªã´ã³åä½ã§ã©ã¤ãããã¼ãã®ãµã³ããªã³ã°ãè¡ããã¦ãã¾ãã®ã§ãªã¼ãã¼ã©ããããæ¥ç¶é¨ã§ã©ã¤ãã£ã³ã°ã®ä¸æ´åãèµ·ãããç ´ç¶»ãã¦ãã¾ãã¾ãã
è²ä»ã
è²ã¤ãã§ããããããªæã㧠PostEffect
ã§å度ã¬ã¤ãã¼ãã³ã°ãèµ°ããããã®çµæã®è·é¢ããè¿ããã°ãã®è²ãæ¿ããªãããã«ããã°ãã¬ã¤ã«æ··ããåããã¬ã³ããå¯è½ã§ãã
float4 _CubeColor; float4 _SphereColor; float4 _TorusColor; float4 _PlaneColor; inline void PostEffect(RaymarchInfo ray, inout PostEffectOutput o) { float3 wpos = ray.endPos; float4 cPos = mul(_Cube, float4(wpos, 1.0)); float4 sPos = mul(_Sphere, float4(wpos, 1.0)); float4 tPos = mul(_Torus, float4(wpos, 1.0)); float4 pPos = mul(_Plane, float4(wpos, 1.0)); float s = Sphere(sPos, 0.5); float c = Box(cPos, 0.5); float t = Torus(tPos, float2(0.5, 0.2)); float p = Plane(pPos, float3(0, 1, 0)); float4 a = normalize(float4(1.0 / s, 1.0 / c, 1.0 / t, 1.0 / p)); o.Albedo = a.x * _SphereColor + a.y * _CubeColor + a.z * _TorusColor + a.w * _PlaneColor; }
VRChat ã¸ã®ç§»æ¤
uRaymarching ã§çæãããªãã¸ã§ã¯ãã¯åºæ¬çã«ã¯ãã®ã¾ã¾ publish ãã¦ããããã° VR å ã§ãåé¡ãªãè¦ããã¨æãã¾ãããã ä»åã¯ãã©ã³ã¹ãã©ã¼ã ã®åã渡ãã®ã¨ããã§è¦ãããã«ã¹ã¯ãªãããå¿ è¦ã§ãããã®ã¹ã¯ãªããã®é¨åã«ã¯ Udon ã使ããã¨ã«ãã¾ããU# ã使ã£ãã»ããç°¡åã¨ã¯æãã¾ãããã¾ãã¯åãã¦ãªã®ã§ Udon Graph ã§å®è£ ãã¦ã¿ã¾ãããå ¨ä½åã¯ãããªæãã§ãï¼
ã¬ã³ãã©ã®ã«ã¼ã
renderers
ã¨ãã Renderer[]
㪠public ãªå¤æ°ãç¨æãã¦ããã¾ããããã LateUpdate()
èµ·ç¹ã§ for ã«ã¼ãã§åãã¦ä¸ã¤ä¸ã¤å¦çãã¦ããã¾ãã
ãã©ã³ã¹ãã©ã¼ã ã®åã渡ã
åå³å½¢ã®ãã©ã³ã¹ãã©ã¼ã ã public ãªå¤æ°ã¨ãã¦ç¨æãã¦ãããããããå
ç¨ã¨åæ§ã«è¡åãä½æãéè¡åã«ãã¦ãããªã¢ã«ã« SetMatrix()
ãã¾ããé
åã«è©°ãããããã°ããå°ãã·ã³ãã«ã«æ¸ããã¨ã¯æãã®ã§ãããã¾ãéãããã»ã©å¤ããªãã®ã§æç´ã« 4 ã¤ä¸¦ã¹ã¦ã¿ã¾ããã
æã¦ãããã«ãã
é©å½ãªã³ã©ã¤ããåãã©ã³ã¹ãã©ã¼ã ã²ã¼ã ãªãã¸ã§ã¯ãã«åãä»ãããã®ä¸ã§ VRC_Pickup
ã³ã³ãã¼ãã³ããã¤ãã¦ããã¾ãããUdonBehavior
㧠Synchronize Position
ã¤ãã¦ããã°ããã§åæããããã§ãããã...ãã¤ãã³ãåã«ã¯è©¦ãã¦ããããã§ãã
ã¬ã³ããªã³ã°
ãã¤ã¯ããã©ã¤ãããã¼ãã«ããã©ã¤ãã£ã³ã°ã®åæ ãè¦ã¦ã¿ããã£ãã®ã§ä»åã¯ã¬ã³ããªã³ã°â ãæ¡ç¨ãã¾ããããã¥ã¼ãã®ä¸ã«å
¥ãå½¢ã«ãªãã®ã§ãCamera Inside Object
ã«ãã§ãã¯ãå
¥ãããã¤è£é¢ãæç»ãããããã«ãããªã¢ã«ã®è¨å®ã§ Culling
ã Off
ã«ãã¦ããã¾ãã
ãªãããã®ç¯å²ããå¤ã«æã£ã¦åºãã¨ãã®ãªãã¸ã§ã¯ãã¯æ¶ãã¦ãã¾ãã¾ããè¦å¤±ããªãããã«ä¸å¿é¨ã«å°ãããã¥ã¼ãããªã´ã³ãä»è¾¼ãã§ããã¾ãï¼åé ã®åç»ã®ãã¼ã©ã¹ã®ä¸å¿ãè¦ãã¨å ¥ã£ã¦ããã®ãåããã¨æãã¾ãâ¦ï¼ã
ãããã«
ã¤ãã³ãã¾ã§ã«ã¯å°ã調æ´ãã¦çããã«å ¬éã§ããããã«ãã¦ããã¾ããåãã¦è©¦ãã¾ããããuRaymarching ã VRChat ã§ããã®ã¾ã¾åãã¦å¬ããã£ãã§ãï¼ãã ã©ã¤ãã£ã³ã°ãå½±å¨ãã§ã¾ã å¹¾ã¤ããã°ãè¦ã¤ããã®ã§ç¶ç¶ãã¦æ¹åãã¦ããããã§ãã