diff options
Diffstat (limited to 'src/render/shaders')
| -rw-r--r-- | src/render/shaders/vr_video.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/render/shaders/vr_video.h b/src/render/shaders/vr_video.h new file mode 100644 index 0000000..fc2d192 --- /dev/null +++ b/src/render/shaders/vr_video.h @@ -0,0 +1,46 @@ +#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 +//" const float yaw = M_PI*(-1.0+(mouse_x*2.0));\n" // 360 +static const char vr_video_shader[] = \ +"//!PARAM mouse_x\n" +"//!TYPE float\n" +"//!MINIMUM -0.5\n" +"//!MAXIMUM 1.5\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\n" +"//!MAXIMUM 3.141592653589793\n" +"1.5707963267948966\n" +"//!HOOK MAINPRESUB\n" +"//!BIND HOOKED\n" +"//!DESC un360\n" +"const float M_PI = 3.141592653589793;\n" +"vec4 hook() {\n" +" float yaw = M_PI*mouse_x;\n" +" float pitch = M_PI*(-0.5+mouse_y);\n" +" float roll = M_PI*0.0;\n" +" float t = tan(fov/2);\n" +" float c = cos(pitch);\n" +" float s = sin(pitch);\n" +" float r = target_size.y/target_size.x;\n" +" float sR = sin(roll);\n" +" float cR = cos(roll);\n" +" mat3 m = mat3(2*t*cR, 2*sR*t*r, -t*(cR+sR*r), -2*sR*t*c, 2*cR*t*c*r, t*c*(sR-cR*r)-s, -2*sR*t*s, 2*cR*t*s*r, t*s*(sR-cR*r)+c);\n" +" vec3 p = vec3(HOOKED_pos, 1.0) * m;\n" +" float theta = atan(p.x, p.z) + yaw;\n" +" float phi = atan(p.y, length(p.xz)) + M_PI/2;\n" +" float x = fract(theta / (2*M_PI));\n" +" float y = phi / M_PI;\n" +" return HOOKED_tex(vec2(x, y));\n" +"}\n"; |