/// <summary> /// Gets the pose of the given eye, predicted for the time when the current frame will scan out. /// </summary> public Pose GetEyePose (dpncEYE eye , dpnQuarterion pose , dpnVector3 position // position 在当前应该已经被转成左手系(Unity)了 , float interpupillary_distance ) { Quaternion rot = pose.ToQuaternion(); // 右手螺旋, 左手系 -> 左手螺旋,左手系(Unity) float eye_offset_x = 0.5f * interpupillary_distance; eye_offset_x = (eye == dpncEYE.LEFT) ? -eye_offset_x : eye_offset_x; float neck_to_eye_height = 0.0f; float eye_depth = 0.0f; // PC: head model do in native sdk, Android: for compatible old game, do here as old apps #if UNITY_ANDROID && !UNITY_EDITOR float eye_height = 1.6f; float player_height = eye_height * 1.067f; // eye should be at 15/16 of total height. neck_to_eye_height = player_height * 0.0625f * DpnManager.worldScale; //neck_to_eye_height should be 1/16 of total height. eye_depth = 0.0805f * DpnManager.worldScale; #endif Vector3 neck_model = new Vector3(0.0f, neck_to_eye_height, eye_depth); Vector3 pos = rot * (new Vector3(eye_offset_x, 0.0f, 0.0f) + neck_model); // neck-pivot space pos -= neck_model; // what it does is converting pos to initially oriented center-eye space, making the initial position of center eye (0,0,0) Pose ret = new Pose(); ret.position = pos + new Vector3(position.x, position.y, position.z); ret.orientation = rot; return(ret); }
// this is used for unity 5.6 //public IntPtr GetEyeTexturePtr56(dpncEYE eye) { return _texture_ptrs[(_current_texture_index + _texture_count + (int)eye - 2) % _texture_count]; } private void ConfigureEyeTexture (int buffer_index, dpncEYE eye , TEXTURE_DEPTH texture_depth , RenderTextureFormat texture_format , int texture_w, int texture_h ) { int tex_index = buffer_index + (int)eye; _textures[tex_index] = new RenderTexture (texture_w, texture_h , (int)texture_depth, texture_format); if (QualitySettings.antiAliasing != 0) { _textures[tex_index].antiAliasing = QualitySettings.antiAliasing; } else { #if UNITY_ANDROID && !UNITY_EDITOR _textures[tex_index].antiAliasing = 4; #else _textures[tex_index].antiAliasing = 1; #endif } _textures[tex_index].Create(); _texture_ptrs[tex_index] = _textures[tex_index].GetNativeTexturePtr(); }
public static bool SetTextures(IntPtr tex_ptr, dpncEYE eye) { bool ret; ret = DpnuSetTexture(tex_ptr, (int)eye, 3, // distortion time warp DpnManager.DeviceInfo.resolution_x, DpnManager.DeviceInfo.resolution_y); if (!ret) { return(false); } return(true); }
/// <summary> /// invoked by DpnPostRender /// </summary> public void _EndEye(Camera cam) { dpncEYE eye = ((PLUGIN_EVENT_TYPE)cam.depth == PLUGIN_EVENT_TYPE.RightEyeEndFrame) ? dpncEYE.RIGHT : dpncEYE.LEFT; dpnRect view = new dpnRect(new Rect(0, 0, Camera.current.targetTexture.width, Camera.current.targetTexture.height)); IntPtr tempPtr = Marshal.AllocHGlobal(Marshal.SizeOf(view)); Marshal.StructureToPtr(view, tempPtr, false); Composer.PostRender(RENDER_EVENT.Postnontransparent, (int)tempPtr); #if UNITY_5_6_0 || UNITY_5_6_1 IntPtr eyeTexturePtr = prev; prev = Camera.current.targetTexture.GetNativeTexturePtr(); #else IntPtr eyeTexturePtr = Camera.current.targetTexture.GetNativeTexturePtr(); #endif Composer.SetTextures(eyeTexturePtr, eye); }
/// <summary> /// invoked by DpnPostRender /// </summary> public void _EndEye(Camera cam) { dpncEYE eye = ((PLUGIN_EVENT_TYPE)cam.depth == PLUGIN_EVENT_TYPE.RightEyeEndFrame) ? dpncEYE.RIGHT : dpncEYE.LEFT; dpnRect view = new dpnRect(new Rect(0, 0, Camera.current.targetTexture.width, Camera.current.targetTexture.height)); IntPtr tempPtr = Marshal.AllocHGlobal(Marshal.SizeOf(view)); Marshal.StructureToPtr(view, tempPtr, false); if (!DpnDevice.bQCOM) // XR1: support texture clamp to board, don't need app fill edge as black. Plugin use partial clear to filledge, which cause enable foveated rendering failed { Composer.PostRender(RENDER_EVENT.Postnontransparent, (int)tempPtr); } #if UNITY_5_6_0 || UNITY_5_6_1 IntPtr eyeTexturePtr = prev; prev = Camera.current.targetTexture.GetNativeTexturePtr(); #else IntPtr eyeTexturePtr = Camera.current.targetTexture.GetNativeTexturePtr(); #endif Composer.SetTextures(eyeTexturePtr, eye); }
/// <summary> /// Gets the currently active render texture's native ID for the given eye. /// </summary> public IntPtr GetEyeTexturePtr(dpncEYE eye) { return(_texture_ptrs[_current_texture_index + (int)eye]); }
/// <summary> /// Gets the currently active render texture for the given eye. /// </summary> public RenderTexture GetEyeTexture(dpncEYE eye) { return(_textures[_current_texture_index + (int)eye]); }