stk-code_catmod/data/shaders/objectpass_spheremap.frag

23 lines
721 B
GLSL
Raw Normal View History

#version 330
uniform sampler2D tex;
noperspective in vec3 nor;
out vec4 FragColor;
void main() {
// Calculate the spherical UV
const vec3 forward = vec3(0.0, 0.0, 1.0);
// get the angle between the forward vector and the horizontal portion of the normal
2014-01-17 21:24:55 -05:00
vec3 normal_x = normalize(vec3(nor.x, 0.0, nor.z));
2014-01-18 12:00:08 -05:00
float sin_theta_x = length(cross( forward, normal_x )) * nor.x / abs(nor.x);
// get the angle between the forward vector and the vertical portion of the normal
2014-01-17 21:24:55 -05:00
vec3 normal_y = normalize(vec3(0.0, nor.y, nor.z));
2014-01-18 12:00:08 -05:00
float sin_theta_y = length(cross( forward, normal_y )) * nor.y / abs(nor.y);
vec4 detail0 = texture(tex, 0.5 * vec2(sin_theta_x, sin_theta_y) + 0.5);
FragColor = vec4(detail0.xyz, 1.);
}