mirror of
https://github.com/lubosz/overte.git
synced 2025-04-10 00:04:18 +02:00
add helpers for v3 and shaders
This commit is contained in:
parent
030f0d7103
commit
3ccc493871
3 changed files with 46 additions and 0 deletions
|
@ -264,6 +264,37 @@ float snoise(vec2 v) {
|
|||
return 130.0 * dot(m, g);
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/lsfGRr
|
||||
float hash( float n )
|
||||
{
|
||||
return fract(sin(n)*43758.5453);
|
||||
}
|
||||
|
||||
float 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( hash(n+ 0.0), hash(n+ 1.0),f.x),
|
||||
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
|
||||
}
|
||||
|
||||
// https://www.shadertoy.com/view/MdX3Rr
|
||||
// https://en.wikipedia.org/wiki/Fractional_Brownian_motion
|
||||
float fbm(in vec2 p) {
|
||||
const mat2 m2 = mat2(0.8, -0.6, 0.6, 0.8);
|
||||
float f = 0.0;
|
||||
f += 0.5000 * noise(p); p = m2 * p * 2.02;
|
||||
f += 0.2500 * noise(p); p = m2 * p * 2.03;
|
||||
f += 0.1250 * noise(p); p = m2 * p * 2.01;
|
||||
f += 0.0625 * noise(p);
|
||||
|
||||
return f / 0.9375;
|
||||
}
|
||||
|
||||
#define PROCEDURAL 1
|
||||
|
||||
|
|
|
@ -82,3 +82,16 @@ glm::vec3 Vec3::fromPolar(float elevation, float azimuth) {
|
|||
glm::vec3 v = glm::vec3(elevation, azimuth, 1.0f);
|
||||
return fromPolar(v);
|
||||
}
|
||||
|
||||
float Vec3::angle(const glm::vec3& fromV, const glm::vec3& toV) {
|
||||
glm::vec3 fromVNormalized = glm::normalize(fromV);
|
||||
glm::vec3 toVNormalized = glm::normalize(toV);
|
||||
|
||||
float radians = glm::acos(glm::dot(fromVNormalized, toVNormalized));
|
||||
|
||||
return radians * 180.0f / PI;
|
||||
}
|
||||
|
||||
glm::vec3 Vec3::lerp(const glm::vec3& v1, const glm::vec3& v2, float t) {
|
||||
return v1 * (1.0f - t) + v2 * t;
|
||||
}
|
||||
|
|
|
@ -83,6 +83,8 @@ public slots:
|
|||
glm::vec3 toPolar(const glm::vec3& v);
|
||||
glm::vec3 fromPolar(const glm::vec3& polar);
|
||||
glm::vec3 fromPolar(float elevation, float azimuth);
|
||||
float angle(const glm::vec3& fromV, const glm::vec3& toV);
|
||||
glm::vec3 lerp(const glm::vec3& v1, const glm::vec3& v2, float t);
|
||||
|
||||
private:
|
||||
const glm::vec3& UNIT_X() { return Vectors::UNIT_X; }
|
||||
|
|
Loading…
Reference in a new issue