1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 12:42:11 +00:00
OpenMW/files/shaders/s360_fragment.glsl

54 lines
1.2 KiB
Plaintext
Raw Normal View History

2017-11-15 14:20:59 +00:00
#version 120
varying vec2 uv;
uniform samplerCube cubeMap;
2017-11-15 16:01:16 +00:00
uniform int mapping;
2017-11-15 14:20:59 +00:00
2017-11-15 15:07:01 +00:00
#define PI 3.1415926535
2017-11-15 16:01:16 +00: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 15:07:01 +00: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 16:01:16 +00: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);
}
2017-11-15 14:20:59 +00:00
void main(void)
{
2017-11-15 15:07:01 +00:00
vec3 c;
2017-11-15 16:01:16 +00:00
switch (mapping)
{
case 0: c = sphericalCoords(uv); break;
case 1: c = cylindricalCoords(uv); break;
case 2: c = planetCoords(uv); break;
default: c = sphericalCoords(uv); break;
}
gl_FragData[0] = textureCube(cubeMap,c);
2017-11-15 14:20:59 +00:00
}