SuperTuxKart 1.5 upstream source (from official release tarball)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
// Lambert model
|
||||
vec3 DiffuseBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// From "An Efficient Representation for Irradiance Environment Maps" article
|
||||
// See http://graphics.stanford.edu/papers/envmap/
|
||||
// Coefficients are calculated in IBL.cpp
|
||||
|
||||
mat4 getMatrix(float L00, float L1m1, float L10, float L11, float L2m2, float L2m1, float L20, float L21, float L22)
|
||||
{
|
||||
float c1 = 0.429043, c2 = 0.511664, c3 = 0.743125, c4 = 0.886227, c5 = 0.247708;
|
||||
|
||||
return mat4(
|
||||
c1 * L22, c1 * L2m2, c1 * L21, c2 * L11,
|
||||
c1 * L2m2, - c1 * L22, c1 * L2m1, c2 * L1m1,
|
||||
c1 * L21, c1 * L2m1, c3 * L20, c2 * L10,
|
||||
c2 * L11, c2 * L1m1, c2 * L10, c4 * L00 - c5 * L20
|
||||
);
|
||||
}
|
||||
|
||||
vec3 DiffuseIBL(vec3 normal)
|
||||
{
|
||||
// Convert normal in wobLd space (where SH coordinates were computed)
|
||||
vec4 extendednormal = vec4(normal, 0.);
|
||||
extendednormal.w = 1.;
|
||||
|
||||
#ifdef UBO_DISABLED
|
||||
mat4 rmat = getMatrix(redLmn[0], redLmn[1], redLmn[2], redLmn[3], redLmn[4], redLmn[5], redLmn[6], redLmn[7], redLmn[8]);
|
||||
mat4 gmat = getMatrix(greenLmn[0], greenLmn[1], greenLmn[2], greenLmn[3], greenLmn[4], greenLmn[5], greenLmn[6], greenLmn[7], greenLmn[8]);
|
||||
mat4 bmat = getMatrix(blueLmn[0], blueLmn[1], blueLmn[2], blueLmn[3], blueLmn[4], blueLmn[5], blueLmn[6], blueLmn[7], blueLmn[8]);
|
||||
#else
|
||||
mat4 rmat = getMatrix(rL00, rL1m1, rL10, rL11, rL2m2, rL2m1, rL20, rL21, rL22);
|
||||
mat4 gmat = getMatrix(gL00, gL1m1, gL10, gL11, gL2m2, gL2m1, gL20, gL21, gL22);
|
||||
mat4 bmat = getMatrix(bL00, bL1m1, bL10, bL11, bL2m2, bL2m1, bL20, bL21, bL22);
|
||||
#endif
|
||||
|
||||
float r = dot(extendednormal, rmat * extendednormal);
|
||||
float g = dot(extendednormal, gmat * extendednormal);
|
||||
float b = dot(extendednormal, bmat * extendednormal);
|
||||
|
||||
return max(vec3(r, g, b), vec3(0.));
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Blinn Phong with emulated fresnel factor
|
||||
vec3 SpecularBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness)
|
||||
{
|
||||
float exponentroughness = exp2(10. * roughness + 1.);
|
||||
// Half Light View direction
|
||||
vec3 H = normalize(eyedir + lightdir);
|
||||
float NdotH = clamp(dot(normal, H), 0., 1.);
|
||||
float normalisationFactor = (exponentroughness + 2.) / 8.;
|
||||
vec3 FresnelSchlick = color + (1.0f - color) * pow(1.0f - clamp(dot(eyedir, H), 0., 1.), 5.);
|
||||
return max(pow(NdotH, exponentroughness) * FresnelSchlick * normalisationFactor, vec3(0.));
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
uniform samplerCube probe;
|
||||
|
||||
vec3 SpecularIBL(vec3 normal, vec3 V, float roughness)
|
||||
{
|
||||
vec3 sampleDirection = reflect(-V, normal);
|
||||
sampleDirection = (u_inverse_view_matrix * vec4(sampleDirection, 0.)).xyz;
|
||||
|
||||
// Assume 8 level of lod (ie 256x256 texture)
|
||||
float lodval = 7. * (1. - roughness);
|
||||
return clamp(textureLod(probe, sampleDirection, lodval).rgb, 0., 1.);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Sun Most Representative Point (used for MRP area lighting method)
|
||||
// From "Frostbite going PBR" paper
|
||||
vec3 SunMRP(vec3 normal, vec3 eyedir)
|
||||
{
|
||||
vec3 local_sundir = normalize((transpose(u_inverse_view_matrix) * vec4(sundirection, 0.)).xyz);
|
||||
vec3 R = reflect(-eyedir, normal);
|
||||
float angularRadius = 3.14 * sun_angle / 180.;
|
||||
vec3 D = local_sundir;
|
||||
float d = cos(angularRadius);
|
||||
float r = sin(angularRadius);
|
||||
float DdotR = dot(D, R);
|
||||
vec3 S = R - DdotR * D;
|
||||
return (DdotR < d) ? normalize(d * D + normalize (S) * r) : R;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
vec3 DecodeNormal(vec2 n)
|
||||
{
|
||||
n = n * 2.0 - 1.0;
|
||||
vec3 ret = vec3(n.x, n.y, 1.0 - abs(n.x) - abs(n.y));
|
||||
float t = max(-ret.z, 0.0);
|
||||
ret.x += ret.x >= 0.0 ? -t : t;
|
||||
ret.y += ret.y >= 0.0 ? -t : t;
|
||||
return normalize(ret);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
vec2 getDisplaceShift(float horiz, float vert)
|
||||
{
|
||||
vec2 offset = vec2(horiz, vert);
|
||||
offset = 2.0 * offset - 1.0;
|
||||
|
||||
vec4 shiftval;
|
||||
shiftval.r = step(offset.x, 0.0) * -offset.x;
|
||||
shiftval.g = step(0.0, offset.x) * offset.x;
|
||||
shiftval.b = step(offset.y, 0.0) * -offset.y;
|
||||
shiftval.a = step(0.0, offset.y) * offset.y;
|
||||
|
||||
vec2 shift;
|
||||
shift.x = -shiftval.x + shiftval.y;
|
||||
shift.y = -shiftval.z + shiftval.w;
|
||||
return shift;
|
||||
}
|
||||
|
||||
ivec2 getDisplaceUV(vec2 shift, vec4 viewport, sampler2D displace_mask)
|
||||
{
|
||||
ivec2 uv = ivec2(gl_FragCoord.xy);
|
||||
shift *= 0.02 * viewport.zw;
|
||||
ivec2 lo = ivec2(viewport.xy);
|
||||
ivec2 hi = ivec2(viewport.xy + viewport.zw);
|
||||
ivec2 suv = clamp(ivec2(gl_FragCoord.xy) + ivec2(shift), lo, hi);
|
||||
vec2 new_mask = texelFetch(displace_mask, suv, 0).xy;
|
||||
if (!(new_mask.x == 0.0 && new_mask.y == 0.0))
|
||||
uv = suv;
|
||||
return uv;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Octahedron Normal Vector
|
||||
|
||||
vec2 OctWrap(vec2 v)
|
||||
{
|
||||
vec2 w = 1.0 - abs( v.yx );
|
||||
if (v.x < 0.0) w.x = -w.x;
|
||||
if (v.y < 0.0) w.y = -w.y;
|
||||
return w;
|
||||
}
|
||||
|
||||
vec2 EncodeNormal(vec3 n)
|
||||
{
|
||||
n /= (abs(n.x) + abs(n.y) + abs(n.z));
|
||||
n.xy = n.z >= 0.0 ? n.xy : OctWrap(n.xy);
|
||||
n.xy = n.xy * 0.5 + 0.5;
|
||||
return n.xy;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Using numerical value from here
|
||||
// http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering
|
||||
|
||||
vec3 getCIEYxy(vec3 rgbColor)
|
||||
{
|
||||
mat3 RGB2XYZ = transpose(mat3(
|
||||
vec3(.4125, .2126, .0193),
|
||||
vec3(.3576, .7152, .1192),
|
||||
vec3(.1805, .0722, .9505)));
|
||||
|
||||
vec3 xYz = RGB2XYZ * rgbColor;
|
||||
float tmp = max(xYz.x + xYz.y + xYz.z, 0.1);
|
||||
return vec3(xYz.y, xYz.xy / tmp);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 u_inverse_projection_matrix)
|
||||
{
|
||||
vec4 pos = 2.0 * vec4(uvDepth, 1.0) - 1.0;
|
||||
pos.xy *= vec2(u_inverse_projection_matrix[0][0], u_inverse_projection_matrix[1][1]);
|
||||
pos.zw = vec2(pos.z * u_inverse_projection_matrix[2][2] + pos.w, pos.z * u_inverse_projection_matrix[2][3] + pos.w);
|
||||
pos /= pos.w;
|
||||
return pos;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// Using numerical value from here
|
||||
// http://content.gpwiki.org/index.php/D3DBook:High-Dynamic_Range_Rendering
|
||||
|
||||
vec3 getRGBFromCIEXxy(vec3 YxyColor)
|
||||
{
|
||||
float Yovery = YxyColor.x / max(YxyColor.z, 0.1);
|
||||
vec3 XYZ = vec3(YxyColor.y * Yovery, YxyColor.x, (1. - YxyColor.y - YxyColor.z) * Yovery);
|
||||
|
||||
mat3 XYZ2RGB = transpose(mat3(
|
||||
vec3(3.2405, -.9693, .0556),
|
||||
vec3(-1.5371, 1.8760, -.2040),
|
||||
vec3(-.4985, .0416, 1.0572)));
|
||||
|
||||
vec3 RGBColor = XYZ2RGB * XYZ;
|
||||
return max(RGBColor, vec3(0.));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
vec3 rotateVector(vec4 quat, vec3 vec)
|
||||
{
|
||||
return vec + 2.0 * cross(cross(vec, quat.xyz) + quat.w * vec, quat.xyz);
|
||||
}
|
||||
|
||||
vec4 getWorldPosition(vec3 origin, vec4 rotation, vec3 scale, vec3 local_pos)
|
||||
{
|
||||
local_pos = local_pos * scale;
|
||||
local_pos = rotateVector(rotation, local_pos);
|
||||
local_pos = local_pos + origin;
|
||||
return vec4(local_pos, 1.0);
|
||||
}
|
||||
|
||||
vec4 convert10BitVector(vec4 orig)
|
||||
{
|
||||
vec4 ret;
|
||||
ret.x = orig.x * 0.00195694715;
|
||||
ret.y = orig.y * 0.00195694715;
|
||||
ret.z = orig.z * 0.00195694715;
|
||||
ret.w = max(orig.w, -1.0);
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
vec3 rgbToHsv(vec3 c)
|
||||
{
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
||||
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
||||
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
vec3 hsvToRgb(vec3 c)
|
||||
{
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
vec3 CalcCoordFromPosition(vec3 pos, mat4 projection_matrix,
|
||||
vec2 viewport_scale, vec2 viewport_offset)
|
||||
{
|
||||
vec4 projectedCoord = projection_matrix * vec4(pos, 1.0);
|
||||
projectedCoord.xyz /= projectedCoord.w;
|
||||
#if defined(VULKAN)
|
||||
projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5; // map X,Y from -1 -> +1 into 0 -> 1
|
||||
// no Z remap here because vulkan projection matrix already gave us Z in [0..1]
|
||||
#else
|
||||
projectedCoord.xyz = projectedCoord.xyz * 0.5 + 0.5;
|
||||
#endif
|
||||
// scale and offset by viewport
|
||||
projectedCoord.xy = projectedCoord.xy * viewport_scale + viewport_offset;
|
||||
return projectedCoord.xyz;
|
||||
}
|
||||
|
||||
// Fade out edges of screen buffer tex
|
||||
// 1 means full render tex, 0 means full IBL tex
|
||||
float GetEdgeFade(vec2 coords, vec2 viewport_scale, vec2 viewport_offset)
|
||||
{
|
||||
// transform coords to viewport space
|
||||
vec2 viewport_coords = (coords - viewport_offset) / viewport_scale;
|
||||
float gradL = smoothstep(0.0, 0.4, viewport_coords.x);
|
||||
float gradR = 1.0 - smoothstep(0.6, 1.0, viewport_coords.x);
|
||||
float gradT = smoothstep(0.0, 0.4, viewport_coords.y);
|
||||
float gradB = 1.0 - smoothstep(0.6, 1.0, viewport_coords.y);
|
||||
return min(min(gradL, gradR), min(gradT, gradB));
|
||||
}
|
||||
|
||||
vec2 RayCast(vec3 dir, vec3 hitCoord, mat4 projection_matrix,
|
||||
vec2 viewport_scale, vec2 viewport_offset, sampler2DShadow depth)
|
||||
{
|
||||
dir *= 0.5;
|
||||
hitCoord += dir;
|
||||
|
||||
vec3 projectedCoord = CalcCoordFromPosition(hitCoord, projection_matrix,
|
||||
viewport_scale, viewport_offset);
|
||||
float factor = 1.0;
|
||||
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
float direction = texture(depth, projectedCoord);
|
||||
factor *= direction;
|
||||
dir = dir * (0.5 + 0.5 * factor);
|
||||
hitCoord += dir * (2. * direction - 1.);
|
||||
projectedCoord = CalcCoordFromPosition(hitCoord, projection_matrix,
|
||||
viewport_scale, viewport_offset);
|
||||
}
|
||||
|
||||
return projectedCoord.xy;
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// Wrapper to allow easy sampling for material texture layers
|
||||
uniform sampler2D tex_layer_0;
|
||||
uniform sampler2D tex_layer_1;
|
||||
uniform sampler2D tex_layer_2;
|
||||
uniform sampler2D tex_layer_3;
|
||||
uniform sampler2D tex_layer_4;
|
||||
uniform sampler2D tex_layer_5;
|
||||
|
||||
#define HIGH_SAMPLING 4.0
|
||||
#define MEDIUM_SAMPLING 2.0
|
||||
#define LOW_SAMPLING 1.0
|
||||
|
||||
vec4 sampleTextureLayer0(vec2 uv)
|
||||
{
|
||||
return texture(tex_layer_0, uv);
|
||||
}
|
||||
|
||||
vec4 multi_sampleTextureLayer0(vec2 uv, float distance)
|
||||
{
|
||||
|
||||
vec4 l_col = sampleTextureLayer0(uv * LOW_SAMPLING);
|
||||
vec4 m_col = sampleTextureLayer0(uv * MEDIUM_SAMPLING);
|
||||
vec4 h_col = sampleTextureLayer0(uv * HIGH_SAMPLING);
|
||||
|
||||
/* debug
|
||||
l_col = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
m_col = vec4(0.0, 1.0, 0.0, 1.0);
|
||||
h_col = vec4(0.0, 0.0, 1.0, 1.0);*/
|
||||
|
||||
// From Low to medium
|
||||
float factor = distance * 0.02;
|
||||
factor = pow(factor, 2.5);
|
||||
factor = clamp(factor, 0.0, 1.0);
|
||||
vec4 f_col = mix(m_col, l_col, factor);
|
||||
|
||||
// From medium to high
|
||||
factor = distance * 0.1;
|
||||
factor = pow(factor, 2.5);
|
||||
factor = clamp(factor, 0.0, 1.0);
|
||||
|
||||
f_col = mix(h_col, f_col, factor);
|
||||
|
||||
return f_col;
|
||||
}
|
||||
|
||||
vec4 sampleTextureLayer1(vec2 uv)
|
||||
{
|
||||
return texture(tex_layer_1, uv);
|
||||
}
|
||||
|
||||
vec4 sampleTextureLayer2(vec2 uv)
|
||||
{
|
||||
return texture(tex_layer_2, uv);
|
||||
}
|
||||
|
||||
vec4 multi_sampleTextureLayer2(vec2 uv, float distance)
|
||||
{
|
||||
|
||||
vec4 l_col = sampleTextureLayer2(uv * LOW_SAMPLING);
|
||||
vec4 m_col = sampleTextureLayer2(uv * MEDIUM_SAMPLING);
|
||||
vec4 h_col = sampleTextureLayer2(uv * HIGH_SAMPLING);
|
||||
|
||||
// From Low to medium
|
||||
float factor = distance * 0.02;
|
||||
factor = pow(factor, 2.5);
|
||||
factor = clamp(factor, 0.0, 1.0);
|
||||
vec4 f_col = mix(m_col, l_col, factor);
|
||||
|
||||
// From medium to high
|
||||
factor = distance * 0.1;
|
||||
factor = pow(factor, 2.5);
|
||||
factor = clamp(factor, 0.0, 1.0);
|
||||
|
||||
f_col = mix(h_col, f_col, factor);
|
||||
|
||||
return f_col;
|
||||
}
|
||||
|
||||
vec4 sampleTextureLayer3(vec2 uv)
|
||||
{
|
||||
return texture(tex_layer_3, uv);
|
||||
}
|
||||
|
||||
vec4 multi_sampleTextureLayer3(vec2 uv, float distance)
|
||||
{
|
||||
|
||||
vec4 l_col = sampleTextureLayer3(uv * LOW_SAMPLING);
|
||||
vec4 m_col = sampleTextureLayer3(uv * MEDIUM_SAMPLING);
|
||||
vec4 h_col = sampleTextureLayer3(uv * HIGH_SAMPLING);
|
||||
|
||||
// From Low to medium
|
||||
float factor = distance * 0.02;
|
||||
factor = pow(factor, 2.5);
|
||||
factor = clamp(factor, 0.0, 1.0);
|
||||
vec4 f_col = mix(m_col, l_col, factor);
|
||||
|
||||
// From medium to high
|
||||
factor = distance * 0.1;
|
||||
factor = pow(factor, 2.5);
|
||||
factor = clamp(factor, 0.0, 1.0);
|
||||
|
||||
f_col = mix(h_col, f_col, factor);
|
||||
|
||||
return f_col;
|
||||
}
|
||||
|
||||
vec4 sampleTextureLayer4(vec2 uv)
|
||||
{
|
||||
return texture(tex_layer_4, uv);
|
||||
}
|
||||
|
||||
vec4 multi_sampleTextureLayer4(vec2 uv, float distance)
|
||||
{
|
||||
|
||||
vec4 l_col = sampleTextureLayer4(uv * LOW_SAMPLING);
|
||||
vec4 m_col = sampleTextureLayer4(uv * MEDIUM_SAMPLING);
|
||||
vec4 h_col = sampleTextureLayer4(uv * HIGH_SAMPLING);
|
||||
|
||||
// From Low to medium
|
||||
float factor = distance * 0.02;
|
||||
factor = pow(factor, 2.5);
|
||||
factor = clamp(factor, 0.0, 1.0);
|
||||
vec4 f_col = mix(m_col, l_col, factor);
|
||||
|
||||
// From medium to high
|
||||
factor = distance * 0.1;
|
||||
factor = pow(factor, 2.5);
|
||||
factor = clamp(factor, 0.0, 1.0);
|
||||
|
||||
f_col = mix(h_col, f_col, factor);
|
||||
|
||||
return f_col;
|
||||
}
|
||||
|
||||
vec4 sampleTextureLayer5(vec2 uv)
|
||||
{
|
||||
return texture(tex_layer_5, uv);
|
||||
}
|
||||
Reference in New Issue
Block a user