stk-code_catmod/data/shaders/objectpass_spheremap.frag

37 lines
938 B
GLSL
Raw Normal View History

2014-05-17 21:19:18 -04:00
// See http://www.ozone3d.net/tutorials/glsl_texturing_p04.php for ref
2014-08-18 11:49:44 -04:00
#ifdef GL_ARB_bindless_texture
layout(bindless_sampler) uniform sampler2D tex;
#else
2014-05-17 21:01:24 -04:00
uniform sampler2D tex;
2014-08-18 11:49:44 -04:00
#endif
#if __VERSION__ >= 130
in vec3 nor;
out vec4 FragColor;
#else
varying vec3 nor;
#define FragColor gl_FragColor
#endif
2014-05-17 21:19:18 -04:00
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
2014-05-17 21:39:53 -04:00
vec3 getLightFactor(float specMapValue);
void main() {
2014-05-17 21:19:18 -04:00
vec3 texc = gl_FragCoord.xyz / vec3(screen, 1.);
vec3 u = getPosFromUVDepth(texc, InverseProjectionMatrix).xyz;
vec3 r = reflect(u, nor);
float m = 2.0 * sqrt(r.x * r.x + r.y * r.y + (r.z + 1.0) * (r.z + 1.0));
2014-05-17 21:39:53 -04:00
r.y = - r.y;
2014-05-17 21:19:18 -04:00
vec4 detail0 = texture(tex, r.xy / m + .5);
2014-08-18 11:49:44 -04:00
#ifdef GL_ARB_bindless_texture
#ifdef SRGBBindlessFix
2014-08-18 11:49:44 -04:00
detail0.xyz = pow(detail0.xyz, vec3(2.2));
#endif
2014-08-18 11:49:44 -04:00
#endif
2014-05-17 21:39:53 -04:00
vec3 LightFactor = getLightFactor(1.);
2014-05-17 21:39:53 -04:00
FragColor = vec4(detail0.xyz * LightFactor, 1.);
}