[Bf-blender-cvs] [1d1ba540bb] HMD_viewport: New OpenHMD 0.3rc version with PSVR, Oculus CV1 and better Vive tracking support. Also introduces global shader, which will be adjusted based on the variables of the HMD drivers, this will make the manual selection of lens correction shaders obsolete, will be removed in next commit.

Joey Ferwerda noreply at git.blender.org
Mon Mar 6 01:23:30 CET 2017


Commit: 1d1ba540bba10077576eb75bd54b61f6880500ee
Author: Joey Ferwerda
Date:   Mon Mar 6 01:21:14 2017 +0100
Branches: HMD_viewport
https://developer.blender.org/rB1d1ba540bba10077576eb75bd54b61f6880500ee

New OpenHMD 0.3rc version with PSVR, Oculus CV1 and better Vive tracking support.
Also introduces global shader, which will be adjusted based on the variables of the HMD drivers, this will make the manual selection of lens correction shaders obsolete, will be removed in next commit.

The hmd window is currently black before started (due to shader not having the hmd data yet), will be fixed as well.

===================================================================

M	extern/openhmd/CMakeLists.txt
M	extern/openhmd/include/openhmd.h
A	extern/openhmd/src/drv_htc_vive/config.h
M	extern/openhmd/src/drv_htc_vive/packet.c
M	extern/openhmd/src/drv_htc_vive/vive.c
M	extern/openhmd/src/drv_htc_vive/vive.h
M	extern/openhmd/src/drv_oculus_rift/rift.c
A	extern/openhmd/src/drv_psvr/packet.c
A	extern/openhmd/src/drv_psvr/psvr.c
A	extern/openhmd/src/drv_psvr/psvr.h
M	extern/openhmd/src/openhmd.c
M	extern/openhmd/src/openhmdi.h
A	extern/openhmd/src/shaders.c
A	extern/openhmd/src/shaders.h
M	intern/ghost/GHOST_C-api.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_OpenHMDManager.cpp
M	intern/ghost/intern/GHOST_OpenHMDManager.h
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/GPU_compositing.h
M	source/blender/gpu/GPU_shader.h
M	source/blender/gpu/intern/gpu_compositing.c
M	source/blender/gpu/intern/gpu_shader.c
M	source/blender/gpu/shaders/gpu_shader_fx_lensdistortion_frag.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_lensdistortion_vert.glsl
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_device.c

===================================================================

diff --git a/extern/openhmd/CMakeLists.txt b/extern/openhmd/CMakeLists.txt
index 7c0a1aa673..e769d6c2e4 100644
--- a/extern/openhmd/CMakeLists.txt
+++ b/extern/openhmd/CMakeLists.txt
@@ -34,12 +34,14 @@ set(SRC
 	src/platform-posix.c
 	src/fusion.c
 	src/queue.c
+	src/shaders.c
 )
 
 # TODO: Either remove this or move to main CMakeLists.txt
 OPTION(OPENHMD_DRIVER_OCULUS_RIFT "Oculus Rift DK1, DK2 and CV1" ON)
-OPTION(OPENHMD_DRIVER_DEEPOON "Deepoon E2 support" ON)
-OPTION(OPENHMD_DRIVER_HTC_VIVE "HTC Vive support" ON)
+OPTION(OPENHMD_DRIVER_DEEPOON "Deepoon E2" ON)
+OPTION(OPENHMD_DRIVER_PSVR "Sony PSVR" ON)
+OPTION(OPENHMD_DRIVER_HTC_VIVE "HTC Vive" ON)
 OPTION(OPENHMD_DRIVER_EXTERNAL "External sensor driver" OFF)
 OPTION(OPENHMD_DRIVER_ANDROID "General Android driver" OFF)
 
@@ -70,6 +72,17 @@ if(OPENHMD_DRIVER_DEEPOON)
 	list(APPEND INC_SYS ${HIDAPI_INCLUDE_DIRS})
 endif()
 
+if(OPENHMD_DRIVER_PSVR)
+	list(APPEND SRC
+		src/drv_psvr/psvr.c
+		src/drv_psvr/packet.c
+	)
+	add_definitions(-DDRIVER_PSVR)
+
+	find_package(HIDAPI REQUIRED)
+	list(APPEND INC_SYS ${HIDAPI_INCLUDE_DIRS})
+endif()
+
 if(OPENHMD_DRIVER_HTC_VIVE)
 	list(APPEND SRC
 		src/drv_htc_vive/vive.c
diff --git a/extern/openhmd/include/openhmd.h b/extern/openhmd/include/openhmd.h
index 5468fb55b9..c15250168b 100644
--- a/extern/openhmd/include/openhmd.h
+++ b/extern/openhmd/include/openhmd.h
@@ -57,6 +57,12 @@ typedef enum {
 	OHMD_PATH      = 2,
 } ohmd_string_value;
 
+/** A collection of string descriptions, used for getting strings with ohmd_gets(). */
+typedef enum {
+	OHMD_GLSL_DISTORTION_VERT_SRC = 0,
+	OHMD_GLSL_DISTORTION_FRAG_SRC = 1,
+} ohmd_string_description;
+
 /** A collection of float value information types, used for getting and setting information with
     ohmd_device_getf() and ohmd_device_setf(). */
 typedef enum {
@@ -109,7 +115,7 @@ typedef enum {
 
 	/** float[6] (get): Device specific distortion value. */
 	OHMD_DISTORTION_K                     = 18,
-	
+
 	/**
 	 * float[10] (set): Perform sensor fusion on values from external sensors.
 	 *
@@ -117,6 +123,12 @@ typedef enum {
 	 **/
 	OHMD_EXTERNAL_SENSOR_FUSION           = 19,
 
+	/** float[4] (get): Universal shader distortion coefficients (PanoTools model <a,b,c,d>. */
+	OHMD_UNIVERSAL_DISTORTION_K           = 20,
+
+	/** float[3] (get): Universal shader aberration coefficients (post warp scaling <r,g,b>. */
+	OHMD_UNIVERSAL_ABERRATION_K           = 21,
+
 } ohmd_float_value;
 
 /** A collection of int value information types used for getting information with ohmd_device_geti(). */
@@ -226,6 +238,17 @@ OHMD_APIENTRYDLL void OHMD_APIENTRY ohmd_ctx_update(ohmd_context* ctx);
 OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_ctx_probe(ohmd_context* ctx);
 
 /**
+ * Get string from openhmd.
+ *
+ * Gets a string from OpenHMD. This is where non-device specific strings reside.
+ * This is where the distortion shader sources can be retrieved.
+ *
+ * @param type The name of the string to fetch. One of OHMD_GLSL_DISTORTION_FRAG_SRC, and OHMD_GLSL_DISTORTION_FRAG_SRC.
+ * @return a string with a human readable device name.
+ **/
+OHMD_APIENTRYDLL const char* OHMD_APIENTRY ohmd_gets(ohmd_string_description type);
+
+/**
  * Get device description from enumeration list index.
  *
  * Gets a human readable device description string from a zero indexed enumeration index
diff --git a/extern/openhmd/src/drv_htc_vive/config.h b/extern/openhmd/src/drv_htc_vive/config.h
new file mode 100644
index 0000000000..cc6cf6aec8
--- /dev/null
+++ b/extern/openhmd/src/drv_htc_vive/config.h
@@ -0,0 +1 @@
+//Reserved
\ No newline at end of file
diff --git a/extern/openhmd/src/drv_htc_vive/packet.c b/extern/openhmd/src/drv_htc_vive/packet.c
index 2192948e08..c8effb1382 100644
--- a/extern/openhmd/src/drv_htc_vive/packet.c
+++ b/extern/openhmd/src/drv_htc_vive/packet.c
@@ -1,8 +1,5 @@
 #include "vive.h"
-
-/* Suppress the warnings for this include, since we don't care about them for external dependencies
-/* Requires at least GCC 4.6 or higher
-*/
+#include "config.h"
 
 inline static uint8_t read8(const unsigned char** buffer)
 {
diff --git a/extern/openhmd/src/drv_htc_vive/vive.c b/extern/openhmd/src/drv_htc_vive/vive.c
index 39e03563b7..ef575f6102 100644
--- a/extern/openhmd/src/drv_htc_vive/vive.c
+++ b/extern/openhmd/src/drv_htc_vive/vive.c
@@ -27,7 +27,6 @@
 #include <stdbool.h>
 
 #include "vive.h"
-#include "openhmdi.h"
 
 typedef struct {
 	ohmd_device base;
@@ -192,10 +191,10 @@ static void close_device(ohmd_device* device)
 
 	// turn the display off
 	hret = hid_send_feature_report(priv->hmd_handle, vive_magic_power_off1, sizeof(vive_magic_power_off1));
-	printf("power off magic 1: %d\n", hret);
+	//printf("power off magic 1: %d\n", hret);
 
 	hret = hid_send_feature_report(priv->hmd_handle, vive_magic_power_off2, sizeof(vive_magic_power_off2));
-	printf("power off magic 2: %d\n", hret);
+	//printf("power off magic 2: %d\n", hret);
 
 	hid_close(priv->hmd_handle);
 	hid_close(priv->imu_handle);
diff --git a/extern/openhmd/src/drv_htc_vive/vive.h b/extern/openhmd/src/drv_htc_vive/vive.h
index e0eb9db069..7c0e1ec3f3 100644
--- a/extern/openhmd/src/drv_htc_vive/vive.h
+++ b/extern/openhmd/src/drv_htc_vive/vive.h
@@ -30,8 +30,8 @@ typedef struct
 typedef struct
 {
 	uint8_t report_id;
-	uint8_t length;
-	uint8_t config_data;
+	uint16_t length;
+	unsigned char config_data[99999];
 } vive_config_packet;
 
 void vec3f_from_vive_vec(const int16_t* smp, vec3f* out_vec);
diff --git a/extern/openhmd/src/drv_oculus_rift/rift.c b/extern/openhmd/src/drv_oculus_rift/rift.c
index ee045f8bea..2011704105 100644
--- a/extern/openhmd/src/drv_oculus_rift/rift.c
+++ b/extern/openhmd/src/drv_oculus_rift/rift.c
@@ -313,11 +313,62 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 	priv->base.properties.vres = priv->display_info.v_resolution;
 	priv->base.properties.lens_sep = priv->display_info.lens_separation;
 	priv->base.properties.lens_vpos = priv->display_info.v_center;
-	priv->base.properties.fov = DEG_TO_RAD(125.5144f); // TODO calculate.
 	priv->base.properties.ratio = ((float)priv->display_info.h_resolution / (float)priv->display_info.v_resolution) / 2.0f;
 
+	//setup generic distortion coeffs, from hand-calibration
+	switch (desc->revision) {
+		case REV_DK2:
+			priv->base.properties.universal_distortion_k[0] = 0.247;
+			priv->base.properties.universal_distortion_k[1] = -0.145;
+			priv->base.properties.universal_distortion_k[2] = 0.103;
+			priv->base.properties.universal_distortion_k[3] = 0.795;
+			priv->base.properties.universal_aberration_k[0] = 0.985;
+			priv->base.properties.universal_aberration_k[1] = 1.000;
+			priv->base.properties.universal_aberration_k[2] = 1.015;
+			break;
+		case REV_DK1:
+			priv->base.properties.universal_distortion_k[0] = 1.003;
+			priv->base.properties.universal_distortion_k[1] = -1.005;
+			priv->base.properties.universal_distortion_k[2] = 0.403;
+			priv->base.properties.universal_distortion_k[3] = 0.599;
+			priv->base.properties.universal_aberration_k[0] = 0.985;
+			priv->base.properties.universal_aberration_k[1] = 1.000;
+			priv->base.properties.universal_aberration_k[2] = 1.015;
+			break;
+		default:
+			break;
+	}
+
 	// calculate projection eye projection matrices from the device properties
-	ohmd_calc_default_proj_matrices(&priv->base.properties);
+	//ohmd_calc_default_proj_matrices(&priv->base.properties);
+	float l,r,t,b,n,f;
+	mat4x4f l_proj; // left projection matrix
+	mat4x4f r_proj; // right projection matrix
+	mat4x4f translate;
+	// left eye screen bounds
+	l = -1.0f * (priv->display_info.h_screen_size/2 - priv->display_info.lens_separation/2);
+	r = priv->display_info.lens_separation/2;
+	t = priv->display_info.v_screen_size - priv->display_info.v_center;
+	b = -1.0f * priv->display_info.v_center;
+	n = priv->display_info.eye_to_screen_distance[0];
+	f = n*10e6;
+	//LOGD("l: %0.3f, r: %0.3f, b: %0.3f, t: %0.3f, n: %0.3f, f: %0.3f", l,r,b,t,n,f);
+	omat4x4f_init_frustum(&l_proj, l, r, b, t, n, f);
+	omat4x4f_init_translate(&translate, r, 0, 0); //shift over eye offset
+	omat4x4f_mult(&translate, &l_proj, &priv->base.properties.proj_left); //LEFT multiply inside OpenHMD
+	//right eye screen bounds
+	l = -1.0f * priv->display_info.lens_separation/2;
+	r = priv->display_info.h_screen_size/2 - priv->display_info.lens_separation/2;
+	n = priv->display_info.eye_to_screen_distance[1];
+	f = n*10e6;
+	//LOGD("l: %0.3f, r: %0.3f, b: %0.3f, t: %0.3f, n: %0.3f, f: %0.3f", l,r,b,t,n,f);
+	omat4x4f_init_frustum(&r_proj, l, r, b, t, n, f);
+	omat4x4f_init_translate(&translate, l, 0, 0); //shift over eye offset
+	omat4x4f_mult(&translate, &r_proj, &priv->base.properties.proj_right); //LEFT multiply inside OpenHMD
+
+	priv->base.properties.fov = 2 * atan2f(
+			priv->display_info.h_screen_size/2 - priv->display_info.lens_separation/2,
+			priv->display_info.eye_to_screen_distance[0]);
 
 	// set up device callbacks
 	priv->base.update = update_device;
diff --git a/extern/openhmd/src/drv_psvr/packet.c b/extern/openhmd/src/drv_psvr/packet.c
new file mode 100644
index 0000000000..285e389223
--- /dev/null
+++ b/extern/openhmd/src/drv_psvr/packet.c
@@ -0,0 +1,49 @@
+#include "psvr.h"
+
+inline static uint8_t read8(const unsigned char** buffer)
+{
+	uint8_t ret = **buffer;
+	*buffer += 1;
+	return ret;
+}
+
+inline static int16_t read16(const unsigned char** buffer)
+{
+	int16_t ret = **buffer | (*(*buffer + 1) << 8);
+	*buffer += 2;
+	return ret;
+}
+
+inline static uint32_t read32(const unsigned char** buffer)
+{
+	uint32_t ret = **buffer | (*(*buffer + 1) << 8) | (*(*buffer + 2) << 16) | (*(*buffer + 3) << 24);
+	*buffer += 4;
+	return ret;
+}
+
+bool psvr_decode_sensor_packet(psvr_sensor_packet* pkt, const unsigned char* buffer, int size)
+{
+	if(size != 64){
+		LOGE("invalid psvr sensor packet size (expected 64 but got %d)", size);
+		return false;
+	}
+
+	buffer += 2; //skip 2
+	pkt->samples[0].volume = read16(&buffer); //volume
+	buffer += 12; //unknown, skip 12
+	pkt->samples[0].tick = read32(&buffer); //TICK
+	// acceleration
+	for(int i = 0; i < 3; i++){
+		pkt->samples[0].gyro[i] = read16(&buffer);
+	}
+
+	// rotation
+	for(int i = 0; i < 3; i++){
+		pkt->samples[0].

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list