118705f19a
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14737 178a84e3-b1eb-0310-8ba1-8eac791a3b58
44 lines
1.3 KiB
GLSL
44 lines
1.3 KiB
GLSL
#version 130
|
|
uniform sampler2D tex;
|
|
uniform float far;
|
|
uniform float objectid;
|
|
|
|
noperspective in vec3 eyenor;
|
|
noperspective in vec3 viewpos;
|
|
noperspective in vec3 nor;
|
|
|
|
const float near = 1.0;
|
|
|
|
vec4 encdepth(float v) {
|
|
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v;
|
|
enc = fract(enc);
|
|
enc -= enc.yzww * vec4(1.0/255.0, 1.0/255.0, 1.0/255.0, 0.0);
|
|
return enc;
|
|
}
|
|
|
|
void main() {
|
|
|
|
float linear_z = (2.0 * near) / (far + near - gl_FragCoord.z * (far - near));
|
|
|
|
// Tune for better inside range without losing outdoors
|
|
linear_z *= 2.0;
|
|
|
|
// 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
|
|
vec3 normal_x = normalize(vec3(eyenor.x, 0.0, eyenor.z));
|
|
float sin_theta_x = length(cross( forward, normal_x )) * eyenor.x/abs(eyenor.x);
|
|
|
|
// get the angle between the forward vector and the vertical portion of the normal
|
|
vec3 normal_y = normalize(vec3(0.0, eyenor.y, eyenor.z));
|
|
float sin_theta_y = length(cross( forward, normal_y )) * eyenor.y/abs(eyenor.y);
|
|
|
|
vec4 detail0 = texture2D(tex, vec2(0.5 + sin_theta_x*0.5, 0.5 + sin_theta_y*0.5));
|
|
|
|
gl_FragData[0] = detail0 * gl_Color;
|
|
|
|
gl_FragData[1] = vec4(nor, linear_z);
|
|
gl_FragData[2] = vec4(encdepth(gl_FragCoord.z).xyz, objectid);
|
|
}
|