gl_engine: fix radial gradient not render correctly

root cause: the gradient shader not taking into account FillSpread property
This commit is contained in:
RuiwenTang 2024-01-12 10:43:50 +08:00 committed by Hermet Park
parent be65d9d2e5
commit 78b2435596
2 changed files with 12 additions and 0 deletions

View file

@ -568,6 +568,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFla
gradientBlock.nStops[0] = stopCnt * 1.f;
gradientBlock.nStops[1] = NOISE_LEVEL;
gradientBlock.nStops[2] = static_cast<int32_t>(fill->spread()) * 1.f;
for (uint32_t i = 0; i < stopCnt; ++i) {
gradientBlock.stopPoints[i] = stops[i].offset;
gradientBlock.stopColors[i * 4 + 0] = stops[i].r / 255.f;
@ -600,6 +601,7 @@ void GlRenderer::drawPrimitive(GlShape& sdata, const Fill* fill, RenderUpdateFla
gradientBlock.nStops[0] = stopCnt * 1.f;
gradientBlock.nStops[1] = NOISE_LEVEL;
gradientBlock.nStops[2] = static_cast<int32_t>(fill->spread()) * 1.f;
for (uint32_t i = 0; i < stopCnt; ++i) {
gradientBlock.stopPoints[i] = stops[i].offset;
gradientBlock.stopColors[i * 4 + 0] = stops[i].r / 255.f;

View file

@ -90,12 +90,22 @@ float gradientStop(int index)
\n
float gradientWrap(float d) \n
{ \n
int spread = int(uGradientInfo.nStops[2]); \n
\n
if (spread == 0) { /* pad */ \n
return clamp(d, 0.0, 1.0); \n
} \n
\n
int i = 1; \n
while (d > 1.0) { \n
d = d - 1.0; \n
i *= -1; \n
} \n
\n
if (spread == 2) { /* Reflect */ \n
return smoothstep(0.0, 1.0, d); \n
} \n
\n
if (i == 1) \n
return smoothstep(0.0, 1.0, d); \n
else \n