1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-18 13:12:50 +00:00
OpenMW/files/shaders/lib/util/coordinates.glsl

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
924 B
Plaintext
Raw Normal View History

2023-02-25 11:03:39 -08:00
#ifndef LIB_UTIL_COORDINATES
#define LIB_UTIL_COORDINATES
2017-11-15 15:20:59 +01:00
2017-11-15 16:07:01 +01:00
#define PI 3.1415926535
2017-11-15 17:01:16 +01:00
vec3 sphericalCoords(vec2 coords)
{
coords.x = -1 * coords.x * 2 * PI;
coords.y = (coords.y - 0.5) * PI;
vec3 result = vec3(0.0,cos(coords.y),sin(coords.y));
result = vec3(cos(coords.x) * result.y,sin(coords.x) * result.y,result.z);
return result;
}
2017-11-15 16:07:01 +01:00
vec3 cylindricalCoords(vec2 coords)
{
return normalize(vec3(cos(-1 * coords.x * 2 * PI),sin(-1 * coords.x * 2 * PI),coords.y * 2.0 - 1.0));
}
2017-11-15 17:01:16 +01:00
vec3 planetCoords(vec2 coords)
{
vec2 fromCenter = coords - vec2(0.5,0.5);
float magnitude = length(fromCenter);
fromCenter = normalize(fromCenter);
float dotProduct = dot(fromCenter,vec2(0.0,1.0));
coords.x = coords.x > 0.5 ? 0.5 - (dotProduct + 1.0) / 4.0 : 0.5 + (dotProduct + 1.0) / 4.0;
coords.y = max(0.0,1.0 - pow(magnitude / 0.5,0.5));
return sphericalCoords(coords);
}
2023-02-25 11:03:39 -08:00
#endif