mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Merge pull request #9128 from Polyrhythm/ryan/v3-and-shader-helpers
Vec3 and shader helpers
This commit is contained in:
commit
333e9ec7f4
3 changed files with 35 additions and 0 deletions
|
@ -264,6 +264,35 @@ float snoise(vec2 v) {
|
|||
return 130.0 * dot(m, g);
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/lsfGRr
|
||||
float hifi_hash(float n) {
|
||||
return fract(sin(n) * 43758.5453);
|
||||
}
|
||||
|
||||
float hifi_noise(in vec2 x) {
|
||||
vec2 p = floor(x);
|
||||
vec2 f = fract(x);
|
||||
|
||||
f = f * f * (3.0 - 2.0 * f);
|
||||
|
||||
float n = p.x + p.y * 57.0;
|
||||
|
||||
return mix(mix(hifi_hash(n + 0.0), hifi_hash(n + 1.0), f.x),
|
||||
mix(hifi_hash(n + 57.0), hifi_hash(n + 58.0), f.x), f.y);
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/MdX3Rr
|
||||
// https://en.wikipedia.org/wiki/Fractional_Brownian_motion
|
||||
float hifi_fbm(in vec2 p) {
|
||||
const mat2 m2 = mat2(0.8, -0.6, 0.6, 0.8);
|
||||
float f = 0.0;
|
||||
f += 0.5000 * hifi_noise(p); p = m2 * p * 2.02;
|
||||
f += 0.2500 * hifi_noise(p); p = m2 * p * 2.03;
|
||||
f += 0.1250 * hifi_noise(p); p = m2 * p * 2.01;
|
||||
f += 0.0625 * hifi_noise(p);
|
||||
|
||||
return f / 0.9375;
|
||||
}
|
||||
|
||||
#define PROCEDURAL 1
|
||||
|
||||
|
|
|
@ -82,3 +82,8 @@ glm::vec3 Vec3::fromPolar(float elevation, float azimuth) {
|
|||
glm::vec3 v = glm::vec3(elevation, azimuth, 1.0f);
|
||||
return fromPolar(v);
|
||||
}
|
||||
|
||||
float Vec3::getAngle(const glm::vec3& v1, const glm::vec3& v2) {
|
||||
return glm::acos(glm::dot(glm::normalize(v1), glm::normalize(v2)));
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ public slots:
|
|||
glm::vec3 toPolar(const glm::vec3& v);
|
||||
glm::vec3 fromPolar(const glm::vec3& polar);
|
||||
glm::vec3 fromPolar(float elevation, float azimuth);
|
||||
float getAngle(const glm::vec3& v1, const glm::vec3& v2);
|
||||
|
||||
private:
|
||||
const glm::vec3& UNIT_X() { return Vectors::UNIT_X; }
|
||||
|
|
Loading…
Reference in a new issue