|
@@ -6,13 +6,13 @@
|
|
|
#ifndef ANKI_SHADERS_FUNCTIONS_GLSL
|
|
#ifndef ANKI_SHADERS_FUNCTIONS_GLSL
|
|
|
#define ANKI_SHADERS_FUNCTIONS_GLSL
|
|
#define ANKI_SHADERS_FUNCTIONS_GLSL
|
|
|
|
|
|
|
|
-#include "shaders/Common.glsl"
|
|
|
|
|
|
|
+#include <shaders/Common.glsl>
|
|
|
|
|
|
|
|
#if defined(ANKI_FRAGMENT_SHADER)
|
|
#if defined(ANKI_FRAGMENT_SHADER)
|
|
|
-vec3 dither(in vec3 col, in float C)
|
|
|
|
|
|
|
+Vec3 dither(in Vec3 col, in F32 C)
|
|
|
{
|
|
{
|
|
|
- vec3 vDither = vec3(dot(vec2(171.0, 231.0), gl_FragCoord.xy));
|
|
|
|
|
- vDither.rgb = fract(vDither.rgb / vec3(103.0, 71.0, 97.0));
|
|
|
|
|
|
|
+ Vec3 vDither = Vec3(dot(Vec2(171.0, 231.0), gl_FragCoord.xy));
|
|
|
|
|
+ vDither.rgb = fract(vDither.rgb / Vec3(103.0, 71.0, 97.0));
|
|
|
|
|
|
|
|
col = col * (255.0 / C) + vDither.rgb;
|
|
col = col * (255.0 / C) + vDither.rgb;
|
|
|
col = floor(col) / 255.0;
|
|
col = floor(col) / 255.0;
|
|
@@ -21,9 +21,9 @@ vec3 dither(in vec3 col, in float C)
|
|
|
return col;
|
|
return col;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-float dither(in float col, in float C)
|
|
|
|
|
|
|
+F32 dither(in F32 col, in F32 C)
|
|
|
{
|
|
{
|
|
|
- float vDither = dot(vec2(171.0, 231.0), gl_FragCoord.xy);
|
|
|
|
|
|
|
+ F32 vDither = dot(Vec2(171.0, 231.0), gl_FragCoord.xy);
|
|
|
vDither = fract(vDither / 103.0);
|
|
vDither = fract(vDither / 103.0);
|
|
|
|
|
|
|
|
col = col * (255.0 / C) + vDither;
|
|
col = col * (255.0 / C) + vDither;
|
|
@@ -35,21 +35,21 @@ float dither(in float col, in float C)
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
// Convert to linear depth
|
|
// Convert to linear depth
|
|
|
-float linearizeDepth(in float depth, in float zNear, in float zFar)
|
|
|
|
|
|
|
+F32 linearizeDepth(in F32 depth, in F32 zNear, in F32 zFar)
|
|
|
{
|
|
{
|
|
|
return zNear / ((zNear - zFar) + zFar / depth);
|
|
return zNear / ((zNear - zFar) + zFar / depth);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// This is the optimal linearizeDepth where a=(n-f)/n and b=f/n
|
|
// This is the optimal linearizeDepth where a=(n-f)/n and b=f/n
|
|
|
-float linearizeDepthOptimal(in float depth, in float a, in float b)
|
|
|
|
|
|
|
+F32 linearizeDepthOptimal(in F32 depth, in F32 a, in F32 b)
|
|
|
{
|
|
{
|
|
|
return 1.0 / (a + b / depth);
|
|
return 1.0 / (a + b / depth);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Project a vector by knowing only the non zero values of a perspective matrix
|
|
// Project a vector by knowing only the non zero values of a perspective matrix
|
|
|
-vec4 projectPerspective(in vec4 vec, in float m00, in float m11, in float m22, in float m23)
|
|
|
|
|
|
|
+Vec4 projectPerspective(in Vec4 vec, in F32 m00, in F32 m11, in F32 m22, in F32 m23)
|
|
|
{
|
|
{
|
|
|
- vec4 o;
|
|
|
|
|
|
|
+ Vec4 o;
|
|
|
o.x = vec.x * m00;
|
|
o.x = vec.x * m00;
|
|
|
o.y = vec.y * m11;
|
|
o.y = vec.y * m11;
|
|
|
o.z = vec.z * m22 + vec.w * m23;
|
|
o.z = vec.z * m22 + vec.w * m23;
|
|
@@ -58,14 +58,14 @@ vec4 projectPerspective(in vec4 vec, in float m00, in float m11, in float m22, i
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Stolen from shadertoy.com/view/4tyGDD
|
|
// Stolen from shadertoy.com/view/4tyGDD
|
|
|
-vec4 textureCatmullRom4Samples(sampler2D tex, vec2 uv, vec2 texSize)
|
|
|
|
|
|
|
+Vec4 textureCatmullRom4Samples(sampler2D tex, Vec2 uv, Vec2 texSize)
|
|
|
{
|
|
{
|
|
|
- vec2 halff = 2.0 * fract(0.5 * uv * texSize - 0.25) - 1.0;
|
|
|
|
|
- vec2 f = fract(halff);
|
|
|
|
|
- vec2 sum0 = (2.0 * f - 3.5) * f + 0.5;
|
|
|
|
|
- vec2 sum1 = (2.0 * f - 2.5) * f - 0.5;
|
|
|
|
|
- vec4 w = vec4(f * sum0 + 1.0, f * sum1);
|
|
|
|
|
- vec4 pos = vec4((((-2.0 * f + 3.0) * f + 0.5) * f - 1.5) * f / (w.xy * texSize) + uv,
|
|
|
|
|
|
|
+ Vec2 halff = 2.0 * fract(0.5 * uv * texSize - 0.25) - 1.0;
|
|
|
|
|
+ Vec2 f = fract(halff);
|
|
|
|
|
+ Vec2 sum0 = (2.0 * f - 3.5) * f + 0.5;
|
|
|
|
|
+ Vec2 sum1 = (2.0 * f - 2.5) * f - 0.5;
|
|
|
|
|
+ Vec4 w = Vec4(f * sum0 + 1.0, f * sum1);
|
|
|
|
|
+ Vec4 pos = Vec4((((-2.0 * f + 3.0) * f + 0.5) * f - 1.5) * f / (w.xy * texSize) + uv,
|
|
|
(((-2.0 * f + 5.0) * f - 2.5) * f - 0.5) / (sum1 * texSize) + uv);
|
|
(((-2.0 * f + 5.0) * f - 2.5) * f - 0.5) / (sum1 * texSize) + uv);
|
|
|
w.xz *= halff.x * halff.y > 0.0 ? 1.0 : -1.0;
|
|
w.xz *= halff.x * halff.y > 0.0 ? 1.0 : -1.0;
|
|
|
|
|
|
|
@@ -73,19 +73,19 @@ vec4 textureCatmullRom4Samples(sampler2D tex, vec2 uv, vec2 texSize)
|
|
|
+ (texture(tex, pos.xw) * w.x + texture(tex, pos.zw) * w.z) * w.w;
|
|
+ (texture(tex, pos.xw) * w.x + texture(tex, pos.zw) * w.z) * w.w;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-float rand(vec2 n)
|
|
|
|
|
|
|
+F32 rand(Vec2 n)
|
|
|
{
|
|
{
|
|
|
- return 0.5 + 0.5 * fract(sin(dot(n, vec2(12.9898, 78.233))) * 43758.5453);
|
|
|
|
|
|
|
+ return 0.5 + 0.5 * fract(sin(dot(n, Vec2(12.9898, 78.233))) * 43758.5453);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-vec3 nearestDepthUpscale(vec2 uv, sampler2D depthFull, sampler2D depthHalf, sampler2D colorTex, float depthThreshold)
|
|
|
|
|
|
|
+Vec3 nearestDepthUpscale(Vec2 uv, sampler2D depthFull, sampler2D depthHalf, sampler2D colorTex, F32 depthThreshold)
|
|
|
{
|
|
{
|
|
|
- float fullDepth = texture(depthFull, uv).r;
|
|
|
|
|
- vec4 halfDepths = textureGather(depthHalf, uv, 0);
|
|
|
|
|
- vec4 diffs = abs(vec4(fullDepth) - halfDepths);
|
|
|
|
|
- vec3 color;
|
|
|
|
|
|
|
+ F32 fullDepth = texture(depthFull, uv).r;
|
|
|
|
|
+ Vec4 halfDepths = textureGather(depthHalf, uv, 0);
|
|
|
|
|
+ Vec4 diffs = abs(Vec4(fullDepth) - halfDepths);
|
|
|
|
|
+ Vec3 color;
|
|
|
|
|
|
|
|
- if(all(lessThan(diffs, vec4(depthThreshold))))
|
|
|
|
|
|
|
+ if(all(lessThan(diffs, Vec4(depthThreshold))))
|
|
|
{
|
|
{
|
|
|
// No major discontinuites, sample with bilinear
|
|
// No major discontinuites, sample with bilinear
|
|
|
color = texture(colorTex, uv).rgb;
|
|
color = texture(colorTex, uv).rgb;
|
|
@@ -93,12 +93,12 @@ vec3 nearestDepthUpscale(vec2 uv, sampler2D depthFull, sampler2D depthHalf, samp
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
// Some discontinuites, need to use the newUv
|
|
// Some discontinuites, need to use the newUv
|
|
|
- vec4 r = textureGather(colorTex, uv, 0);
|
|
|
|
|
- vec4 g = textureGather(colorTex, uv, 1);
|
|
|
|
|
- vec4 b = textureGather(colorTex, uv, 2);
|
|
|
|
|
|
|
+ Vec4 r = textureGather(colorTex, uv, 0);
|
|
|
|
|
+ Vec4 g = textureGather(colorTex, uv, 1);
|
|
|
|
|
+ Vec4 b = textureGather(colorTex, uv, 2);
|
|
|
|
|
|
|
|
- float minDiff = diffs.x;
|
|
|
|
|
- uint comp = 0;
|
|
|
|
|
|
|
+ F32 minDiff = diffs.x;
|
|
|
|
|
+ U32 comp = 0;
|
|
|
|
|
|
|
|
if(diffs.y < minDiff)
|
|
if(diffs.y < minDiff)
|
|
|
{
|
|
{
|
|
@@ -117,184 +117,184 @@ vec3 nearestDepthUpscale(vec2 uv, sampler2D depthFull, sampler2D depthHalf, samp
|
|
|
comp = 3;
|
|
comp = 3;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- color = vec3(r[comp], g[comp], b[comp]);
|
|
|
|
|
|
|
+ color = Vec3(r[comp], g[comp], b[comp]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return color;
|
|
return color;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-float _calcDepthWeight(sampler2D depthLow, vec2 uv, float ref, vec2 linearDepthCf)
|
|
|
|
|
|
|
+F32 _calcDepthWeight(sampler2D depthLow, Vec2 uv, F32 ref, Vec2 linearDepthCf)
|
|
|
{
|
|
{
|
|
|
- float d = texture(depthLow, uv).r;
|
|
|
|
|
- float linearD = linearizeDepthOptimal(d, linearDepthCf.x, linearDepthCf.y);
|
|
|
|
|
|
|
+ F32 d = texture(depthLow, uv).r;
|
|
|
|
|
+ F32 linearD = linearizeDepthOptimal(d, linearDepthCf.x, linearDepthCf.y);
|
|
|
return 1.0 / (EPSILON + abs(ref - linearD));
|
|
return 1.0 / (EPSILON + abs(ref - linearD));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-vec4 _sampleAndWeight(sampler2D depthLow,
|
|
|
|
|
|
|
+Vec4 _sampleAndWeight(sampler2D depthLow,
|
|
|
sampler2D colorLow,
|
|
sampler2D colorLow,
|
|
|
- vec2 lowInvSize,
|
|
|
|
|
- vec2 uv,
|
|
|
|
|
- vec2 offset,
|
|
|
|
|
- float ref,
|
|
|
|
|
- float weight,
|
|
|
|
|
- vec2 linearDepthCf,
|
|
|
|
|
- inout float normalize)
|
|
|
|
|
|
|
+ Vec2 lowInvSize,
|
|
|
|
|
+ Vec2 uv,
|
|
|
|
|
+ Vec2 offset,
|
|
|
|
|
+ F32 ref,
|
|
|
|
|
+ F32 weight,
|
|
|
|
|
+ Vec2 linearDepthCf,
|
|
|
|
|
+ inout F32 normalize)
|
|
|
{
|
|
{
|
|
|
uv += offset * lowInvSize;
|
|
uv += offset * lowInvSize;
|
|
|
- float dw = _calcDepthWeight(depthLow, uv, ref, linearDepthCf);
|
|
|
|
|
- vec4 v = texture(colorLow, uv);
|
|
|
|
|
|
|
+ F32 dw = _calcDepthWeight(depthLow, uv, ref, linearDepthCf);
|
|
|
|
|
+ Vec4 v = texture(colorLow, uv);
|
|
|
normalize += weight * dw;
|
|
normalize += weight * dw;
|
|
|
return v * dw * weight;
|
|
return v * dw * weight;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-vec4 bilateralUpsample(
|
|
|
|
|
- sampler2D depthHigh, sampler2D depthLow, sampler2D colorLow, vec2 lowInvSize, vec2 uv, vec2 linearDepthCf)
|
|
|
|
|
|
|
+Vec4 bilateralUpsample(
|
|
|
|
|
+ sampler2D depthHigh, sampler2D depthLow, sampler2D colorLow, Vec2 lowInvSize, Vec2 uv, Vec2 linearDepthCf)
|
|
|
{
|
|
{
|
|
|
- const vec3 WEIGHTS = vec3(0.25, 0.125, 0.0625);
|
|
|
|
|
- float depthRef = linearizeDepthOptimal(texture(depthHigh, uv).r, linearDepthCf.x, linearDepthCf.y);
|
|
|
|
|
- float normalize = 0.0;
|
|
|
|
|
|
|
+ const Vec3 WEIGHTS = Vec3(0.25, 0.125, 0.0625);
|
|
|
|
|
+ F32 depthRef = linearizeDepthOptimal(texture(depthHigh, uv).r, linearDepthCf.x, linearDepthCf.y);
|
|
|
|
|
+ F32 normalize = 0.0;
|
|
|
|
|
|
|
|
- vec4 sum = _sampleAndWeight(
|
|
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(0.0, 0.0), depthRef, WEIGHTS.x, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ Vec4 sum = _sampleAndWeight(
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(0.0, 0.0), depthRef, WEIGHTS.x, linearDepthCf, normalize);
|
|
|
sum += _sampleAndWeight(
|
|
sum += _sampleAndWeight(
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(-1.0, 0.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(-1.0, 0.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
|
|
|
sum += _sampleAndWeight(
|
|
sum += _sampleAndWeight(
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(0.0, -1.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(0.0, -1.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
|
|
|
sum += _sampleAndWeight(
|
|
sum += _sampleAndWeight(
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(1.0, 0.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(1.0, 0.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
|
|
|
sum += _sampleAndWeight(
|
|
sum += _sampleAndWeight(
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(0.0, 1.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(0.0, 1.0), depthRef, WEIGHTS.y, linearDepthCf, normalize);
|
|
|
sum += _sampleAndWeight(
|
|
sum += _sampleAndWeight(
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(1.0, 1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(1.0, 1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
|
|
|
sum += _sampleAndWeight(
|
|
sum += _sampleAndWeight(
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(1.0, -1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(1.0, -1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
|
|
|
sum += _sampleAndWeight(
|
|
sum += _sampleAndWeight(
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(-1.0, 1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(-1.0, 1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
|
|
|
sum += _sampleAndWeight(
|
|
sum += _sampleAndWeight(
|
|
|
- depthLow, colorLow, lowInvSize, uv, vec2(-1.0, -1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
|
|
|
|
|
|
|
+ depthLow, colorLow, lowInvSize, uv, Vec2(-1.0, -1.0), depthRef, WEIGHTS.z, linearDepthCf, normalize);
|
|
|
|
|
|
|
|
return sum / normalize;
|
|
return sum / normalize;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-vec3 getCubemapDirection(vec2 norm, uint faceIdx)
|
|
|
|
|
|
|
+Vec3 getCubemapDirection(Vec2 norm, U32 faceIdx)
|
|
|
{
|
|
{
|
|
|
- vec3 zDir = vec3((faceIdx <= 1u) ? 1 : 0, (faceIdx & 2u) >> 1u, (faceIdx & 4u) >> 2u);
|
|
|
|
|
|
|
+ Vec3 zDir = Vec3((faceIdx <= 1u) ? 1 : 0, (faceIdx & 2u) >> 1u, (faceIdx & 4u) >> 2u);
|
|
|
zDir *= (((faceIdx & 1u) == 1u) ? -1.0 : 1.0);
|
|
zDir *= (((faceIdx & 1u) == 1u) ? -1.0 : 1.0);
|
|
|
- vec3 yDir = (faceIdx == 2u) ? vec3(0.0, 0.0, 1.0) : (faceIdx == 3u) ? vec3(0.0, 0.0, -1.0) : vec3(0.0, -1.0, 0.0);
|
|
|
|
|
- vec3 xDir = cross(zDir, yDir);
|
|
|
|
|
|
|
+ Vec3 yDir = (faceIdx == 2u) ? Vec3(0.0, 0.0, 1.0) : (faceIdx == 3u) ? Vec3(0.0, 0.0, -1.0) : Vec3(0.0, -1.0, 0.0);
|
|
|
|
|
+ Vec3 xDir = cross(zDir, yDir);
|
|
|
return normalize(norm.x * xDir + norm.y * yDir + zDir);
|
|
return normalize(norm.x * xDir + norm.y * yDir + zDir);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Convert 3D cubemap coordinates to 2D plus face index. v doesn't need to be normalized.
|
|
// Convert 3D cubemap coordinates to 2D plus face index. v doesn't need to be normalized.
|
|
|
-vec2 convertCubeUvs(vec3 v, out float faceIndex)
|
|
|
|
|
|
|
+Vec2 convertCubeUvs(Vec3 v, out F32 faceIndex)
|
|
|
{
|
|
{
|
|
|
- vec3 absV = abs(v);
|
|
|
|
|
- float mag;
|
|
|
|
|
- vec2 uv;
|
|
|
|
|
|
|
+ Vec3 absV = abs(v);
|
|
|
|
|
+ F32 mag;
|
|
|
|
|
+ Vec2 uv;
|
|
|
|
|
|
|
|
if(all(greaterThanEqual(absV.zz, absV.xy)))
|
|
if(all(greaterThanEqual(absV.zz, absV.xy)))
|
|
|
{
|
|
{
|
|
|
faceIndex = (v.z < 0.0) ? 5.0 : 4.0;
|
|
faceIndex = (v.z < 0.0) ? 5.0 : 4.0;
|
|
|
- uv = vec2((v.z < 0.0) ? -v.x : v.x, -v.y);
|
|
|
|
|
|
|
+ uv = Vec2((v.z < 0.0) ? -v.x : v.x, -v.y);
|
|
|
mag = absV.z;
|
|
mag = absV.z;
|
|
|
}
|
|
}
|
|
|
else if(absV.y >= absV.x)
|
|
else if(absV.y >= absV.x)
|
|
|
{
|
|
{
|
|
|
faceIndex = (v.y < 0.0) ? 3.0 : 2.0;
|
|
faceIndex = (v.y < 0.0) ? 3.0 : 2.0;
|
|
|
- uv = vec2(v.x, (v.y < 0.0) ? -v.z : v.z);
|
|
|
|
|
|
|
+ uv = Vec2(v.x, (v.y < 0.0) ? -v.z : v.z);
|
|
|
mag = absV.y;
|
|
mag = absV.y;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
faceIndex = (v.x < 0.0) ? 1.0 : 0.0;
|
|
faceIndex = (v.x < 0.0) ? 1.0 : 0.0;
|
|
|
- uv = vec2((v.x < 0.0) ? v.z : -v.z, -v.y);
|
|
|
|
|
|
|
+ uv = Vec2((v.x < 0.0) ? v.z : -v.z, -v.y);
|
|
|
mag = absV.x;
|
|
mag = absV.x;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return 0.5 / mag * uv + 0.5;
|
|
return 0.5 / mag * uv + 0.5;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Same as convertCubeUvs but it returns the faceIndex as unsigned int.
|
|
|
|
|
-vec2 convertCubeUvsu(vec3 v, out uint faceIndex)
|
|
|
|
|
|
|
+// Same as convertCubeUvs but it returns the faceIndex as unsigned I32.
|
|
|
|
|
+Vec2 convertCubeUvsu(Vec3 v, out U32 faceIndex)
|
|
|
{
|
|
{
|
|
|
- vec3 absV = abs(v);
|
|
|
|
|
- float mag;
|
|
|
|
|
- vec2 uv;
|
|
|
|
|
|
|
+ Vec3 absV = abs(v);
|
|
|
|
|
+ F32 mag;
|
|
|
|
|
+ Vec2 uv;
|
|
|
|
|
|
|
|
if(all(greaterThanEqual(absV.zz, absV.xy)))
|
|
if(all(greaterThanEqual(absV.zz, absV.xy)))
|
|
|
{
|
|
{
|
|
|
faceIndex = (v.z < 0.0) ? 5u : 4u;
|
|
faceIndex = (v.z < 0.0) ? 5u : 4u;
|
|
|
- uv = vec2((v.z < 0.0) ? -v.x : v.x, -v.y);
|
|
|
|
|
|
|
+ uv = Vec2((v.z < 0.0) ? -v.x : v.x, -v.y);
|
|
|
mag = absV.z;
|
|
mag = absV.z;
|
|
|
}
|
|
}
|
|
|
else if(absV.y >= absV.x)
|
|
else if(absV.y >= absV.x)
|
|
|
{
|
|
{
|
|
|
faceIndex = (v.y < 0.0) ? 3u : 2u;
|
|
faceIndex = (v.y < 0.0) ? 3u : 2u;
|
|
|
- uv = vec2(v.x, (v.y < 0.0) ? -v.z : v.z);
|
|
|
|
|
|
|
+ uv = Vec2(v.x, (v.y < 0.0) ? -v.z : v.z);
|
|
|
mag = absV.y;
|
|
mag = absV.y;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
faceIndex = (v.x < 0.0) ? 1u : 0u;
|
|
faceIndex = (v.x < 0.0) ? 1u : 0u;
|
|
|
- uv = vec2((v.x < 0.0) ? v.z : -v.z, -v.y);
|
|
|
|
|
|
|
+ uv = Vec2((v.x < 0.0) ? v.z : -v.z, -v.y);
|
|
|
mag = absV.x;
|
|
mag = absV.x;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return 0.5 / mag * uv + 0.5;
|
|
return 0.5 / mag * uv + 0.5;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-vec3 grayScale(vec3 col)
|
|
|
|
|
|
|
+Vec3 grayScale(Vec3 col)
|
|
|
{
|
|
{
|
|
|
- float grey = (col.r + col.g + col.b) * (1.0 / 3.0);
|
|
|
|
|
- return vec3(grey);
|
|
|
|
|
|
|
+ F32 grey = (col.r + col.g + col.b) * (1.0 / 3.0);
|
|
|
|
|
+ return Vec3(grey);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-vec3 saturateColor(vec3 col, float factor)
|
|
|
|
|
|
|
+Vec3 saturateColor(Vec3 col, F32 factor)
|
|
|
{
|
|
{
|
|
|
- const vec3 LUM_COEFF = vec3(0.2125, 0.7154, 0.0721);
|
|
|
|
|
- vec3 intensity = vec3(dot(col, LUM_COEFF));
|
|
|
|
|
|
|
+ const Vec3 LUM_COEFF = Vec3(0.2125, 0.7154, 0.0721);
|
|
|
|
|
+ Vec3 intensity = Vec3(dot(col, LUM_COEFF));
|
|
|
return mix(intensity, col, factor);
|
|
return mix(intensity, col, factor);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-vec3 gammaCorrection(vec3 gamma, vec3 col)
|
|
|
|
|
|
|
+Vec3 gammaCorrection(Vec3 gamma, Vec3 col)
|
|
|
{
|
|
{
|
|
|
return pow(col, 1.0 / gamma);
|
|
return pow(col, 1.0 / gamma);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Can use 0.15 for sharpenFactor
|
|
// Can use 0.15 for sharpenFactor
|
|
|
-vec3 readSharpen(sampler2D tex, vec2 uv, float sharpenFactor, bool detailed)
|
|
|
|
|
|
|
+Vec3 readSharpen(sampler2D tex, Vec2 uv, F32 sharpenFactor, bool detailed)
|
|
|
{
|
|
{
|
|
|
- vec3 col = textureLod(tex, uv, 0.0).rgb;
|
|
|
|
|
|
|
+ Vec3 col = textureLod(tex, uv, 0.0).rgb;
|
|
|
|
|
|
|
|
- vec3 col2 = textureLodOffset(tex, uv, 0.0, ivec2(1, 1)).rgb;
|
|
|
|
|
- col2 += textureLodOffset(tex, uv, 0.0, ivec2(-1, -1)).rgb;
|
|
|
|
|
- col2 += textureLodOffset(tex, uv, 0.0, ivec2(1, -1)).rgb;
|
|
|
|
|
- col2 += textureLodOffset(tex, uv, 0.0, ivec2(-1, 1)).rgb;
|
|
|
|
|
|
|
+ Vec3 col2 = textureLodOffset(tex, uv, 0.0, IVec2(1, 1)).rgb;
|
|
|
|
|
+ col2 += textureLodOffset(tex, uv, 0.0, IVec2(-1, -1)).rgb;
|
|
|
|
|
+ col2 += textureLodOffset(tex, uv, 0.0, IVec2(1, -1)).rgb;
|
|
|
|
|
+ col2 += textureLodOffset(tex, uv, 0.0, IVec2(-1, 1)).rgb;
|
|
|
|
|
|
|
|
- float f = 4.0;
|
|
|
|
|
|
|
+ F32 f = 4.0;
|
|
|
if(detailed)
|
|
if(detailed)
|
|
|
{
|
|
{
|
|
|
- col2 += textureLodOffset(tex, uv, 0.0, ivec2(0, 1)).rgb;
|
|
|
|
|
- col2 += textureLodOffset(tex, uv, 0.0, ivec2(1, 0)).rgb;
|
|
|
|
|
- col2 += textureLodOffset(tex, uv, 0.0, ivec2(-1, 0)).rgb;
|
|
|
|
|
- col2 += textureLodOffset(tex, uv, 0.0, ivec2(0, -1)).rgb;
|
|
|
|
|
|
|
+ col2 += textureLodOffset(tex, uv, 0.0, IVec2(0, 1)).rgb;
|
|
|
|
|
+ col2 += textureLodOffset(tex, uv, 0.0, IVec2(1, 0)).rgb;
|
|
|
|
|
+ col2 += textureLodOffset(tex, uv, 0.0, IVec2(-1, 0)).rgb;
|
|
|
|
|
+ col2 += textureLodOffset(tex, uv, 0.0, IVec2(0, -1)).rgb;
|
|
|
|
|
|
|
|
f = 8.0;
|
|
f = 8.0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
col = col * (f * sharpenFactor + 1.0) - sharpenFactor * col2;
|
|
col = col * (f * sharpenFactor + 1.0) - sharpenFactor * col2;
|
|
|
- return max(vec3(0.0), col);
|
|
|
|
|
|
|
+ return max(Vec3(0.0), col);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-vec3 readErosion(sampler2D tex, vec2 uv)
|
|
|
|
|
|
|
+Vec3 readErosion(sampler2D tex, Vec2 uv)
|
|
|
{
|
|
{
|
|
|
- vec3 minValue = textureLod(tex, uv, 0.0).rgb;
|
|
|
|
|
|
|
+ Vec3 minValue = textureLod(tex, uv, 0.0).rgb;
|
|
|
|
|
|
|
|
#define ANKI_EROSION(x, y) \
|
|
#define ANKI_EROSION(x, y) \
|
|
|
- col2 = textureLodOffset(tex, uv, 0.0, ivec2(x, y)).rgb; \
|
|
|
|
|
|
|
+ col2 = textureLodOffset(tex, uv, 0.0, IVec2(x, y)).rgb; \
|
|
|
minValue = min(col2, minValue);
|
|
minValue = min(col2, minValue);
|
|
|
|
|
|
|
|
- vec3 col2;
|
|
|
|
|
|
|
+ Vec3 col2;
|
|
|
ANKI_EROSION(1, 1);
|
|
ANKI_EROSION(1, 1);
|
|
|
ANKI_EROSION(-1, -1);
|
|
ANKI_EROSION(-1, -1);
|
|
|
ANKI_EROSION(1, -1);
|
|
ANKI_EROSION(1, -1);
|
|
@@ -310,30 +310,30 @@ vec3 readErosion(sampler2D tex, vec2 uv)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 5 color heatmap from a factor.
|
|
// 5 color heatmap from a factor.
|
|
|
-vec3 heatmap(float factor)
|
|
|
|
|
|
|
+Vec3 heatmap(F32 factor)
|
|
|
{
|
|
{
|
|
|
- float intPart;
|
|
|
|
|
- float fractional = modf(factor * 4.0, intPart);
|
|
|
|
|
|
|
+ F32 intPart;
|
|
|
|
|
+ F32 fractional = modf(factor * 4.0, intPart);
|
|
|
|
|
|
|
|
if(intPart < 1.0)
|
|
if(intPart < 1.0)
|
|
|
{
|
|
{
|
|
|
- return mix(vec3(0.0, 0.0, 0.0), vec3(0.0, 0.0, 1.0), fractional);
|
|
|
|
|
|
|
+ return mix(Vec3(0.0, 0.0, 0.0), Vec3(0.0, 0.0, 1.0), fractional);
|
|
|
}
|
|
}
|
|
|
else if(intPart < 2.0)
|
|
else if(intPart < 2.0)
|
|
|
{
|
|
{
|
|
|
- return mix(vec3(0.0, 0.0, 1.0), vec3(0.0, 1.0, 0.0), fractional);
|
|
|
|
|
|
|
+ return mix(Vec3(0.0, 0.0, 1.0), Vec3(0.0, 1.0, 0.0), fractional);
|
|
|
}
|
|
}
|
|
|
else if(intPart < 3.0)
|
|
else if(intPart < 3.0)
|
|
|
{
|
|
{
|
|
|
- return mix(vec3(0.0, 1.0, 0.0), vec3(1.0, 1.0, 0.0), fractional);
|
|
|
|
|
|
|
+ return mix(Vec3(0.0, 1.0, 0.0), Vec3(1.0, 1.0, 0.0), fractional);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
- return mix(vec3(1.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), fractional);
|
|
|
|
|
|
|
+ return mix(Vec3(1.0, 1.0, 0.0), Vec3(1.0, 0.0, 0.0), fractional);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool incorrectColor(vec3 c)
|
|
|
|
|
|
|
+bool incorrectColor(Vec3 c)
|
|
|
{
|
|
{
|
|
|
return isnan(c.x) || isnan(c.y) || isnan(c.z) || isinf(c.x) || isinf(c.y) || isinf(c.z);
|
|
return isnan(c.x) || isnan(c.y) || isnan(c.z) || isinf(c.x) || isinf(c.y) || isinf(c.z);
|
|
|
}
|
|
}
|