101 lines
2.6 KiB
GLSL
101 lines
2.6 KiB
GLSL
|
|
#define PI 3.14159265359
|
|
#define HALF_PI 1.570796327
|
|
#define MEDIUMP_FLT_MAX 65504.0
|
|
#define MEDIUMP_FLT_MIN 0.00006103515625
|
|
#ifdef TARGET_MOBILE
|
|
#define FLT_EPS MEDIUMP_FLT_MIN
|
|
#else
|
|
#define FLT_EPS 1e-5
|
|
#endif
|
|
#define saturate(x) clamp(x, 0.0, 1.0)
|
|
#ifdef TARGET_MOBILE
|
|
#define PREVENT_DIV0(n, d, magic) ((n) / max(d, magic))
|
|
#else
|
|
#define PREVENT_DIV0(n, d, magic) ((n) / (d))
|
|
#endif
|
|
float pow5(float x) {
|
|
float x2 = x * x;
|
|
return x2 * x2 * x;
|
|
}
|
|
float sq(float x) {
|
|
return x * x;
|
|
}
|
|
float max3(const vec3 v) {
|
|
return max(v.x, max(v.y, v.z));
|
|
}
|
|
float vmax(const vec2 v) {
|
|
return max(v.x, v.y);
|
|
}
|
|
float vmax(const vec3 v) {
|
|
return max(v.x, max(v.y, v.z));
|
|
}
|
|
float vmax(const vec4 v) {
|
|
return max(max(v.x, v.y), max(v.z, v.w));
|
|
}
|
|
float min3(const vec3 v) {
|
|
return min(v.x, min(v.y, v.z));
|
|
}
|
|
float vmin(const vec2 v) {
|
|
return min(v.x, v.y);
|
|
}
|
|
float vmin(const vec3 v) {
|
|
return min(v.x, min(v.y, v.z));
|
|
}
|
|
float vmin(const vec4 v) {
|
|
return min(min(v.x, v.y), min(v.z, v.w));
|
|
}
|
|
float acosFast(float x) {
|
|
float y = abs(x);
|
|
float p = -0.1565827 * y + 1.570796;
|
|
p *= sqrt(1.0 - y);
|
|
return x >= 0.0 ? p : PI - p;
|
|
}
|
|
float acosFastPositive(float x) {
|
|
float p = -0.1565827 * x + 1.570796;
|
|
return p * sqrt(1.0 - x);
|
|
}
|
|
highp vec4 mulMat4x4Float3(const highp mat4 m, const highp vec3 v) {
|
|
return v.x * m[0] + (v.y * m[1] + (v.z * m[2] + m[3]));
|
|
}
|
|
highp vec3 mulMat3x3Float3(const highp mat4 m, const highp vec3 v) {
|
|
return v.x * m[0].xyz + (v.y * m[1].xyz + (v.z * m[2].xyz));
|
|
}
|
|
void toTangentFrame(const highp vec4 q, out highp vec3 n) {
|
|
n = vec3( 0.0, 0.0, 1.0) +
|
|
vec3( 2.0, -2.0, -2.0) * q.x * q.zwx +
|
|
vec3( 2.0, 2.0, -2.0) * q.y * q.wzy;
|
|
}
|
|
void toTangentFrame(const highp vec4 q, out highp vec3 n, out highp vec3 t) {
|
|
toTangentFrame(q, n);
|
|
t = vec3( 1.0, 0.0, 0.0) +
|
|
vec3(-2.0, 2.0, -2.0) * q.y * q.yxw +
|
|
vec3(-2.0, 2.0, 2.0) * q.z * q.zwx;
|
|
}
|
|
highp mat3 cofactor(const highp mat3 m) {
|
|
highp float a = m[0][0];
|
|
highp float b = m[1][0];
|
|
highp float c = m[2][0];
|
|
highp float d = m[0][1];
|
|
highp float e = m[1][1];
|
|
highp float f = m[2][1];
|
|
highp float g = m[0][2];
|
|
highp float h = m[1][2];
|
|
highp float i = m[2][2];
|
|
highp mat3 cof;
|
|
cof[0][0] = e * i - f * h;
|
|
cof[0][1] = c * h - b * i;
|
|
cof[0][2] = b * f - c * e;
|
|
cof[1][0] = f * g - d * i;
|
|
cof[1][1] = a * i - c * g;
|
|
cof[1][2] = c * d - a * f;
|
|
cof[2][0] = d * h - e * g;
|
|
cof[2][1] = b * g - a * h;
|
|
cof[2][2] = a * e - b * d;
|
|
return cof;
|
|
}
|
|
float interleavedGradientNoise(highp vec2 w) {
|
|
const vec3 m = vec3(0.06711056, 0.00583715, 52.9829189);
|
|
return fract(m.z * fract(dot(w, m.xy)));
|
|
}
|