stk-code_catmod/data/shaders/objectpass_spheremap.frag

35 lines
818 B
GLSL
Raw Normal View History

2014-04-10 11:34:57 -04:00
layout (std140) uniform MatrixesData
{
mat4 ViewMatrix;
mat4 ProjectionMatrix;
mat4 InverseViewMatrix;
mat4 InverseProjectionMatrix;
mat4 ShadowViewProjMatrixes[4];
};
2014-03-02 18:47:13 -05:00
uniform samplerCube tex;
uniform vec2 screen;
#if __VERSION__ >= 130
in vec3 nor;
out vec4 FragColor;
#else
varying vec3 nor;
#define FragColor gl_FragColor
#endif
void main() {
2014-03-02 18:47:13 -05:00
vec3 fpos = gl_FragCoord.xyz / vec3(screen, 1.);
vec4 xpos = 2.0 * vec4(fpos, 1.0) - 1.0;
2014-04-10 11:34:57 -04:00
xpos = InverseProjectionMatrix * xpos;
2014-03-02 18:47:13 -05:00
xpos.xyz /= xpos.w;
vec3 viewSampleDir = reflect(xpos.xyz, nor);
// Convert sampleDir in world space (where tex was generated)
2014-04-10 11:34:57 -04:00
vec4 sampleDir = transpose(InverseViewMatrix) * vec4(viewSampleDir, 0.);
vec4 detail0 = texture(tex, sampleDir.xyz);
2014-03-02 18:47:13 -05:00
FragColor = vec4(detail0.xyz, 1.);
}