2020-03-19 19:44:45 -04:00
|
|
|
// Automatically generated from files in pathfinder/shaders/. Do not edit!
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
|
|
|
|
|
|
|
#include <metal_stdlib>
|
|
|
|
#include <simd/simd.h>
|
|
|
|
|
|
|
|
using namespace metal;
|
|
|
|
|
2020-07-23 16:45:20 -04:00
|
|
|
constant float3 _1121 = {};
|
2020-05-08 00:26:41 -04:00
|
|
|
|
2020-03-19 19:44:45 -04:00
|
|
|
struct main0_out
|
|
|
|
{
|
|
|
|
float4 oFragColor [[color(0)]];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct main0_in
|
|
|
|
{
|
|
|
|
float3 vMaskTexCoord0 [[user(locn0)]];
|
2020-04-21 16:09:23 -04:00
|
|
|
float2 vColorTexCoord0 [[user(locn1)]];
|
|
|
|
float4 vBaseColor [[user(locn2)]];
|
2020-04-22 14:04:16 -04:00
|
|
|
float vTileCtrl [[user(locn3)]];
|
2020-06-23 15:27:04 -04:00
|
|
|
float4 vFilterParams0 [[user(locn4)]];
|
|
|
|
float4 vFilterParams1 [[user(locn5)]];
|
|
|
|
float4 vFilterParams2 [[user(locn6)]];
|
2020-07-21 12:56:47 -04:00
|
|
|
float4 vFilterParams3 [[user(locn7)]];
|
|
|
|
float4 vFilterParams4 [[user(locn8)]];
|
|
|
|
float vCtrl [[user(locn9)]];
|
2020-03-19 19:44:45 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of the GLSL mod() function, which is slightly different than Metal fmod()
|
|
|
|
template<typename Tx, typename Ty>
|
2020-04-23 21:00:52 -04:00
|
|
|
inline Tx mod(Tx x, Ty y)
|
2020-03-19 19:44:45 -04:00
|
|
|
{
|
|
|
|
return x - y * floor(x / y);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-05-04 16:26:40 -04:00
|
|
|
float sampleMask(thread const float& maskAlpha, thread const texture2d<float> maskTexture, thread const sampler maskTextureSmplr, thread const float2& maskTextureSize, thread const float3& maskTexCoord, thread const int& maskCtrl)
|
2020-03-19 19:44:45 -04:00
|
|
|
{
|
|
|
|
if (maskCtrl == 0)
|
|
|
|
{
|
|
|
|
return maskAlpha;
|
|
|
|
}
|
2020-05-04 16:26:40 -04:00
|
|
|
int2 maskTexCoordI = int2(floor(maskTexCoord.xy));
|
|
|
|
float4 texel = maskTexture.sample(maskTextureSmplr, ((float2(maskTexCoordI / int2(1, 4)) + float2(0.5)) / maskTextureSize));
|
|
|
|
float coverage = texel[maskTexCoordI.y % 4] + maskTexCoord.z;
|
2020-03-19 19:44:45 -04:00
|
|
|
if ((maskCtrl & 1) != 0)
|
|
|
|
{
|
|
|
|
coverage = abs(coverage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
coverage = 1.0 - abs(1.0 - mod(coverage, 2.0));
|
|
|
|
}
|
|
|
|
return fast::min(maskAlpha, coverage);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-26 23:01:17 -04:00
|
|
|
float4 filterRadialGradient(thread const float2& colorTexCoord, thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr, thread const float2& colorTextureSize, thread const float2& fragCoord, thread const float2& framebufferSize, thread const float4& filterParams0, thread const float4& filterParams1)
|
|
|
|
{
|
|
|
|
float2 lineFrom = filterParams0.xy;
|
|
|
|
float2 lineVector = filterParams0.zw;
|
|
|
|
float2 radii = filterParams1.xy;
|
|
|
|
float2 uvOrigin = filterParams1.zw;
|
2020-04-20 16:03:49 -04:00
|
|
|
float2 dP = colorTexCoord - lineFrom;
|
2020-03-26 23:01:17 -04:00
|
|
|
float2 dC = lineVector;
|
|
|
|
float dR = radii.y - radii.x;
|
|
|
|
float a = dot(dC, dC) - (dR * dR);
|
|
|
|
float b = dot(dP, dC) + (radii.x * dR);
|
|
|
|
float c = dot(dP, dP) - (radii.x * radii.x);
|
|
|
|
float discrim = (b * b) - (a * c);
|
|
|
|
float4 color = float4(0.0);
|
2020-07-23 16:45:20 -04:00
|
|
|
if (discrim != 0.0)
|
2020-03-26 23:01:17 -04:00
|
|
|
{
|
|
|
|
float2 ts = float2((float2(1.0, -1.0) * sqrt(discrim)) + float2(b)) / float2(a);
|
2020-04-14 19:13:32 -04:00
|
|
|
if (ts.x > ts.y)
|
2020-03-26 23:01:17 -04:00
|
|
|
{
|
2020-04-14 19:13:32 -04:00
|
|
|
ts = ts.yx;
|
2020-03-26 23:01:17 -04:00
|
|
|
}
|
2020-07-23 16:45:20 -04:00
|
|
|
float _581;
|
2020-04-14 19:13:32 -04:00
|
|
|
if (ts.x >= 0.0)
|
2020-03-26 23:01:17 -04:00
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_581 = ts.x;
|
2020-03-26 23:01:17 -04:00
|
|
|
}
|
2020-04-14 19:13:32 -04:00
|
|
|
else
|
2020-03-26 23:01:17 -04:00
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_581 = ts.y;
|
2020-03-26 23:01:17 -04:00
|
|
|
}
|
2020-07-23 16:45:20 -04:00
|
|
|
float t = _581;
|
2020-07-16 13:30:39 -04:00
|
|
|
color = colorTexture.sample(colorTextureSmplr, (uvOrigin + float2(t, 0.0)));
|
2020-03-26 23:01:17 -04:00
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float4 filterBlur(thread const float2& colorTexCoord, thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr, thread const float2& colorTextureSize, thread const float4& filterParams0, thread const float4& filterParams1)
|
|
|
|
{
|
|
|
|
float2 srcOffsetScale = filterParams0.xy / colorTextureSize;
|
|
|
|
int support = int(filterParams0.z);
|
|
|
|
float3 gaussCoeff = filterParams1.xyz;
|
|
|
|
float gaussSum = gaussCoeff.x;
|
|
|
|
float4 color = colorTexture.sample(colorTextureSmplr, colorTexCoord) * gaussCoeff.x;
|
2020-07-23 16:45:20 -04:00
|
|
|
float2 _625 = gaussCoeff.xy * gaussCoeff.yz;
|
|
|
|
gaussCoeff = float3(_625.x, _625.y, gaussCoeff.z);
|
2020-03-19 19:44:45 -04:00
|
|
|
for (int i = 1; i <= support; i += 2)
|
|
|
|
{
|
|
|
|
float gaussPartialSum = gaussCoeff.x;
|
2020-07-23 16:45:20 -04:00
|
|
|
float2 _645 = gaussCoeff.xy * gaussCoeff.yz;
|
|
|
|
gaussCoeff = float3(_645.x, _645.y, gaussCoeff.z);
|
2020-03-19 19:44:45 -04:00
|
|
|
gaussPartialSum += gaussCoeff.x;
|
|
|
|
float2 srcOffset = srcOffsetScale * (float(i) + (gaussCoeff.x / gaussPartialSum));
|
|
|
|
color += ((colorTexture.sample(colorTextureSmplr, (colorTexCoord - srcOffset)) + colorTexture.sample(colorTextureSmplr, (colorTexCoord + srcOffset))) * gaussPartialSum);
|
|
|
|
gaussSum += (2.0 * gaussPartialSum);
|
2020-07-23 16:45:20 -04:00
|
|
|
float2 _685 = gaussCoeff.xy * gaussCoeff.yz;
|
|
|
|
gaussCoeff = float3(_685.x, _685.y, gaussCoeff.z);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
return color / float4(gaussSum);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float filterTextSample1Tap(thread const float& offset, thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr, thread const float2& colorTexCoord)
|
|
|
|
{
|
|
|
|
return colorTexture.sample(colorTextureSmplr, (colorTexCoord + float2(offset, 0.0))).x;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
void filterTextSample9Tap(thread float4& outAlphaLeft, thread float& outAlphaCenter, thread float4& outAlphaRight, thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr, thread const float2& colorTexCoord, thread const float4& kernel0, thread const float& onePixel)
|
|
|
|
{
|
|
|
|
bool wide = kernel0.x > 0.0;
|
2020-07-21 12:56:47 -04:00
|
|
|
float _264;
|
2020-03-19 19:44:45 -04:00
|
|
|
if (wide)
|
|
|
|
{
|
|
|
|
float param = (-4.0) * onePixel;
|
|
|
|
float2 param_1 = colorTexCoord;
|
2020-07-21 12:56:47 -04:00
|
|
|
_264 = filterTextSample1Tap(param, colorTexture, colorTextureSmplr, param_1);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-21 12:56:47 -04:00
|
|
|
_264 = 0.0;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
float param_2 = (-3.0) * onePixel;
|
|
|
|
float2 param_3 = colorTexCoord;
|
|
|
|
float param_4 = (-2.0) * onePixel;
|
|
|
|
float2 param_5 = colorTexCoord;
|
|
|
|
float param_6 = (-1.0) * onePixel;
|
|
|
|
float2 param_7 = colorTexCoord;
|
2020-07-21 12:56:47 -04:00
|
|
|
outAlphaLeft = float4(_264, filterTextSample1Tap(param_2, colorTexture, colorTextureSmplr, param_3), filterTextSample1Tap(param_4, colorTexture, colorTextureSmplr, param_5), filterTextSample1Tap(param_6, colorTexture, colorTextureSmplr, param_7));
|
2020-03-19 19:44:45 -04:00
|
|
|
float param_8 = 0.0;
|
|
|
|
float2 param_9 = colorTexCoord;
|
|
|
|
outAlphaCenter = filterTextSample1Tap(param_8, colorTexture, colorTextureSmplr, param_9);
|
|
|
|
float param_10 = 1.0 * onePixel;
|
|
|
|
float2 param_11 = colorTexCoord;
|
|
|
|
float param_12 = 2.0 * onePixel;
|
|
|
|
float2 param_13 = colorTexCoord;
|
|
|
|
float param_14 = 3.0 * onePixel;
|
|
|
|
float2 param_15 = colorTexCoord;
|
2020-07-21 12:56:47 -04:00
|
|
|
float _324;
|
2020-03-19 19:44:45 -04:00
|
|
|
if (wide)
|
|
|
|
{
|
|
|
|
float param_16 = 4.0 * onePixel;
|
|
|
|
float2 param_17 = colorTexCoord;
|
2020-07-21 12:56:47 -04:00
|
|
|
_324 = filterTextSample1Tap(param_16, colorTexture, colorTextureSmplr, param_17);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-21 12:56:47 -04:00
|
|
|
_324 = 0.0;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-21 12:56:47 -04:00
|
|
|
outAlphaRight = float4(filterTextSample1Tap(param_10, colorTexture, colorTextureSmplr, param_11), filterTextSample1Tap(param_12, colorTexture, colorTextureSmplr, param_13), filterTextSample1Tap(param_14, colorTexture, colorTextureSmplr, param_15), _324);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float filterTextConvolve7Tap(thread const float4& alpha0, thread const float3& alpha1, thread const float4& kernel0)
|
|
|
|
{
|
|
|
|
return dot(alpha0, kernel0) + dot(alpha1, kernel0.zyx);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float filterTextGammaCorrectChannel(thread const float& bgColor, thread const float& fgColor, thread const texture2d<float> gammaLUT, thread const sampler gammaLUTSmplr)
|
|
|
|
{
|
|
|
|
return gammaLUT.sample(gammaLUTSmplr, float2(fgColor, 1.0 - bgColor)).x;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 filterTextGammaCorrect(thread const float3& bgColor, thread const float3& fgColor, thread const texture2d<float> gammaLUT, thread const sampler gammaLUTSmplr)
|
|
|
|
{
|
|
|
|
float param = bgColor.x;
|
|
|
|
float param_1 = fgColor.x;
|
|
|
|
float param_2 = bgColor.y;
|
|
|
|
float param_3 = fgColor.y;
|
|
|
|
float param_4 = bgColor.z;
|
|
|
|
float param_5 = fgColor.z;
|
|
|
|
return float3(filterTextGammaCorrectChannel(param, param_1, gammaLUT, gammaLUTSmplr), filterTextGammaCorrectChannel(param_2, param_3, gammaLUT, gammaLUTSmplr), filterTextGammaCorrectChannel(param_4, param_5, gammaLUT, gammaLUTSmplr));
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float4 filterText(thread const float2& colorTexCoord, thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr, thread const texture2d<float> gammaLUT, thread const sampler gammaLUTSmplr, thread const float2& colorTextureSize, thread const float4& filterParams0, thread const float4& filterParams1, thread const float4& filterParams2)
|
|
|
|
{
|
|
|
|
float4 kernel0 = filterParams0;
|
|
|
|
float3 bgColor = filterParams1.xyz;
|
|
|
|
float3 fgColor = filterParams2.xyz;
|
|
|
|
bool gammaCorrectionEnabled = filterParams2.w != 0.0;
|
|
|
|
float3 alpha;
|
|
|
|
if (kernel0.w == 0.0)
|
|
|
|
{
|
|
|
|
alpha = colorTexture.sample(colorTextureSmplr, colorTexCoord).xxx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float2 param_3 = colorTexCoord;
|
|
|
|
float4 param_4 = kernel0;
|
|
|
|
float param_5 = 1.0 / colorTextureSize.x;
|
|
|
|
float4 param;
|
|
|
|
float param_1;
|
|
|
|
float4 param_2;
|
|
|
|
filterTextSample9Tap(param, param_1, param_2, colorTexture, colorTextureSmplr, param_3, param_4, param_5);
|
|
|
|
float4 alphaLeft = param;
|
|
|
|
float alphaCenter = param_1;
|
|
|
|
float4 alphaRight = param_2;
|
|
|
|
float4 param_6 = alphaLeft;
|
|
|
|
float3 param_7 = float3(alphaCenter, alphaRight.xy);
|
|
|
|
float4 param_8 = kernel0;
|
|
|
|
float r = filterTextConvolve7Tap(param_6, param_7, param_8);
|
|
|
|
float4 param_9 = float4(alphaLeft.yzw, alphaCenter);
|
|
|
|
float3 param_10 = alphaRight.xyz;
|
|
|
|
float4 param_11 = kernel0;
|
|
|
|
float g = filterTextConvolve7Tap(param_9, param_10, param_11);
|
|
|
|
float4 param_12 = float4(alphaLeft.zw, alphaCenter, alphaRight.x);
|
|
|
|
float3 param_13 = alphaRight.yzw;
|
|
|
|
float4 param_14 = kernel0;
|
|
|
|
float b = filterTextConvolve7Tap(param_12, param_13, param_14);
|
|
|
|
alpha = float3(r, g, b);
|
|
|
|
}
|
|
|
|
if (gammaCorrectionEnabled)
|
|
|
|
{
|
|
|
|
float3 param_15 = bgColor;
|
|
|
|
float3 param_16 = alpha;
|
|
|
|
alpha = filterTextGammaCorrect(param_15, param_16, gammaLUT, gammaLUTSmplr);
|
|
|
|
}
|
|
|
|
return float4(mix(bgColor, fgColor, alpha), 1.0);
|
|
|
|
}
|
|
|
|
|
2020-07-21 12:56:47 -04:00
|
|
|
static inline __attribute__((always_inline))
|
|
|
|
float4 filterColorMatrix(thread const float2& colorTexCoord, thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr, thread const float4& filterParams0, thread const float4& filterParams1, thread const float4& filterParams2, thread const float4& filterParams3, thread const float4& filterParams4)
|
|
|
|
{
|
|
|
|
float4 srcColor = colorTexture.sample(colorTextureSmplr, colorTexCoord);
|
|
|
|
float4x4 colorMatrix = float4x4(float4(filterParams0), float4(filterParams1), float4(filterParams2), float4(filterParams3));
|
|
|
|
return (colorMatrix * srcColor) + filterParams4;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float4 sampleColor(thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr, thread const float2& colorTexCoord)
|
|
|
|
{
|
|
|
|
return colorTexture.sample(colorTextureSmplr, colorTexCoord);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float4 filterNone(thread const float2& colorTexCoord, thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr)
|
|
|
|
{
|
|
|
|
float2 param = colorTexCoord;
|
|
|
|
return sampleColor(colorTexture, colorTextureSmplr, param);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-07-21 12:56:47 -04:00
|
|
|
float4 filterColor(thread const float2& colorTexCoord, thread const texture2d<float> colorTexture, thread const sampler colorTextureSmplr, thread const texture2d<float> gammaLUT, thread const sampler gammaLUTSmplr, thread const float2& colorTextureSize, thread const float2& fragCoord, thread const float2& framebufferSize, thread const float4& filterParams0, thread const float4& filterParams1, thread const float4& filterParams2, thread const float4& filterParams3, thread const float4& filterParams4, thread const int& colorFilter)
|
2020-03-19 19:44:45 -04:00
|
|
|
{
|
|
|
|
switch (colorFilter)
|
|
|
|
{
|
2020-03-26 23:01:17 -04:00
|
|
|
case 1:
|
2020-03-19 19:44:45 -04:00
|
|
|
{
|
|
|
|
float2 param = colorTexCoord;
|
|
|
|
float2 param_1 = colorTextureSize;
|
2020-03-26 23:01:17 -04:00
|
|
|
float2 param_2 = fragCoord;
|
|
|
|
float2 param_3 = framebufferSize;
|
|
|
|
float4 param_4 = filterParams0;
|
|
|
|
float4 param_5 = filterParams1;
|
|
|
|
return filterRadialGradient(param, colorTexture, colorTextureSmplr, param_1, param_2, param_3, param_4, param_5);
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
float2 param_6 = colorTexCoord;
|
|
|
|
float2 param_7 = colorTextureSize;
|
|
|
|
float4 param_8 = filterParams0;
|
|
|
|
float4 param_9 = filterParams1;
|
|
|
|
return filterBlur(param_6, colorTexture, colorTextureSmplr, param_7, param_8, param_9);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
2020-03-26 23:01:17 -04:00
|
|
|
float2 param_10 = colorTexCoord;
|
|
|
|
float2 param_11 = colorTextureSize;
|
|
|
|
float4 param_12 = filterParams0;
|
|
|
|
float4 param_13 = filterParams1;
|
|
|
|
float4 param_14 = filterParams2;
|
|
|
|
return filterText(param_10, colorTexture, colorTextureSmplr, gammaLUT, gammaLUTSmplr, param_11, param_12, param_13, param_14);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-21 12:56:47 -04:00
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
float2 param_15 = colorTexCoord;
|
|
|
|
float4 param_16 = filterParams0;
|
|
|
|
float4 param_17 = filterParams1;
|
|
|
|
float4 param_18 = filterParams2;
|
|
|
|
float4 param_19 = filterParams3;
|
|
|
|
float4 param_20 = filterParams4;
|
|
|
|
return filterColorMatrix(param_15, colorTexture, colorTextureSmplr, param_16, param_17, param_18, param_19, param_20);
|
|
|
|
}
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-21 12:56:47 -04:00
|
|
|
float2 param_21 = colorTexCoord;
|
|
|
|
return filterNone(param_21, colorTexture, colorTextureSmplr);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-04-13 14:52:10 -04:00
|
|
|
float4 combineColor0(thread const float4& destColor, thread const float4& srcColor, thread const int& op)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
return float4(srcColor.xyz, srcColor.w * destColor.w);
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
return float4(destColor.xyz, srcColor.w * destColor.w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return destColor;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeScreen(thread const float3& destColor, thread const float3& srcColor)
|
|
|
|
{
|
|
|
|
return (destColor + srcColor) - (destColor * srcColor);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeSelect(thread const bool3& cond, thread const float3& ifTrue, thread const float3& ifFalse)
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
float _805;
|
2020-03-19 19:44:45 -04:00
|
|
|
if (cond.x)
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_805 = ifTrue.x;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_805 = ifFalse.x;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-23 16:45:20 -04:00
|
|
|
float _816;
|
2020-03-19 19:44:45 -04:00
|
|
|
if (cond.y)
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_816 = ifTrue.y;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_816 = ifFalse.y;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-23 16:45:20 -04:00
|
|
|
float _827;
|
2020-03-19 19:44:45 -04:00
|
|
|
if (cond.z)
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_827 = ifTrue.z;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_827 = ifFalse.z;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-23 16:45:20 -04:00
|
|
|
return float3(_805, _816, _827);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeHardLight(thread const float3& destColor, thread const float3& srcColor)
|
|
|
|
{
|
|
|
|
float3 param = destColor;
|
|
|
|
float3 param_1 = (float3(2.0) * srcColor) - float3(1.0);
|
|
|
|
bool3 param_2 = srcColor <= float3(0.5);
|
|
|
|
float3 param_3 = (destColor * float3(2.0)) * srcColor;
|
|
|
|
float3 param_4 = compositeScreen(param, param_1);
|
|
|
|
return compositeSelect(param_2, param_3, param_4);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeColorDodge(thread const float3& destColor, thread const float3& srcColor)
|
|
|
|
{
|
|
|
|
bool3 destZero = destColor == float3(0.0);
|
|
|
|
bool3 srcOne = srcColor == float3(1.0);
|
|
|
|
bool3 param = srcOne;
|
|
|
|
float3 param_1 = float3(1.0);
|
|
|
|
float3 param_2 = destColor / (float3(1.0) - srcColor);
|
|
|
|
bool3 param_3 = destZero;
|
|
|
|
float3 param_4 = float3(0.0);
|
|
|
|
float3 param_5 = compositeSelect(param, param_1, param_2);
|
|
|
|
return compositeSelect(param_3, param_4, param_5);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeSoftLight(thread const float3& destColor, thread const float3& srcColor)
|
|
|
|
{
|
|
|
|
bool3 param = destColor <= float3(0.25);
|
|
|
|
float3 param_1 = ((((float3(16.0) * destColor) - float3(12.0)) * destColor) + float3(4.0)) * destColor;
|
|
|
|
float3 param_2 = sqrt(destColor);
|
|
|
|
float3 darkenedDestColor = compositeSelect(param, param_1, param_2);
|
|
|
|
bool3 param_3 = srcColor <= float3(0.5);
|
|
|
|
float3 param_4 = destColor * (float3(1.0) - destColor);
|
|
|
|
float3 param_5 = darkenedDestColor - destColor;
|
|
|
|
float3 factor = compositeSelect(param_3, param_4, param_5);
|
|
|
|
return destColor + (((srcColor * 2.0) - float3(1.0)) * factor);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float compositeDivide(thread const float& num, thread const float& denom)
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
float _841;
|
2020-03-19 19:44:45 -04:00
|
|
|
if (denom != 0.0)
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_841 = num / denom;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_841 = 0.0;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-23 16:45:20 -04:00
|
|
|
return _841;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeRGBToHSL(thread const float3& rgb)
|
|
|
|
{
|
|
|
|
float v = fast::max(fast::max(rgb.x, rgb.y), rgb.z);
|
|
|
|
float xMin = fast::min(fast::min(rgb.x, rgb.y), rgb.z);
|
|
|
|
float c = v - xMin;
|
|
|
|
float l = mix(xMin, v, 0.5);
|
2020-07-23 16:45:20 -04:00
|
|
|
float3 _947;
|
2020-03-19 19:44:45 -04:00
|
|
|
if (rgb.x == v)
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_947 = float3(0.0, rgb.yz);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
float3 _960;
|
2020-03-19 19:44:45 -04:00
|
|
|
if (rgb.y == v)
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_960 = float3(2.0, rgb.zx);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-23 16:45:20 -04:00
|
|
|
_960 = float3(4.0, rgb.xy);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-23 16:45:20 -04:00
|
|
|
_947 = _960;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-07-23 16:45:20 -04:00
|
|
|
float3 terms = _947;
|
2020-03-19 19:44:45 -04:00
|
|
|
float param = ((terms.x * c) + terms.y) - terms.z;
|
|
|
|
float param_1 = c;
|
|
|
|
float h = 1.0471975803375244140625 * compositeDivide(param, param_1);
|
|
|
|
float param_2 = c;
|
|
|
|
float param_3 = v;
|
|
|
|
float s = compositeDivide(param_2, param_3);
|
|
|
|
return float3(h, s, l);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeHSL(thread const float3& destColor, thread const float3& srcColor, thread const int& op)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
return float3(srcColor.x, destColor.y, destColor.z);
|
|
|
|
}
|
|
|
|
case 13:
|
|
|
|
{
|
|
|
|
return float3(destColor.x, srcColor.y, destColor.z);
|
|
|
|
}
|
|
|
|
case 14:
|
|
|
|
{
|
|
|
|
return float3(srcColor.x, srcColor.y, destColor.z);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return float3(destColor.x, destColor.y, srcColor.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeHSLToRGB(thread const float3& hsl)
|
|
|
|
{
|
|
|
|
float a = hsl.y * fast::min(hsl.z, 1.0 - hsl.z);
|
|
|
|
float3 ks = mod(float3(0.0, 8.0, 4.0) + float3(hsl.x * 1.90985929965972900390625), float3(12.0));
|
|
|
|
return hsl.zzz - (fast::clamp(fast::min(ks - float3(3.0), float3(9.0) - ks), float3(-1.0), float3(1.0)) * a);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float3 compositeRGB(thread const float3& destColor, thread const float3& srcColor, thread const int& op)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
return destColor * srcColor;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
float3 param = destColor;
|
|
|
|
float3 param_1 = srcColor;
|
|
|
|
return compositeScreen(param, param_1);
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
float3 param_2 = srcColor;
|
|
|
|
float3 param_3 = destColor;
|
|
|
|
return compositeHardLight(param_2, param_3);
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
return fast::min(destColor, srcColor);
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
return fast::max(destColor, srcColor);
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
float3 param_4 = destColor;
|
|
|
|
float3 param_5 = srcColor;
|
|
|
|
return compositeColorDodge(param_4, param_5);
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
float3 param_6 = float3(1.0) - destColor;
|
|
|
|
float3 param_7 = float3(1.0) - srcColor;
|
|
|
|
return float3(1.0) - compositeColorDodge(param_6, param_7);
|
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
float3 param_8 = destColor;
|
|
|
|
float3 param_9 = srcColor;
|
|
|
|
return compositeHardLight(param_8, param_9);
|
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
|
|
|
float3 param_10 = destColor;
|
|
|
|
float3 param_11 = srcColor;
|
|
|
|
return compositeSoftLight(param_10, param_11);
|
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
return abs(destColor - srcColor);
|
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
return (destColor + srcColor) - ((float3(2.0) * destColor) * srcColor);
|
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
case 13:
|
|
|
|
case 14:
|
|
|
|
case 15:
|
|
|
|
{
|
|
|
|
float3 param_12 = destColor;
|
|
|
|
float3 param_13 = srcColor;
|
|
|
|
float3 param_14 = compositeRGBToHSL(param_12);
|
|
|
|
float3 param_15 = compositeRGBToHSL(param_13);
|
|
|
|
int param_16 = op;
|
|
|
|
float3 param_17 = compositeHSL(param_14, param_15, param_16);
|
|
|
|
return compositeHSLToRGB(param_17);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return srcColor;
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-03-19 19:44:45 -04:00
|
|
|
float4 composite(thread const float4& srcColor, thread const texture2d<float> destTexture, thread const sampler destTextureSmplr, thread const float2& destTextureSize, thread const float2& fragCoord, thread const int& op)
|
|
|
|
{
|
|
|
|
if (op == 0)
|
|
|
|
{
|
|
|
|
return srcColor;
|
|
|
|
}
|
|
|
|
float2 destTexCoord = fragCoord / destTextureSize;
|
|
|
|
float4 destColor = destTexture.sample(destTextureSmplr, destTexCoord);
|
|
|
|
float3 param = destColor.xyz;
|
|
|
|
float3 param_1 = srcColor.xyz;
|
|
|
|
int param_2 = op;
|
|
|
|
float3 blendedRGB = compositeRGB(param, param_1, param_2);
|
|
|
|
return float4(((srcColor.xyz * (srcColor.w * (1.0 - destColor.w))) + (blendedRGB * (srcColor.w * destColor.w))) + (destColor.xyz * (1.0 - srcColor.w)), 1.0);
|
|
|
|
}
|
|
|
|
|
2020-04-23 21:00:52 -04:00
|
|
|
static inline __attribute__((always_inline))
|
2020-07-21 12:56:47 -04:00
|
|
|
float4 calculateColor(thread const float2& fragCoord, thread const texture2d<float> colorTexture0, thread const sampler colorTexture0Smplr, thread const texture2d<float> maskTexture0, thread const sampler maskTexture0Smplr, thread const texture2d<float> destTexture, thread const sampler destTextureSmplr, thread const texture2d<float> gammaLUT, thread const sampler gammaLUTSmplr, thread const float2& colorTextureSize0, thread const float2& maskTextureSize0, thread const float4& filterParams0, thread const float4& filterParams1, thread const float4& filterParams2, thread const float4& filterParams3, thread const float4& filterParams4, thread const float2& framebufferSize, thread const int& ctrl, thread const float3& maskTexCoord0, thread const float2& colorTexCoord0, thread const float4& baseColor, thread const int& tileCtrl)
|
2020-03-19 19:44:45 -04:00
|
|
|
{
|
2020-04-22 14:04:16 -04:00
|
|
|
int maskCtrl0 = (tileCtrl >> 0) & 3;
|
2020-03-19 19:44:45 -04:00
|
|
|
float maskAlpha = 1.0;
|
|
|
|
float param = maskAlpha;
|
2020-06-23 15:27:04 -04:00
|
|
|
float2 param_1 = maskTextureSize0;
|
|
|
|
float3 param_2 = maskTexCoord0;
|
2020-05-04 16:26:40 -04:00
|
|
|
int param_3 = maskCtrl0;
|
2020-06-23 15:27:04 -04:00
|
|
|
maskAlpha = sampleMask(param, maskTexture0, maskTexture0Smplr, param_1, param_2, param_3);
|
|
|
|
float4 color = baseColor;
|
2020-07-21 12:56:47 -04:00
|
|
|
int color0Combine = (ctrl >> 8) & 3;
|
2020-04-13 14:52:10 -04:00
|
|
|
if (color0Combine != 0)
|
2020-03-19 19:44:45 -04:00
|
|
|
{
|
2020-07-21 12:56:47 -04:00
|
|
|
int color0Filter = (ctrl >> 4) & 15;
|
2020-06-23 15:27:04 -04:00
|
|
|
float2 param_4 = colorTexCoord0;
|
|
|
|
float2 param_5 = colorTextureSize0;
|
|
|
|
float2 param_6 = fragCoord;
|
|
|
|
float2 param_7 = framebufferSize;
|
|
|
|
float4 param_8 = filterParams0;
|
|
|
|
float4 param_9 = filterParams1;
|
|
|
|
float4 param_10 = filterParams2;
|
2020-07-21 12:56:47 -04:00
|
|
|
float4 param_11 = filterParams3;
|
|
|
|
float4 param_12 = filterParams4;
|
|
|
|
int param_13 = color0Filter;
|
|
|
|
float4 color0 = filterColor(param_4, colorTexture0, colorTexture0Smplr, gammaLUT, gammaLUTSmplr, param_5, param_6, param_7, param_8, param_9, param_10, param_11, param_12, param_13);
|
|
|
|
float4 param_14 = color;
|
|
|
|
float4 param_15 = color0;
|
|
|
|
int param_16 = color0Combine;
|
|
|
|
color = combineColor0(param_14, param_15, param_16);
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
2020-04-13 14:52:10 -04:00
|
|
|
color.w *= maskAlpha;
|
2020-07-21 12:56:47 -04:00
|
|
|
int compositeOp = (ctrl >> 10) & 15;
|
|
|
|
float4 param_17 = color;
|
|
|
|
float2 param_18 = framebufferSize;
|
|
|
|
float2 param_19 = fragCoord;
|
|
|
|
int param_20 = compositeOp;
|
|
|
|
color = composite(param_17, destTexture, destTextureSmplr, param_18, param_19, param_20);
|
2020-07-23 16:45:20 -04:00
|
|
|
float3 _1409 = color.xyz * color.w;
|
|
|
|
color = float4(_1409.x, _1409.y, _1409.z, color.w);
|
2020-06-23 15:27:04 -04:00
|
|
|
return color;
|
2020-03-19 19:44:45 -04:00
|
|
|
}
|
|
|
|
|
2020-06-23 15:27:04 -04:00
|
|
|
fragment main0_out main0(main0_in in [[stage_in]], constant float2& uColorTextureSize0 [[buffer(0)]], constant float2& uMaskTextureSize0 [[buffer(1)]], constant float2& uFramebufferSize [[buffer(2)]], texture2d<float> uColorTexture0 [[texture(0)]], texture2d<float> uMaskTexture0 [[texture(1)]], texture2d<float> uDestTexture [[texture(2)]], texture2d<float> uGammaLUT [[texture(3)]], sampler uColorTexture0Smplr [[sampler(0)]], sampler uMaskTexture0Smplr [[sampler(1)]], sampler uDestTextureSmplr [[sampler(2)]], sampler uGammaLUTSmplr [[sampler(3)]], float4 gl_FragCoord [[position]])
|
2020-03-19 19:44:45 -04:00
|
|
|
{
|
|
|
|
main0_out out = {};
|
2020-06-23 15:27:04 -04:00
|
|
|
float2 param = gl_FragCoord.xy;
|
|
|
|
float2 param_1 = uColorTextureSize0;
|
|
|
|
float2 param_2 = uMaskTextureSize0;
|
|
|
|
float4 param_3 = in.vFilterParams0;
|
|
|
|
float4 param_4 = in.vFilterParams1;
|
|
|
|
float4 param_5 = in.vFilterParams2;
|
2020-07-21 12:56:47 -04:00
|
|
|
float4 param_6 = in.vFilterParams3;
|
|
|
|
float4 param_7 = in.vFilterParams4;
|
|
|
|
float2 param_8 = uFramebufferSize;
|
|
|
|
int param_9 = int(in.vCtrl);
|
|
|
|
float3 param_10 = in.vMaskTexCoord0;
|
|
|
|
float2 param_11 = in.vColorTexCoord0;
|
|
|
|
float4 param_12 = in.vBaseColor;
|
|
|
|
int param_13 = int(in.vTileCtrl);
|
|
|
|
out.oFragColor = calculateColor(param, uColorTexture0, uColorTexture0Smplr, uMaskTexture0, uMaskTexture0Smplr, uDestTexture, uDestTextureSmplr, uGammaLUT, uGammaLUTSmplr, param_1, param_2, param_3, param_4, param_5, param_6, param_7, param_8, param_9, param_10, param_11, param_12, param_13);
|
2020-03-19 19:44:45 -04:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|