Optimized shader code
This commit is contained in:
parent
61ce682270
commit
c580104d81
|
@ -3,6 +3,10 @@
|
|||
in vec2 uvCoordinates;
|
||||
in vec2 paintUVCoordinates;
|
||||
|
||||
flat in float paintGradientAngleCos;
|
||||
flat in float paintGradientAngleSin;
|
||||
flat in float[2] paintGradientEndsUnrotated;
|
||||
|
||||
uniform sampler2DRect textureSampler;
|
||||
|
||||
uniform int paintType;
|
||||
|
@ -35,20 +39,23 @@ vec4 gammaMix(vec4 lCol, vec4 rCol, float ratio)
|
|||
|
||||
vec4 gradientColor(void)
|
||||
{
|
||||
float angle = atan(-paintGradientEnds[1].y + paintGradientEnds[0].y, paintGradientEnds[1].x - paintGradientEnds[0].x);
|
||||
float rotatedStartX = paintGradientEnds[0].x * cos(angle) - paintGradientEnds[0].y * sin(angle);
|
||||
float rotatedEndX = paintGradientEnds[1].x * cos(angle) - paintGradientEnds[1].y * sin(angle);
|
||||
float d = rotatedEndX - rotatedStartX;
|
||||
float tStart = paintGradientEndsUnrotated[0];
|
||||
float gradientLength = paintGradientEndsUnrotated[1] - tStart;
|
||||
|
||||
float pX = paintUVCoordinates.x * cos(angle) - paintUVCoordinates.y * sin(angle);
|
||||
float t = paintUVCoordinates.x * paintGradientAngleCos - paintUVCoordinates.y * paintGradientAngleSin;
|
||||
|
||||
float mr = smoothstep(rotatedStartX + paintGradientPositions[0] * d, rotatedStartX + paintGradientPositions[1] * d, pX);
|
||||
vec4 col = gammaMix(paintGradientColors[0], paintGradientColors[1], mr);
|
||||
float ti = paintGradientPositions[0] * gradientLength;
|
||||
float tni;
|
||||
vec4 col = paintGradientColors[0];
|
||||
|
||||
for (int i = 1; i < paintGradientStopCount - 1; i++)
|
||||
for (int i = 0; i < paintGradientStopCount - 1; i++)
|
||||
{
|
||||
mr = smoothstep(rotatedStartX + paintGradientPositions[i] * d, rotatedStartX + paintGradientPositions[i + 1] * d, pX);
|
||||
col = gammaMix(col, paintGradientColors[i + 1], mr);
|
||||
tni = paintGradientPositions[i + 1] * gradientLength;
|
||||
|
||||
float mixValue = smoothstep(tStart + ti, tStart + tni, t);
|
||||
col = gammaMix(col, paintGradientColors[i + 1], mixValue);
|
||||
|
||||
ti = tni;
|
||||
}
|
||||
|
||||
return col;
|
||||
|
|
|
@ -4,6 +4,10 @@ in vec2 uvCoordinates;
|
|||
flat in int atlasPage;
|
||||
in vec2 paintUVCoordinates;
|
||||
|
||||
flat in float paintGradientAngleCos;
|
||||
flat in float paintGradientAngleSin;
|
||||
flat in float[2] paintGradientEndsUnrotated;
|
||||
|
||||
uniform sampler2DArray textureSampler;
|
||||
|
||||
uniform int paintType;
|
||||
|
@ -38,20 +42,23 @@ vec4 gammaMix(vec4 lCol, vec4 rCol, float ratio)
|
|||
|
||||
vec4 gradientColor(void)
|
||||
{
|
||||
float angle = atan(-paintGradientEnds[1].y + paintGradientEnds[0].y, paintGradientEnds[1].x - paintGradientEnds[0].x);
|
||||
float rotatedStartX = paintGradientEnds[0].x * cos(angle) - paintGradientEnds[0].y * sin(angle);
|
||||
float rotatedEndX = paintGradientEnds[1].x * cos(angle) - paintGradientEnds[1].y * sin(angle);
|
||||
float d = rotatedEndX - rotatedStartX;
|
||||
float tStart = paintGradientEndsUnrotated[0];
|
||||
float gradientLength = paintGradientEndsUnrotated[1] - tStart;
|
||||
|
||||
float pX = paintUVCoordinates.x * cos(angle) - paintUVCoordinates.y * sin(angle);
|
||||
float t = paintUVCoordinates.x * paintGradientAngleCos - paintUVCoordinates.y * paintGradientAngleSin;
|
||||
|
||||
float mr = smoothstep(rotatedStartX + paintGradientPositions[0] * d, rotatedStartX + paintGradientPositions[1] * d, pX);
|
||||
vec4 col = gammaMix(paintGradientColors[0], paintGradientColors[1], mr);
|
||||
float ti = paintGradientPositions[0] * gradientLength;
|
||||
float tni;
|
||||
vec4 col = paintGradientColors[0];
|
||||
|
||||
for (int i = 1; i < paintGradientStopCount - 1; i++)
|
||||
for (int i = 0; i < paintGradientStopCount - 1; i++)
|
||||
{
|
||||
mr = smoothstep(rotatedStartX + paintGradientPositions[i] * d, rotatedStartX + paintGradientPositions[i + 1] * d, pX);
|
||||
col = gammaMix(col, paintGradientColors[i + 1], mr);
|
||||
tni = paintGradientPositions[i + 1] * gradientLength;
|
||||
|
||||
float mixValue = smoothstep(tStart + ti, tStart + tni, t);
|
||||
col = gammaMix(col, paintGradientColors[i + 1], mixValue);
|
||||
|
||||
ti = tni;
|
||||
}
|
||||
|
||||
return col;
|
||||
|
|
|
@ -4,6 +4,13 @@ in vec2 position;
|
|||
in vec2 uvCoords;
|
||||
in vec2 paintUVCoords;
|
||||
|
||||
uniform int paintType;
|
||||
|
||||
flat out float paintGradientAngleCos;
|
||||
flat out float paintGradientAngleSin;
|
||||
flat out float[2] paintGradientEndsUnrotated;
|
||||
uniform vec2[2] paintGradientEnds;
|
||||
|
||||
out vec2 uvCoordinates;
|
||||
out vec2 paintUVCoordinates;
|
||||
|
||||
|
@ -15,5 +22,18 @@ void main(void)
|
|||
uvCoordinates = uvCoords;
|
||||
paintUVCoordinates = paintUVCoords;
|
||||
vec3 transformed = vec3((transformation * vec3(position, 1.0)).xy, 0.0);
|
||||
|
||||
if (paintType == 1)
|
||||
{
|
||||
float dy = paintGradientEnds[1].y - paintGradientEnds[0].y;
|
||||
float dx = paintGradientEnds[1].x - paintGradientEnds[0].x;
|
||||
float paintGradientAngle = atan(-dy, dx);
|
||||
paintGradientAngleCos = cos(paintGradientAngle);
|
||||
paintGradientAngleSin = sin(paintGradientAngle);
|
||||
|
||||
paintGradientEndsUnrotated[0] = paintGradientEnds[0].x * paintGradientAngleCos - paintGradientEnds[0].y * paintGradientAngleSin;
|
||||
paintGradientEndsUnrotated[1] = paintGradientEnds[1].x * paintGradientAngleCos - paintGradientEnds[1].y * paintGradientAngleSin;
|
||||
}
|
||||
|
||||
gl_Position = projection * vec4(transformed, 1.0);
|
||||
}
|
|
@ -5,6 +5,13 @@ in vec2 uvCoords;
|
|||
in int page;
|
||||
in vec2 paintUVCoords;
|
||||
|
||||
uniform int paintType;
|
||||
|
||||
flat out float paintGradientAngleCos;
|
||||
flat out float paintGradientAngleSin;
|
||||
flat out float[2] paintGradientEndsUnrotated;
|
||||
uniform vec2[2] paintGradientEnds;
|
||||
|
||||
out vec2 uvCoordinates;
|
||||
out vec2 paintUVCoordinates;
|
||||
flat out int atlasPage;
|
||||
|
@ -18,5 +25,18 @@ void main(void)
|
|||
uvCoordinates = uvCoords;
|
||||
paintUVCoordinates = paintUVCoords;
|
||||
vec3 transformed = vec3((transformation * vec3(position, 1.0)).xy, 0.0);
|
||||
|
||||
if (paintType == 1)
|
||||
{
|
||||
float dy = paintGradientEnds[1].y - paintGradientEnds[0].y;
|
||||
float dx = paintGradientEnds[1].x - paintGradientEnds[0].x;
|
||||
float paintGradientAngle = atan(-dy, dx);
|
||||
paintGradientAngleCos = cos(paintGradientAngle);
|
||||
paintGradientAngleSin = sin(paintGradientAngle);
|
||||
|
||||
paintGradientEndsUnrotated[0] = paintGradientEnds[0].x * paintGradientAngleCos - paintGradientEnds[0].y * paintGradientAngleSin;
|
||||
paintGradientEndsUnrotated[1] = paintGradientEnds[1].x * paintGradientAngleCos - paintGradientEnds[1].y * paintGradientAngleSin;
|
||||
}
|
||||
|
||||
gl_Position = projection * vec4(transformed, 1.0);
|
||||
}
|
27
engine-demo/jsr-clone/mods/tefek.plutogui/default/shaders/FragmentBitmapFontShader.glsl
Normal file → Executable file
27
engine-demo/jsr-clone/mods/tefek.plutogui/default/shaders/FragmentBitmapFontShader.glsl
Normal file → Executable file
|
@ -3,6 +3,10 @@
|
|||
in vec2 uvCoordinates;
|
||||
in vec2 paintUVCoordinates;
|
||||
|
||||
flat in float paintGradientAngleCos;
|
||||
flat in float paintGradientAngleSin;
|
||||
flat in float[2] paintGradientEndsUnrotated;
|
||||
|
||||
uniform sampler2DRect textureSampler;
|
||||
|
||||
uniform int paintType;
|
||||
|
@ -35,20 +39,23 @@ vec4 gammaMix(vec4 lCol, vec4 rCol, float ratio)
|
|||
|
||||
vec4 gradientColor(void)
|
||||
{
|
||||
float angle = atan(-paintGradientEnds[1].y + paintGradientEnds[0].y, paintGradientEnds[1].x - paintGradientEnds[0].x);
|
||||
float rotatedStartX = paintGradientEnds[0].x * cos(angle) - paintGradientEnds[0].y * sin(angle);
|
||||
float rotatedEndX = paintGradientEnds[1].x * cos(angle) - paintGradientEnds[1].y * sin(angle);
|
||||
float d = rotatedEndX - rotatedStartX;
|
||||
float tStart = paintGradientEndsUnrotated[0];
|
||||
float gradientLength = paintGradientEndsUnrotated[1] - tStart;
|
||||
|
||||
float pX = paintUVCoordinates.x * cos(angle) - paintUVCoordinates.y * sin(angle);
|
||||
float t = paintUVCoordinates.x * paintGradientAngleCos - paintUVCoordinates.y * paintGradientAngleSin;
|
||||
|
||||
float mr = smoothstep(rotatedStartX + paintGradientPositions[0] * d, rotatedStartX + paintGradientPositions[1] * d, pX);
|
||||
vec4 col = gammaMix(paintGradientColors[0], paintGradientColors[1], mr);
|
||||
float ti = paintGradientPositions[0] * gradientLength;
|
||||
float tni;
|
||||
vec4 col = paintGradientColors[0];
|
||||
|
||||
for (int i = 1; i < paintGradientStopCount - 1; i++)
|
||||
for (int i = 0; i < paintGradientStopCount - 1; i++)
|
||||
{
|
||||
mr = smoothstep(rotatedStartX + paintGradientPositions[i] * d, rotatedStartX + paintGradientPositions[i + 1] * d, pX);
|
||||
col = gammaMix(col, paintGradientColors[i + 1], mr);
|
||||
tni = paintGradientPositions[i + 1] * gradientLength;
|
||||
|
||||
float mixValue = smoothstep(tStart + ti, tStart + tni, t);
|
||||
col = gammaMix(col, paintGradientColors[i + 1], mixValue);
|
||||
|
||||
ti = tni;
|
||||
}
|
||||
|
||||
return col;
|
||||
|
|
27
engine-demo/jsr-clone/mods/tefek.plutogui/default/shaders/FragmentFontShader.glsl
Normal file → Executable file
27
engine-demo/jsr-clone/mods/tefek.plutogui/default/shaders/FragmentFontShader.glsl
Normal file → Executable file
|
@ -4,6 +4,10 @@ in vec2 uvCoordinates;
|
|||
flat in int atlasPage;
|
||||
in vec2 paintUVCoordinates;
|
||||
|
||||
flat in float paintGradientAngleCos;
|
||||
flat in float paintGradientAngleSin;
|
||||
flat in float[2] paintGradientEndsUnrotated;
|
||||
|
||||
uniform sampler2DArray textureSampler;
|
||||
|
||||
uniform int paintType;
|
||||
|
@ -38,20 +42,23 @@ vec4 gammaMix(vec4 lCol, vec4 rCol, float ratio)
|
|||
|
||||
vec4 gradientColor(void)
|
||||
{
|
||||
float angle = atan(-paintGradientEnds[1].y + paintGradientEnds[0].y, paintGradientEnds[1].x - paintGradientEnds[0].x);
|
||||
float rotatedStartX = paintGradientEnds[0].x * cos(angle) - paintGradientEnds[0].y * sin(angle);
|
||||
float rotatedEndX = paintGradientEnds[1].x * cos(angle) - paintGradientEnds[1].y * sin(angle);
|
||||
float d = rotatedEndX - rotatedStartX;
|
||||
float tStart = paintGradientEndsUnrotated[0];
|
||||
float gradientLength = paintGradientEndsUnrotated[1] - tStart;
|
||||
|
||||
float pX = paintUVCoordinates.x * cos(angle) - paintUVCoordinates.y * sin(angle);
|
||||
float t = paintUVCoordinates.x * paintGradientAngleCos - paintUVCoordinates.y * paintGradientAngleSin;
|
||||
|
||||
float mr = smoothstep(rotatedStartX + paintGradientPositions[0] * d, rotatedStartX + paintGradientPositions[1] * d, pX);
|
||||
vec4 col = gammaMix(paintGradientColors[0], paintGradientColors[1], mr);
|
||||
float ti = paintGradientPositions[0] * gradientLength;
|
||||
float tni;
|
||||
vec4 col = paintGradientColors[0];
|
||||
|
||||
for (int i = 1; i < paintGradientStopCount - 1; i++)
|
||||
for (int i = 0; i < paintGradientStopCount - 1; i++)
|
||||
{
|
||||
mr = smoothstep(rotatedStartX + paintGradientPositions[i] * d, rotatedStartX + paintGradientPositions[i + 1] * d, pX);
|
||||
col = gammaMix(col, paintGradientColors[i + 1], mr);
|
||||
tni = paintGradientPositions[i + 1] * gradientLength;
|
||||
|
||||
float mixValue = smoothstep(tStart + ti, tStart + tni, t);
|
||||
col = gammaMix(col, paintGradientColors[i + 1], mixValue);
|
||||
|
||||
ti = tni;
|
||||
}
|
||||
|
||||
return col;
|
||||
|
|
20
engine-demo/jsr-clone/mods/tefek.plutogui/default/shaders/VertexBitmapFontShader.glsl
Normal file → Executable file
20
engine-demo/jsr-clone/mods/tefek.plutogui/default/shaders/VertexBitmapFontShader.glsl
Normal file → Executable file
|
@ -4,6 +4,13 @@ in vec2 position;
|
|||
in vec2 uvCoords;
|
||||
in vec2 paintUVCoords;
|
||||
|
||||
uniform int paintType;
|
||||
|
||||
flat out float paintGradientAngleCos;
|
||||
flat out float paintGradientAngleSin;
|
||||
flat out float[2] paintGradientEndsUnrotated;
|
||||
uniform vec2[2] paintGradientEnds;
|
||||
|
||||
out vec2 uvCoordinates;
|
||||
out vec2 paintUVCoordinates;
|
||||
|
||||
|
@ -15,5 +22,18 @@ void main(void)
|
|||
uvCoordinates = uvCoords;
|
||||
paintUVCoordinates = paintUVCoords;
|
||||
vec3 transformed = vec3((transformation * vec3(position, 1.0)).xy, 0.0);
|
||||
|
||||
if (paintType == 1)
|
||||
{
|
||||
float dy = paintGradientEnds[1].y - paintGradientEnds[0].y;
|
||||
float dx = paintGradientEnds[1].x - paintGradientEnds[0].x;
|
||||
float paintGradientAngle = atan(-dy, dx);
|
||||
paintGradientAngleCos = cos(paintGradientAngle);
|
||||
paintGradientAngleSin = sin(paintGradientAngle);
|
||||
|
||||
paintGradientEndsUnrotated[0] = paintGradientEnds[0].x * paintGradientAngleCos - paintGradientEnds[0].y * paintGradientAngleSin;
|
||||
paintGradientEndsUnrotated[1] = paintGradientEnds[1].x * paintGradientAngleCos - paintGradientEnds[1].y * paintGradientAngleSin;
|
||||
}
|
||||
|
||||
gl_Position = projection * vec4(transformed, 1.0);
|
||||
}
|
20
engine-demo/jsr-clone/mods/tefek.plutogui/default/shaders/VertexFontShader.glsl
Normal file → Executable file
20
engine-demo/jsr-clone/mods/tefek.plutogui/default/shaders/VertexFontShader.glsl
Normal file → Executable file
|
@ -5,6 +5,13 @@ in vec2 uvCoords;
|
|||
in int page;
|
||||
in vec2 paintUVCoords;
|
||||
|
||||
uniform int paintType;
|
||||
|
||||
flat out float paintGradientAngleCos;
|
||||
flat out float paintGradientAngleSin;
|
||||
flat out float[2] paintGradientEndsUnrotated;
|
||||
uniform vec2[2] paintGradientEnds;
|
||||
|
||||
out vec2 uvCoordinates;
|
||||
out vec2 paintUVCoordinates;
|
||||
flat out int atlasPage;
|
||||
|
@ -18,5 +25,18 @@ void main(void)
|
|||
uvCoordinates = uvCoords;
|
||||
paintUVCoordinates = paintUVCoords;
|
||||
vec3 transformed = vec3((transformation * vec3(position, 1.0)).xy, 0.0);
|
||||
|
||||
if (paintType == 1)
|
||||
{
|
||||
float dy = paintGradientEnds[1].y - paintGradientEnds[0].y;
|
||||
float dx = paintGradientEnds[1].x - paintGradientEnds[0].x;
|
||||
float paintGradientAngle = atan(-dy, dx);
|
||||
paintGradientAngleCos = cos(paintGradientAngle);
|
||||
paintGradientAngleSin = sin(paintGradientAngle);
|
||||
|
||||
paintGradientEndsUnrotated[0] = paintGradientEnds[0].x * paintGradientAngleCos - paintGradientEnds[0].y * paintGradientAngleSin;
|
||||
paintGradientEndsUnrotated[1] = paintGradientEnds[1].x * paintGradientAngleCos - paintGradientEnds[1].y * paintGradientAngleSin;
|
||||
}
|
||||
|
||||
gl_Position = projection * vec4(transformed, 1.0);
|
||||
}
|
Loading…
Reference in New Issue