gl_engine: code clean up

ensure consistency in coding style.
This commit is contained in:
Hermet Park 2024-10-19 14:08:00 +09:00 committed by Hermet Park
parent c4c262fb16
commit 765f927dd0

View file

@ -31,208 +31,193 @@ const char* COLOR_VERT_SHADER = TVG_COMPOSE_SHADER(
layout(std140) uniform Matrix { \n layout(std140) uniform Matrix { \n
mat4 transform; \n mat4 transform; \n
} uMatrix; \n } uMatrix; \n
\n
void main() \n void main() \n
{ \n { \n
vec4 pos = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n vec4 pos = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n
pos.z = uDepth; \n pos.z = uDepth; \n
gl_Position = pos; \n gl_Position = pos; \n
}); } \n
);
const char* COLOR_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* COLOR_FRAG_SHADER = TVG_COMPOSE_SHADER(
layout(std140) uniform ColorInfo { \n layout(std140) uniform ColorInfo { \n
vec4 solidColor; \n vec4 solidColor; \n
} uColorInfo; \n } uColorInfo; \n
out vec4 FragColor; \n out vec4 FragColor; \n
\n
void main() \n void main() \n
{ \n { \n
vec4 uColor = uColorInfo.solidColor; \n vec4 uColor = uColorInfo.solidColor; \n
FragColor = vec4(uColor.rgb * uColor.a, uColor.a); \n FragColor = vec4(uColor.rgb * uColor.a, uColor.a); \n
}); } \n
);
const char* GRADIENT_VERT_SHADER = TVG_COMPOSE_SHADER( const char* GRADIENT_VERT_SHADER = TVG_COMPOSE_SHADER(
uniform float uDepth; \n uniform float uDepth; \n
layout(location = 0) in vec2 aLocation; \n layout(location = 0) in vec2 aLocation; \n
out vec2 vPos; \n out vec2 vPos; \n
layout(std140) uniform Matrix { \n layout(std140) uniform Matrix { \n
mat4 transform; \n mat4 transform; \n
} uMatrix; \n } uMatrix; \n
layout(std140) uniform InvMatrix { \n layout(std140) uniform InvMatrix { \n
mat4 transform; \n mat4 transform; \n
} uInvMatrix; \n } uInvMatrix; \n
\n \n
void main() \n void main() \n
{ \n { \n
vec4 glPos = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n vec4 glPos = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n
glPos.z = uDepth; \n glPos.z = uDepth; \n
gl_Position = glPos; \n gl_Position = glPos; \n
vec4 pos = uInvMatrix.transform * vec4(aLocation, 0.0, 1.0); \n vec4 pos = uInvMatrix.transform * vec4(aLocation, 0.0, 1.0); \n
vPos = pos.xy / pos.w; \n vPos = pos.xy / pos.w; \n
}); } \n
);
std::string STR_GRADIENT_FRAG_COMMON_VARIABLES = TVG_COMPOSE_SHADER( std::string STR_GRADIENT_FRAG_COMMON_VARIABLES = TVG_COMPOSE_SHADER(
const int MAX_STOP_COUNT = 16; \n const int MAX_STOP_COUNT = 16; \n
in vec2 vPos; \n in vec2 vPos; \n
); );
std::string STR_GRADIENT_FRAG_COMMON_FUNCTIONS = TVG_COMPOSE_SHADER( std::string STR_GRADIENT_FRAG_COMMON_FUNCTIONS = TVG_COMPOSE_SHADER(
float gradientStep(float edge0, float edge1, float x) \n float gradientStep(float edge0, float edge1, float x) \n
{ \n { \n
// linear \n // linear \n
x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); \n x = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); \n
return x; \n return x; \n
} \n } \n
\n \n
float gradientStop(int index) \n float gradientStop(int index) \n
{ \n { \n
if (index >= MAX_STOP_COUNT) index = MAX_STOP_COUNT - 1; \n if (index >= MAX_STOP_COUNT) index = MAX_STOP_COUNT - 1; \n
int i = index / 4; \n int i = index / 4; \n
int j = index % 4; \n int j = index % 4; \n
return uGradientInfo.stopPoints[i][j]; \n return uGradientInfo.stopPoints[i][j]; \n
} \n } \n
\n \n
float gradientWrap(float d) \n float gradientWrap(float d) \n
{ \n { \n
int spread = int(uGradientInfo.nStops[2]); \n int spread = int(uGradientInfo.nStops[2]); \n
\n if (spread == 0) return clamp(d, 0.0, 1.0); \n
if (spread == 0) { /* pad */ \n \n
return clamp(d, 0.0, 1.0); \n if (spread == 1) { /* Reflect */ \n
} \n float n = mod(d, 2.0); \n
\n if (n > 1.0) { \n
if (spread == 1) { /* Reflect */ \n n = 2.0 - n; \n
float n = mod(d, 2.0); \n } \n
if (n > 1.0) \n return n; \n
{ \n } \n
n = 2.0 - n; \n if (spread == 2) { /* Repeat */ \n
} \n float n = mod(d, 1.0); \n
return n; \n if (n < 0.0) { \n
} \n n += 1.0 + n; \n
\n } \n
if (spread == 2) { /* Repeat */ \n return n; \n
float n = mod(d, 1.0); \n } \n
if (n < 0.0) \n } \n
{ \n \n
n += 1.0 + n; \n vec4 gradient(float t, float d, float l) \n
} \n { \n
return n; \n float dist = d * 2.0 / l; \n
} \n vec4 col = vec4(0.0); \n
} \n int i = 0; \n
\n int count = int(uGradientInfo.nStops[0]); \n
vec4 gradient(float t, float d, float l) \n if (t <= gradientStop(0)) { \n
{ \n col = uGradientInfo.stopColors[0]; \n
float dist = d * 2.0 / l; \n } else if (t >= gradientStop(count - 1)) { \n
vec4 col = vec4(0.0); \n col = uGradientInfo.stopColors[count - 1]; \n
int i = 0; \n if (int(uGradientInfo.nStops[2]) == 2 && (1.0 - t) < dist) { \n
int count = int(uGradientInfo.nStops[0]); \n float dd = (1.0 - t) / dist; \n
if (t <= gradientStop(0)) \n float alpha = dd; \n
{ \n col *= alpha; \n
col = uGradientInfo.stopColors[0]; \n col += uGradientInfo.stopColors[0] * (1. - alpha); \n
} \n } \n
else if (t >= gradientStop(count - 1)) \n } else { \n
{ \n for (i = 0; i < count - 1; ++i) { \n
col = uGradientInfo.stopColors[count - 1]; \n float stopi = gradientStop(i); \n
if (int(uGradientInfo.nStops[2]) == 2 && (1.0 - t) < dist) { \n float stopi1 = gradientStop(i + 1); \n
float dd = (1.0 - t) / dist; \n if (t >= stopi && t <= stopi1) { \n
float alpha = dd; \n col = (uGradientInfo.stopColors[i] * (1. - gradientStep(stopi, stopi1, t))); \n
col *= alpha; \n col += (uGradientInfo.stopColors[i + 1] * gradientStep(stopi, stopi1, t)); \n
col += uGradientInfo.stopColors[0] * (1. - alpha);\n if (int(uGradientInfo.nStops[2]) == 2 && abs(d) > dist) { \n
} \n if (i == 0 && (t - stopi) < dist) { \n
} \n float dd = (t - stopi) / dist; \n
else \n float alpha = dd; \n
{ \n col *= alpha; \n
for (i = 0; i < count - 1; ++i) \n vec4 nc = uGradientInfo.stopColors[0] * (1.0 - (t - stopi)); \n
{ \n nc += uGradientInfo.stopColors[count - 1] * (t - stopi); \n
float stopi = gradientStop(i); \n col += nc * (1.0 - alpha); \n
float stopi1 = gradientStop(i + 1); \n } else if (i == count - 2 && (1.0 - t) < dist) { \n
if (t >= stopi && t <= stopi1) \n float dd = (1.0 - t) / dist; \n
{ \n float alpha = dd; \n
col = (uGradientInfo.stopColors[i] * (1. - gradientStep(stopi, stopi1, t))); \n col *= alpha; \n
col += (uGradientInfo.stopColors[i + 1] * gradientStep(stopi, stopi1, t)); \n col += (uGradientInfo.stopColors[0]) * (1.0 - alpha); \n
if (int(uGradientInfo.nStops[2]) == 2 && abs(d) > dist) { \n } \n
if (i == 0 && (t - stopi) < dist) { \n } \n
float dd = (t - stopi) / dist; \n break; \n
float alpha = dd; \n } \n
col *= alpha; \n } \n
vec4 nc = uGradientInfo.stopColors[0] * (1.0 - (t - stopi)); \n } \n
nc += uGradientInfo.stopColors[count - 1] * (t - stopi); \n return col; \n
col += nc * (1.0 - alpha); \n } \n
} else if (i == count - 2 && (1.0 - t) < dist) { \n \n
float dd = (1.0 - t) / dist; \n vec3 ScreenSpaceDither(vec2 vScreenPos) \n
float alpha = dd; \n { \n
col *= alpha; \n vec3 vDither = vec3(dot(vec2(171.0, 231.0), vScreenPos.xy)); \n
col += (uGradientInfo.stopColors[0]) * (1.0 - alpha); \n vDither.rgb = fract(vDither.rgb / vec3(103.0, 71.0, 97.0)); \n
} \n return vDither.rgb / 255.0; \n
} \n } \n
break; \n );
} \n
} \n
} \n
\n
return col; \n
} \n
\n
vec3 ScreenSpaceDither(vec2 vScreenPos) \n
{ \n
vec3 vDither = vec3(dot(vec2(171.0, 231.0), vScreenPos.xy)); \n
vDither.rgb = fract(vDither.rgb / vec3(103.0, 71.0, 97.0)); \n
return vDither.rgb / 255.0; \n
});
std::string STR_LINEAR_GRADIENT_VARIABLES = TVG_COMPOSE_SHADER( std::string STR_LINEAR_GRADIENT_VARIABLES = TVG_COMPOSE_SHADER(
layout(std140) uniform GradientInfo { \n layout(std140) uniform GradientInfo { \n
vec4 nStops; \n vec4 nStops; \n
vec2 gradStartPos; \n vec2 gradStartPos; \n
vec2 gradEndPos; \n vec2 gradEndPos; \n
vec4 stopPoints[MAX_STOP_COUNT / 4]; \n vec4 stopPoints[MAX_STOP_COUNT / 4]; \n
vec4 stopColors[MAX_STOP_COUNT]; \n vec4 stopColors[MAX_STOP_COUNT]; \n
} uGradientInfo ; \n } uGradientInfo; \n
); );
std::string STR_LINEAR_GRADIENT_MAIN = TVG_COMPOSE_SHADER( std::string STR_LINEAR_GRADIENT_MAIN = TVG_COMPOSE_SHADER(
out vec4 FragColor; \n out vec4 FragColor; \n
void main() \n void main() \n
{ \n { \n
vec2 pos = vPos; \n vec2 pos = vPos; \n
vec2 st = uGradientInfo.gradStartPos; \n vec2 st = uGradientInfo.gradStartPos; \n
vec2 ed = uGradientInfo.gradEndPos; \n vec2 ed = uGradientInfo.gradEndPos; \n
\n vec2 ba = ed - st; \n
vec2 ba = ed - st; \n float d = dot(pos - st, ba) / dot(ba, ba); \n
\n float t = gradientWrap(d); \n
float d = dot(pos - st, ba) / dot(ba, ba); \n vec4 color = gradient(t, d, length(pos - st)); \n
\n FragColor = vec4(color.rgb * color.a, color.a); \n
float t = gradientWrap(d); \n } \n
\n );
vec4 color = gradient(t, d, length(pos - st)); \n
\n
FragColor = vec4(color.rgb * color.a, color.a); \n
});
std::string STR_RADIAL_GRADIENT_VARIABLES = TVG_COMPOSE_SHADER( std::string STR_RADIAL_GRADIENT_VARIABLES = TVG_COMPOSE_SHADER(
layout(std140) uniform GradientInfo { \n layout(std140) uniform GradientInfo { \n
vec4 nStops; \n vec4 nStops; \n
vec2 centerPos; \n vec2 centerPos; \n
vec2 radius; \n vec2 radius; \n
vec4 stopPoints[MAX_STOP_COUNT / 4]; \n vec4 stopPoints[MAX_STOP_COUNT / 4]; \n
vec4 stopColors[MAX_STOP_COUNT]; \n vec4 stopColors[MAX_STOP_COUNT]; \n
} uGradientInfo ; \n } uGradientInfo ; \n
); );
std::string STR_RADIAL_GRADIENT_MAIN = TVG_COMPOSE_SHADER( std::string STR_RADIAL_GRADIENT_MAIN = TVG_COMPOSE_SHADER(
out vec4 FragColor; \n out vec4 FragColor; \n
void main() \n void main() \n
{ \n { \n
vec2 pos = vPos; \n vec2 pos = vPos; \n
\n float ba = uGradientInfo.radius.x; \n
float ba = uGradientInfo.radius.x; \n float d = distance(uGradientInfo.centerPos, pos); \n
float d = distance(uGradientInfo.centerPos, pos); \n float t = (d / ba); \n
float t = (d / ba); \n t = gradientWrap(t); \n
\n vec4 color = gradient(t, (d / ba), d); \n
t = gradientWrap(t); \n FragColor = vec4(color.rgb * color.a, color.a); \n
\n }
vec4 color = gradient(t, (d / ba), d); \n );
\n
FragColor = vec4(color.rgb * color.a, color.a); \n
});
std::string STR_LINEAR_GRADIENT_FRAG_SHADER = std::string STR_LINEAR_GRADIENT_FRAG_SHADER =
STR_GRADIENT_FRAG_COMMON_VARIABLES + STR_GRADIENT_FRAG_COMMON_VARIABLES +
@ -258,10 +243,10 @@ const char* IMAGE_VERT_SHADER = TVG_COMPOSE_SHADER(
layout (std140) uniform Matrix { \n layout (std140) uniform Matrix { \n
mat4 transform; \n mat4 transform; \n
} uMatrix; \n } uMatrix; \n
\n
out vec2 vUV; \n out vec2 vUV; \n
\n \n
void main() { \n void main() \n
{ \n
vUV = aUV; \n vUV = aUV; \n
vec4 pos = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n vec4 pos = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n
pos.z = uDepth; \n pos.z = uDepth; \n
@ -276,12 +261,12 @@ const char* IMAGE_FRAG_SHADER = TVG_COMPOSE_SHADER(
int opacity; \n int opacity; \n
int dummy; \n int dummy; \n
} uColorInfo; \n } uColorInfo; \n
\n
uniform sampler2D uTexture; \n uniform sampler2D uTexture; \n
in vec2 vUV; \n in vec2 vUV; \n
out vec4 FragColor; \n out vec4 FragColor; \n
\n \n
void main() { \n void main() \n
{ \n
vec2 uv = vUV; \n vec2 uv = vUV; \n
if (uColorInfo.flipY == 1) { uv.y = 1.0 - uv.y; } \n if (uColorInfo.flipY == 1) { uv.y = 1.0 - uv.y; } \n
vec4 color = texture(uTexture, uv); \n vec4 color = texture(uTexture, uv); \n
@ -295,211 +280,187 @@ const char* IMAGE_FRAG_SHADER = TVG_COMPOSE_SHADER(
} else if (uColorInfo.format == 3) { /* FMT_ARGB8888S */ \n } else if (uColorInfo.format == 3) { /* FMT_ARGB8888S */ \n
result = vec4(color.bgr * color.a, color.a); \n result = vec4(color.bgr * color.a, color.a); \n
} \n } \n
float opacity = float(uColorInfo.opacity) / 255.0; \n FragColor = result * float(uColorInfo.opacity) / 255.0; \n
FragColor = result * opacity; \n
} \n } \n
); );
const char* MASK_VERT_SHADER = TVG_COMPOSE_SHADER( const char* MASK_VERT_SHADER = TVG_COMPOSE_SHADER(
uniform float uDepth; \n uniform float uDepth; \n
layout(location = 0) in vec2 aLocation; \n layout(location = 0) in vec2 aLocation; \n
layout(location = 1) in vec2 aUV; \n layout(location = 1) in vec2 aUV; \n
\n out vec2 vUV; \n
out vec2 vUV; \n \n
\n void main() \n
void main() { \n { \n
vUV = aUV; \n vUV = aUV; \n
\n gl_Position = vec4(aLocation, uDepth, 1.0); \n
gl_Position = vec4(aLocation, uDepth, 1.0); \n } \n
} \n
); );
const char* MASK_ALPHA_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_ALPHA_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n FragColor = srcColor * maskColor.a; \n
\n } \n
FragColor = srcColor * maskColor.a; \n
} \n
); );
const char* MASK_INV_ALPHA_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_INV_ALPHA_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n FragColor = srcColor *(1.0 - maskColor.a); \n
\n } \n
FragColor = srcColor *(1.0 - maskColor.a); \n
} \n
); );
const char* MASK_LUMA_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_LUMA_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main()
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n \n
\n if (maskColor.a > 0.000001) { \n
if (maskColor.a > 0.000001) { \n maskColor = vec4(maskColor.rgb / maskColor.a, maskColor.a); \n
maskColor = vec4(maskColor.rgb / maskColor.a, maskColor.a); \n } \n
} \n \n
\n FragColor = srcColor * (0.299 * maskColor.r + 0.587 * maskColor.g + 0.114 * maskColor.b) * maskColor.a; \n
FragColor = \n } \n
srcColor * (0.299 * maskColor.r + 0.587 * maskColor.g + 0.114 * maskColor.b) * maskColor.a; \n
} \n
); );
const char* MASK_INV_LUMA_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_INV_LUMA_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n float luma = (0.299 * maskColor.r + 0.587 * maskColor.g + 0.114 * maskColor.b); \n
\n FragColor = srcColor * (1.0 - luma); \n
float luma = (0.299 * maskColor.r + 0.587 * maskColor.g + 0.114 * maskColor.b); \n } \n
FragColor = srcColor * (1.0 - luma); \n
} \n
); );
const char* MASK_ADD_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_ADD_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n vec4 color = srcColor + maskColor * (1.0 - srcColor.a); \n
\n FragColor = min(color, vec4(1.0, 1.0, 1.0, 1.0)) ; \n
vec4 color = srcColor + maskColor * (1.0 - srcColor.a); \n } \n
\n
FragColor = min(color, vec4(1.0, 1.0, 1.0, 1.0)) ; \n
} \n
); );
const char* MASK_SUB_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_SUB_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n float a = srcColor.a - maskColor.a; \n
float a = srcColor.a - maskColor.a; \n \n
\n if (a < 0.0 || srcColor.a == 0.0) { \n
if (a < 0.0 || srcColor.a == 0.0) { \n FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n
FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n } else { \n
} else { \n vec3 srcRgb = srcColor.rgb / srcColor.a; \n
vec3 srcRgb = srcColor.rgb / srcColor.a; \n FragColor = vec4(srcRgb * a, a); \n
FragColor = vec4(srcRgb * a, a); \n } \n
} \n } \n
} \n
); );
const char* MASK_INTERSECT_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_INTERSECT_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n FragColor = maskColor * srcColor.a; \n
\n } \n
\n
FragColor = maskColor * srcColor.a; \n
} \n
); );
const char* MASK_DIFF_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_DIFF_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n float da = srcColor.a - maskColor.a; \n
\n if (da == 0.0) { \n
float da = srcColor.a - maskColor.a; \n FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n
\n } else if (da > 0.0) { \n
if (da == 0.0) { \n FragColor = srcColor * da; \n
FragColor = vec4(0.0, 0.0, 0.0, 0.0); \n } else { \n
} else if (da > 0.0) { \n FragColor = maskColor * (-da); \n
FragColor = srcColor * da; \n } \n
} else { \n } \n
FragColor = maskColor * (-da); \n
} \n
} \n
); );
const char* MASK_DARKEN_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_DARKEN_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n if (srcColor.a > 0.0) srcColor.rgb /= srcColor.a; \n
if (srcColor.a > 0.0) srcColor.rgb /= srcColor.a; \n float alpha = min(srcColor.a, maskColor.a); \n
float alpha = min(srcColor.a, maskColor.a); \n FragColor = vec4(srcColor.rgb * alpha, alpha); \n
\n } \n
FragColor = vec4(srcColor.rgb * alpha, alpha); \n
} \n
); );
const char* MASK_LIGHTEN_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* MASK_LIGHTEN_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
uniform sampler2D uMaskTexture; \n uniform sampler2D uMaskTexture; \n
\n in vec2 vUV; \n
in vec2 vUV; \n out vec4 FragColor; \n
\n \n
out vec4 FragColor; \n void main() \n
\n { \n
void main() { \n vec4 srcColor = texture(uSrcTexture, vUV); \n
vec4 srcColor = texture(uSrcTexture, vUV); \n vec4 maskColor = texture(uMaskTexture, vUV); \n
vec4 maskColor = texture(uMaskTexture, vUV); \n if (srcColor.a > 0.0) srcColor.rgb /= srcColor.a; \n
if (srcColor.a > 0.0) srcColor.rgb /= srcColor.a; \n float alpha = max(srcColor.a, maskColor.a); \n
float alpha = max(srcColor.a, maskColor.a); \n FragColor = vec4(srcColor.rgb * alpha, alpha); \n
\n } \n
FragColor = vec4(srcColor.rgb * alpha, alpha); \n
} \n
); );
const char* STENCIL_VERT_SHADER = TVG_COMPOSE_SHADER( const char* STENCIL_VERT_SHADER = TVG_COMPOSE_SHADER(
@ -508,6 +469,7 @@ const char* STENCIL_VERT_SHADER = TVG_COMPOSE_SHADER(
layout(std140) uniform Matrix { \n layout(std140) uniform Matrix { \n
mat4 transform; \n mat4 transform; \n
} uMatrix; \n } uMatrix; \n
\n
void main() \n void main() \n
{ \n { \n
vec4 pos = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n vec4 pos = uMatrix.transform * vec4(aLocation, 0.0, 1.0); \n
@ -517,14 +479,20 @@ const char* STENCIL_VERT_SHADER = TVG_COMPOSE_SHADER(
const char* STENCIL_FRAG_SHADER = TVG_COMPOSE_SHADER( const char* STENCIL_FRAG_SHADER = TVG_COMPOSE_SHADER(
out vec4 FragColor; \n out vec4 FragColor; \n
void main() { FragColor = vec4(0.0); } \n \n
void main() \n
{ \n
FragColor = vec4(0.0); \n
} \n
); );
const char* BLIT_VERT_SHADER = TVG_COMPOSE_SHADER( const char* BLIT_VERT_SHADER = TVG_COMPOSE_SHADER(
layout(location = 0) in vec2 aLocation; \n layout(location = 0) in vec2 aLocation; \n
layout(location = 1) in vec2 aUV; \n layout(location = 1) in vec2 aUV; \n
out vec2 vUV; \n out vec2 vUV; \n
void main() { \n \n
void main() \n
{ \n
vUV = aUV; \n vUV = aUV; \n
gl_Position = vec4(aLocation, 0.0, 1.0); \n gl_Position = vec4(aLocation, 0.0, 1.0); \n
} }
@ -534,7 +502,9 @@ const char* BLIT_FRAG_SHADER = TVG_COMPOSE_SHADER(
uniform sampler2D uSrcTexture; \n uniform sampler2D uSrcTexture; \n
in vec2 vUV; \n in vec2 vUV; \n
out vec4 FragColor; \n out vec4 FragColor; \n
void main() { \n \n
void main() \n
{ \n
FragColor = texture(uSrcTexture, vUV); \n FragColor = texture(uSrcTexture, vUV); \n
} }
); );
@ -548,7 +518,8 @@ const char* BLIT_FRAG_SHADER = TVG_COMPOSE_SHADER(
)" )"
const char* MULTIPLY_BLEND_FRAG = COMPLEX_BLEND_HEADER R"( const char* MULTIPLY_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
void main() { void main()
{
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);
FragColor = srcColor * dstColor; FragColor = srcColor * dstColor;
@ -556,13 +527,15 @@ const char* MULTIPLY_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
)"; )";
#define SCREEN_BLEND_FUNC R"( \ #define SCREEN_BLEND_FUNC R"( \
vec4 screenBlend(vec4 srcColor, vec4 dstColor) { \ vec4 screenBlend(vec4 srcColor, vec4 dstColor) \
{ \
return dstColor + srcColor - (dstColor * srcColor); \ return dstColor + srcColor - (dstColor * srcColor); \
} \ } \
)" )"
#define HARD_LIGHT_BLEND_FUNC R"( \ #define HARD_LIGHT_BLEND_FUNC R"( \
vec4 hardLightBlend(vec4 srcColor, vec4 dstColor) { \ vec4 hardLightBlend(vec4 srcColor, vec4 dstColor) \
{ \
return vec4(srcColor.r < 0.5 ? 2.0 * srcColor.r * dstColor.r : 1.0 - 2.0 * (1.0 - srcColor.r) * (1.0 - dstColor.r), \ return vec4(srcColor.r < 0.5 ? 2.0 * srcColor.r * dstColor.r : 1.0 - 2.0 * (1.0 - srcColor.r) * (1.0 - dstColor.r), \
srcColor.g < 0.5 ? 2.0 * srcColor.g * dstColor.g : 1.0 - 2.0 * (1.0 - srcColor.g) * (1.0 - dstColor.g), \ srcColor.g < 0.5 ? 2.0 * srcColor.g * dstColor.g : 1.0 - 2.0 * (1.0 - srcColor.g) * (1.0 - dstColor.g), \
srcColor.b < 0.5 ? 2.0 * srcColor.b * dstColor.b : 1.0 - 2.0 * (1.0 - srcColor.b) * (1.0 - dstColor.b), \ srcColor.b < 0.5 ? 2.0 * srcColor.b * dstColor.b : 1.0 - 2.0 * (1.0 - srcColor.b) * (1.0 - dstColor.b), \
@ -571,14 +544,16 @@ const char* MULTIPLY_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
)" )"
#define SOFT_LIGHT_BLEND_FUNC R"( \ #define SOFT_LIGHT_BLEND_FUNC R"( \
float softLightD(float v) { \ float softLightD(float v) \
{ \
if (v <= 0.25) return ((16.0 * v - 12.0) * v + 4.0) * v; \ if (v <= 0.25) return ((16.0 * v - 12.0) * v + 4.0) * v; \
else return sqrt(v); \ else return sqrt(v); \
} \ } \
)" )"
const char* SCREEN_BLEND_FRAG = COMPLEX_BLEND_HEADER SCREEN_BLEND_FUNC R"( const char* SCREEN_BLEND_FRAG = COMPLEX_BLEND_HEADER SCREEN_BLEND_FUNC R"(
void main() { void main()
{
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);
FragColor = screenBlend(srcColor, dstColor); FragColor = screenBlend(srcColor, dstColor);
@ -586,7 +561,8 @@ const char* SCREEN_BLEND_FRAG = COMPLEX_BLEND_HEADER SCREEN_BLEND_FUNC R"(
)"; )";
const char* OVERLAY_BLEND_FRAG = COMPLEX_BLEND_HEADER HARD_LIGHT_BLEND_FUNC R"( const char* OVERLAY_BLEND_FRAG = COMPLEX_BLEND_HEADER HARD_LIGHT_BLEND_FUNC R"(
void main() { void main()
{
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);
FragColor = hardLightBlend(dstColor, srcColor); FragColor = hardLightBlend(dstColor, srcColor);
@ -597,7 +573,6 @@ const char* COLOR_DODGE_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
void main() { void main() {
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);
float opacity = srcColor.a; float opacity = srcColor.a;
srcColor *= 255.0; srcColor *= 255.0;
@ -614,10 +589,10 @@ const char* COLOR_DODGE_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
)"; )";
const char* COLOR_BURN_BLEND_FRAG = COMPLEX_BLEND_HEADER R"( const char* COLOR_BURN_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
void main() { void main()
{
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);
float opacity = srcColor.a; float opacity = srcColor.a;
if (srcColor.a > 0.0) srcColor.rgb /= srcColor.a; if (srcColor.a > 0.0) srcColor.rgb /= srcColor.a;
@ -635,7 +610,8 @@ const char* COLOR_BURN_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
)"; )";
const char* HARD_LIGHT_BLEND_FRAG = COMPLEX_BLEND_HEADER HARD_LIGHT_BLEND_FUNC R"( const char* HARD_LIGHT_BLEND_FRAG = COMPLEX_BLEND_HEADER HARD_LIGHT_BLEND_FUNC R"(
void main() { void main()
{
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);
FragColor = hardLightBlend(srcColor, dstColor); FragColor = hardLightBlend(srcColor, dstColor);
@ -643,7 +619,8 @@ const char* HARD_LIGHT_BLEND_FRAG = COMPLEX_BLEND_HEADER HARD_LIGHT_BLEND_FUNC R
)"; )";
const char* SOFT_LIGHT_BLEND_FRAG = COMPLEX_BLEND_HEADER SOFT_LIGHT_BLEND_FUNC R"( const char* SOFT_LIGHT_BLEND_FRAG = COMPLEX_BLEND_HEADER SOFT_LIGHT_BLEND_FUNC R"(
void main() { void main()
{
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);
@ -657,7 +634,8 @@ const char* SOFT_LIGHT_BLEND_FRAG = COMPLEX_BLEND_HEADER SOFT_LIGHT_BLEND_FUNC R
)"; )";
const char* DIFFERENCE_BLEND_FRAG = COMPLEX_BLEND_HEADER R"( const char* DIFFERENCE_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
void main() { void main()
{
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);
@ -666,7 +644,8 @@ const char* DIFFERENCE_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
)"; )";
const char* EXCLUSION_BLEND_FRAG = COMPLEX_BLEND_HEADER R"( const char* EXCLUSION_BLEND_FRAG = COMPLEX_BLEND_HEADER R"(
void main() { void main()
{
vec4 srcColor = texture(uSrcTexture, vUV); vec4 srcColor = texture(uSrcTexture, vUV);
vec4 dstColor = texture(uDstTexture, vUV); vec4 dstColor = texture(uDstTexture, vUV);