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
|
#pragma once
// https://gist.github.com/tesu/196db5421559de3e9555d4f9da9d847d
// FOV: [0 to M_PI] horizontal field of view, range is exclusive
// YAW: [any float] polar angle, one full revolution is 2*M_PI
// PITCH: [any float] vertical tilt, positive is up
// ROLL: [any float] view rotation, positive is clockwise
static char vr_video_shader[] = \
"//!PARAM mouse_x\n"
"//!TYPE float\n"
"//!MINIMUM -1.0\n"
"//!MAXIMUM 3.0\n"
"0.0\n"
"//!PARAM mouse_y\n"
"//!TYPE float\n"
"//!MINIMUM -0.5\n"
"//!MAXIMUM 1.5\n"
"0.5\n"
"//!PARAM fov\n"
"//!TYPE float\n"
"//!MINIMUM 0.0\n"
"//!MAXIMUM 3.141592653589793\n"
"1.5707963267948966\n"
"//!PARAM mode\n"
"//!TYPE float\n"
"//!MINIMUM 0.0\n"
"//!MAXIMUM 2.0\n"
"1.0\n" // 0.0 = Left eye, 1.0 = Right eye, 2.0 = 360 degrees.
"//!HOOK MAINPRESUB\n"
"//!BIND HOOKED\n"
"//!DESC un360\n"
"const float M_PI = 3.141592653589793;"
"vec4 hook() {"
" float yaw = M_PI*mouse_x;"
" float pitch = M_PI*(-0.5+mouse_y);"
" float roll = M_PI*0.0;"
" float t = tan(fov/2.0);"
" float c = cos(pitch);"
" float s = sin(pitch);"
" float r = target_size.y/target_size.x;"
" float sR = sin(roll);"
" float cR = cos(roll);"
" mat3 m = mat3(2.0*t*cR, 2.0*sR*t*r, -t*(cR+sR*r), -2.0*sR*t*c, 2.0*cR*t*c*r, t*c*(sR-cR*r)-s, -2.0*sR*t*s, 2.0*cR*t*s*r, t*s*(sR-cR*r)+c);"
" vec3 p = vec3(HOOKED_pos, 1.0)*m;"
" float theta = atan(p.x, p.z)+yaw;"
" float phi = atan(p.y, length(p.xz))+M_PI/2.0;"
" float x = fract(theta/(2.0*M_PI));"
" float y = phi/M_PI;" // Range: [M_PI, 2.0*M_PI] = Right eye 180 degrees. float(max(theta, mode-1.0) > 0.0) = Always true except mode = 0.0 and theta < 0.0.
" return HOOKED_tex(vec2(x, y))*clamp(abs((1.0-mode)-(step(M_PI, theta)-step(2.0*M_PI, theta)))*float(max(theta, mode-1.0)>=0.0), 0.0, 1.0);"
"}";
|