2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2017-12-04 13:41:34 +01:00
|
|
|
[vertex]
|
|
|
|
|
2018-02-24 14:48:22 +01:00
|
|
|
#ifdef USE_GLES_OVER_GL
|
2018-12-21 15:14:55 +01:00
|
|
|
#define lowp
|
2018-02-24 14:48:22 +01:00
|
|
|
#define mediump
|
|
|
|
#define highp
|
|
|
|
#else
|
|
|
|
precision mediump float;
|
|
|
|
precision mediump int;
|
|
|
|
#endif
|
2017-12-04 13:41:34 +01:00
|
|
|
|
2018-02-24 14:48:22 +01:00
|
|
|
attribute highp vec4 vertex_attrib; // attrib:0
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2018-02-24 14:48:22 +01:00
|
|
|
attribute vec2 uv_in; // attrib:4
|
2017-12-04 13:41:34 +01:00
|
|
|
|
2018-02-24 14:48:22 +01:00
|
|
|
varying vec2 uv_interp;
|
2017-12-04 13:41:34 +01:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
|
|
|
uv_interp = uv_in;
|
|
|
|
gl_Position = vertex_attrib;
|
|
|
|
}
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2017-12-04 13:41:34 +01:00
|
|
|
[fragment]
|
|
|
|
|
2018-02-24 14:48:22 +01:00
|
|
|
#ifdef USE_GLES_OVER_GL
|
2018-12-21 15:14:55 +01:00
|
|
|
#define lowp
|
2018-02-24 14:48:22 +01:00
|
|
|
#define mediump
|
|
|
|
#define highp
|
|
|
|
#else
|
2019-09-01 00:03:55 +02:00
|
|
|
#if defined(USE_HIGHP_PRECISION)
|
|
|
|
precision highp float;
|
|
|
|
precision highp int;
|
|
|
|
#else
|
2018-02-24 14:48:22 +01:00
|
|
|
precision mediump float;
|
|
|
|
precision mediump int;
|
|
|
|
#endif
|
2019-09-01 00:03:55 +02:00
|
|
|
#endif
|
2017-12-04 13:41:34 +01:00
|
|
|
|
|
|
|
uniform highp samplerCube source_cube; //texunit:0
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2018-02-24 14:48:22 +01:00
|
|
|
varying vec2 uv_interp;
|
2017-12-04 13:41:34 +01:00
|
|
|
|
|
|
|
uniform bool z_flip;
|
|
|
|
uniform highp float z_far;
|
|
|
|
uniform highp float z_near;
|
|
|
|
uniform highp float bias;
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
2018-08-24 14:50:59 +02:00
|
|
|
highp vec3 normal = vec3(uv_interp * 2.0 - 1.0, 0.0);
|
|
|
|
/*
|
|
|
|
if (z_flip) {
|
|
|
|
normal.z = 0.5 - 0.5 * ((normal.x * normal.x) + (normal.y * normal.y));
|
2017-12-04 13:41:34 +01:00
|
|
|
} else {
|
2018-08-24 14:50:59 +02:00
|
|
|
normal.z = -0.5 + 0.5 * ((normal.x * normal.x) + (normal.y * normal.y));
|
2017-12-04 13:41:34 +01:00
|
|
|
}
|
2018-08-24 14:50:59 +02:00
|
|
|
*/
|
2017-12-04 13:41:34 +01:00
|
|
|
|
2018-08-24 14:50:59 +02:00
|
|
|
//normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
|
|
|
|
//normal.xy *= 1.0 + normal.z;
|
2017-12-04 13:41:34 +01:00
|
|
|
|
2018-08-24 14:50:59 +02:00
|
|
|
normal.z = 0.5 - 0.5 * ((normal.x * normal.x) + (normal.y * normal.y));
|
2017-12-04 13:41:34 +01:00
|
|
|
normal = normalize(normal);
|
2018-08-24 14:50:59 +02:00
|
|
|
/*
|
|
|
|
normal.z = 0.5;
|
|
|
|
normal = normalize(normal);
|
|
|
|
*/
|
2017-12-04 13:41:34 +01:00
|
|
|
|
|
|
|
if (!z_flip) {
|
2018-08-24 14:50:59 +02:00
|
|
|
normal.z = -normal.z;
|
2017-12-04 13:41:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//normal = normalize(vec3( uv_interp * 2.0 - 1.0, 1.0 ));
|
2018-08-24 14:50:59 +02:00
|
|
|
float depth = textureCube(source_cube, normal).r;
|
2017-12-04 13:41:34 +01:00
|
|
|
|
|
|
|
// absolute values for direction cosines, bigger value equals closer to basis axis
|
|
|
|
vec3 unorm = abs(normal);
|
|
|
|
|
2018-08-24 14:50:59 +02:00
|
|
|
if ((unorm.x >= unorm.y) && (unorm.x >= unorm.z)) {
|
|
|
|
// x code
|
|
|
|
unorm = normal.x > 0.0 ? vec3(1.0, 0.0, 0.0) : vec3(-1.0, 0.0, 0.0);
|
|
|
|
} else if ((unorm.y > unorm.x) && (unorm.y >= unorm.z)) {
|
|
|
|
// y code
|
|
|
|
unorm = normal.y > 0.0 ? vec3(0.0, 1.0, 0.0) : vec3(0.0, -1.0, 0.0);
|
|
|
|
} else if ((unorm.z > unorm.x) && (unorm.z > unorm.y)) {
|
|
|
|
// z code
|
|
|
|
unorm = normal.z > 0.0 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 0.0, -1.0);
|
2017-12-04 13:41:34 +01:00
|
|
|
} else {
|
2018-08-24 14:50:59 +02:00
|
|
|
// oh-no we messed up code
|
|
|
|
// has to be
|
|
|
|
unorm = vec3(1.0, 0.0, 0.0);
|
2017-12-04 13:41:34 +01:00
|
|
|
}
|
|
|
|
|
2018-08-24 14:50:59 +02:00
|
|
|
float depth_fix = 1.0 / dot(normal, unorm);
|
2017-12-04 13:41:34 +01:00
|
|
|
|
|
|
|
depth = 2.0 * depth - 1.0;
|
|
|
|
float linear_depth = 2.0 * z_near * z_far / (z_far + z_near - depth * (z_far - z_near));
|
2018-08-24 14:50:59 +02:00
|
|
|
gl_FragDepth = (linear_depth * depth_fix + bias) / z_far;
|
2017-12-04 13:41:34 +01:00
|
|
|
}
|