2022-05-04 00:32:44 +00:00
|
|
|
/*
|
|
|
|
* MIT License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2022 493msi
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2022-04-27 17:24:18 +00:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
in vec2 uvCoordinates;
|
|
|
|
in vec2 paintUVCoordinates;
|
|
|
|
|
2022-04-29 21:57:19 +00:00
|
|
|
flat in float paintGradientAngleCos;
|
|
|
|
flat in float paintGradientAngleSin;
|
|
|
|
flat in float[2] paintGradientEndsUnrotated;
|
|
|
|
|
2022-04-27 17:24:18 +00:00
|
|
|
uniform sampler2DRect textureSampler;
|
|
|
|
|
|
|
|
uniform int paintType;
|
|
|
|
uniform vec4 paintColor;
|
|
|
|
|
|
|
|
uniform int paintGradientStopCount;
|
|
|
|
uniform vec4[16] paintGradientColors;
|
|
|
|
uniform float[16] paintGradientPositions;
|
|
|
|
uniform vec2[2] paintGradientEnds;
|
|
|
|
|
|
|
|
out vec4 out_Color;
|
|
|
|
|
|
|
|
vec4 solidColor(void)
|
|
|
|
{
|
|
|
|
return paintColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4 gammaMix(vec4 lCol, vec4 rCol, float ratio)
|
|
|
|
{
|
|
|
|
float gamma = 2.2;
|
|
|
|
float one_over_gamma = 1 / gamma;
|
|
|
|
|
|
|
|
vec4 ilCol = vec4(pow(lCol.r, gamma), pow(lCol.g, gamma), pow(lCol.b, gamma), lCol.a);
|
|
|
|
vec4 irCol = vec4(pow(rCol.r, gamma), pow(rCol.g, gamma), pow(rCol.b, gamma), rCol.a);
|
|
|
|
|
|
|
|
vec4 fCol = mix(ilCol, irCol, ratio);
|
|
|
|
|
|
|
|
return vec4(pow(fCol.r, one_over_gamma), pow(fCol.g, one_over_gamma), pow(fCol.b, one_over_gamma), fCol.a);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4 gradientColor(void)
|
|
|
|
{
|
2022-04-29 21:57:19 +00:00
|
|
|
float tStart = paintGradientEndsUnrotated[0];
|
|
|
|
float gradientLength = paintGradientEndsUnrotated[1] - tStart;
|
2022-04-27 17:24:18 +00:00
|
|
|
|
2022-04-29 21:57:19 +00:00
|
|
|
float t = paintUVCoordinates.x * paintGradientAngleCos - paintUVCoordinates.y * paintGradientAngleSin;
|
2022-04-27 17:24:18 +00:00
|
|
|
|
2022-04-29 21:57:19 +00:00
|
|
|
float ti = paintGradientPositions[0] * gradientLength;
|
|
|
|
float tni;
|
|
|
|
vec4 col = paintGradientColors[0];
|
2022-04-27 17:24:18 +00:00
|
|
|
|
2022-04-29 21:57:19 +00:00
|
|
|
for (int i = 0; i < paintGradientStopCount - 1; i++)
|
2022-04-27 17:24:18 +00:00
|
|
|
{
|
2022-04-29 21:57:19 +00:00
|
|
|
tni = paintGradientPositions[i + 1] * gradientLength;
|
|
|
|
|
|
|
|
float mixValue = smoothstep(tStart + ti, tStart + tni, t);
|
|
|
|
col = gammaMix(col, paintGradientColors[i + 1], mixValue);
|
|
|
|
|
|
|
|
ti = tni;
|
2022-04-27 17:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
|
|
|
vec4 col;
|
|
|
|
|
|
|
|
switch (paintType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
col = solidColor();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
col = gradientColor();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
col.rgba *= texture(textureSampler, uvCoordinates);
|
|
|
|
|
|
|
|
out_Color = col;
|
|
|
|
}
|