Fixed linear gradient rendering in the demo

This commit is contained in:
Natty 2022-04-15 01:56:39 +02:00
parent 6725e24135
commit e3c37c6511
No known key found for this signature in database
GPG Key ID: 40AB22FA416C7019
5 changed files with 32 additions and 13 deletions

View File

@ -1,3 +1,6 @@
## 22.1.0.0-alpha.1
* `plutoengine-demos/basic-application` Made the gradient in the fragment font shader rotatable
## 22.1.0.0-alpha.0
* `[PlutoMesher]` **Partial rewrite**
* *Removed* `VecArray`

View File

@ -23,7 +23,7 @@ object Versions {
const val isPrerelease = true
const val prereleaseName = "alpha"
const val prerealeaseUpdate = 0
const val prerealeaseUpdate = 1
val versionFull =
if (isPrerelease)

View File

@ -23,22 +23,38 @@ 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)
{
float par = smoothstep(paintGradientEnds[0].x, paintGradientEnds[1].x, paintUVCoordinates.x) * (paintGradientStopCount - 1);
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 nPar = clamp(par, 0, float(paintGradientStopCount - 1)) + paintGradientPositions[0] * 0.000001;
vec4 lCol = paintGradientColors[int(floor(nPar))];
vec4 rCol = paintGradientColors[int(ceil(nPar))];
float pX = paintUVCoordinates.x * cos(angle) - paintUVCoordinates.y * sin(angle);
float gamma = 0.45;
float mr = smoothstep(rotatedStartX + paintGradientPositions[0] * d, rotatedStartX + paintGradientPositions[1] * d, pX);
vec4 col = gammaMix(paintGradientColors[0], paintGradientColors[1], mr);
vec4 ilCol = vec4(pow(lCol.r, 1 / gamma), pow(lCol.g, 1 / gamma), pow(lCol.b, 1 / gamma), lCol.a);
vec4 irCol = vec4(pow(rCol.r, 1 / gamma), pow(rCol.g, 1 / gamma), pow(rCol.b, 1 / gamma), rCol.a);
for (int i = 1; i < paintGradientStopCount - 1; i++)
{
mr = smoothstep(rotatedStartX + paintGradientPositions[i] * d, rotatedStartX + paintGradientPositions[i + 1] * d, pX);
col = gammaMix(col, paintGradientColors[i + 1], mr);
}
vec4 fCol = mix(ilCol, irCol, fract(nPar));
return vec4(pow(fCol.r, gamma), pow(fCol.g, gamma), pow(fCol.b, gamma), fCol.a);
return col;
}
void main(void)

View File

@ -65,7 +65,7 @@ public class Main extends PlutoApplication
var watermarkStyle = new TextStyleOptions(20.0f);
watermarkStyle.setHorizontalAlign(TextStyleOptions.TextAlign.CENTER);
watermarkStyle.setPaint(LiPaint.solidColor(Color.from(0x4f000000, EnumColorFormat.CF_INT_ARGB)));
ImmediateFontRenderer.drawString(this.display.getWidth() / 2.0f, 5, "PlutoEngine demo build licensed the MIT license...", BasicApplicationDemoMod.font, watermarkStyle);
ImmediateFontRenderer.drawString(this.display.getWidth() / 2.0f, 5, "PlutoEngine demo build licensed under the MIT license", BasicApplicationDemoMod.font, watermarkStyle);
RectangleRenderer2D.draw()
.at(this.display.getWidth() / 2.0f - 150, this.display.getHeight() / 2.0f - 246, 300, 300)

2
libra

@ -1 +1 @@
Subproject commit 443ab09e71c4ff08184167646fa8b2fe3465986a
Subproject commit 3e0521b1b072f3f87f3ac2131c6849b0624a370f