Skip to content

Commit

Permalink
Fix LayerGradient not adapte float4 color format
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Oct 13, 2024
1 parent a5a9938 commit 451752f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
48 changes: 20 additions & 28 deletions core/2d/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,25 @@ void LayerGradient::updateColor()
Color E(_endColor, _endOpacity * opacityf / 255.0f);

// (-1, -1)
_quad.bl.color.r = (E.r + (S.r - E.r) * ((c + u.x + u.y) / (2.0f * c))) * 255;
_quad.bl.color.g = (E.g + (S.g - E.g) * ((c + u.x + u.y) / (2.0f * c))) * 255;
_quad.bl.color.b = (E.b + (S.b - E.b) * ((c + u.x + u.y) / (2.0f * c))) * 255;
_quad.bl.color.a = (E.a + (S.a - E.a) * ((c + u.x + u.y) / (2.0f * c))) * 255;
_quad.bl.color.r = (E.r + (S.r - E.r) * ((c + u.x + u.y) / (2.0f * c)));
_quad.bl.color.g = (E.g + (S.g - E.g) * ((c + u.x + u.y) / (2.0f * c)));
_quad.bl.color.b = (E.b + (S.b - E.b) * ((c + u.x + u.y) / (2.0f * c)));
_quad.bl.color.a = (E.a + (S.a - E.a) * ((c + u.x + u.y) / (2.0f * c)));
// (1, -1)
_quad.br.color.r = (E.r + (S.r - E.r) * ((c - u.x + u.y) / (2.0f * c))) * 255;
_quad.br.color.g = (E.g + (S.g - E.g) * ((c - u.x + u.y) / (2.0f * c))) * 255;
_quad.br.color.b = (E.b + (S.b - E.b) * ((c - u.x + u.y) / (2.0f * c))) * 255;
_quad.br.color.a = (E.a + (S.a - E.a) * ((c - u.x + u.y) / (2.0f * c))) * 255;
_quad.br.color.r = (E.r + (S.r - E.r) * ((c - u.x + u.y) / (2.0f * c)));
_quad.br.color.g = (E.g + (S.g - E.g) * ((c - u.x + u.y) / (2.0f * c)));
_quad.br.color.b = (E.b + (S.b - E.b) * ((c - u.x + u.y) / (2.0f * c)));
_quad.br.color.a = (E.a + (S.a - E.a) * ((c - u.x + u.y) / (2.0f * c)));
// (-1, 1)
_quad.tl.color.r = (E.r + (S.r - E.r) * ((c + u.x - u.y) / (2.0f * c))) * 255;
_quad.tl.color.g = (E.g + (S.g - E.g) * ((c + u.x - u.y) / (2.0f * c))) * 255;
_quad.tl.color.b = (E.b + (S.b - E.b) * ((c + u.x - u.y) / (2.0f * c))) * 255;
_quad.tl.color.a = (E.a + (S.a - E.a) * ((c + u.x - u.y) / (2.0f * c))) * 255;
_quad.tl.color.r = (E.r + (S.r - E.r) * ((c + u.x - u.y) / (2.0f * c)));
_quad.tl.color.g = (E.g + (S.g - E.g) * ((c + u.x - u.y) / (2.0f * c)));
_quad.tl.color.b = (E.b + (S.b - E.b) * ((c + u.x - u.y) / (2.0f * c)));
_quad.tl.color.a = (E.a + (S.a - E.a) * ((c + u.x - u.y) / (2.0f * c)));
// (1, 1)
_quad.tr.color.r = (E.r + (S.r - E.r) * ((c - u.x - u.y) / (2.0f * c))) * 255;
_quad.tr.color.g = (E.g + (S.g - E.g) * ((c - u.x - u.y) / (2.0f * c))) * 255;
_quad.tr.color.b = (E.b + (S.b - E.b) * ((c - u.x - u.y) / (2.0f * c))) * 255;
_quad.tr.color.a = (E.a + (S.a - E.a) * ((c - u.x - u.y) / (2.0f * c))) * 255;
_quad.tr.color.r = (E.r + (S.r - E.r) * ((c - u.x - u.y) / (2.0f * c)));
_quad.tr.color.g = (E.g + (S.g - E.g) * ((c - u.x - u.y) / (2.0f * c)));
_quad.tr.color.b = (E.b + (S.b - E.b) * ((c - u.x - u.y) / (2.0f * c)));
_quad.tr.color.a = (E.a + (S.a - E.a) * ((c - u.x - u.y) / (2.0f * c)));

// renders using batch node
if (_renderMode == RenderMode::QUAD_BATCHNODE)
Expand Down Expand Up @@ -409,10 +409,10 @@ bool LayerRadialGradient::initWithColor(const ax::Color4B& startColor,

if (Node::initLayer())
{
convertColor4B24F(_startColorRend, startColor);
_startColorRend = static_cast<ax::Color>(startColor);
_startColor = startColor;

convertColor4B24F(_endColorRend, endColor);
_endColorRend = static_cast<ax::Color>(endColor);
_endColor = endColor;

_expand = expand;
Expand Down Expand Up @@ -514,7 +514,7 @@ void LayerRadialGradient::setStartColor(const Color3B& color)
void LayerRadialGradient::setStartColor(const ax::Color4B& color)
{
_startColor = color;
convertColor4B24F(_startColorRend, _startColor);
_startColorRend = static_cast<ax::Color>(color);
}

Color4B LayerRadialGradient::getStartColor() const
Expand All @@ -535,7 +535,7 @@ void LayerRadialGradient::setEndColor(const Color3B& color)
void LayerRadialGradient::setEndColor(const ax::Color4B& color)
{
_endColor = color;
convertColor4B24F(_endColorRend, _endColor);
_endColorRend = static_cast<ax::Color>(color);
}

Color4B LayerRadialGradient::getEndColor() const
Expand All @@ -558,14 +558,6 @@ const BlendFunc& LayerRadialGradient::getBlendFunc() const
return _blendFunc;
}

void LayerRadialGradient::convertColor4B24F(Color& outColor, const Color4B& inColor)
{
outColor.r = inColor.r / 255.0f;
outColor.g = inColor.g / 255.0f;
outColor.b = inColor.b / 255.0f;
outColor.a = inColor.a / 255.0f;
}

/// MultiplexLayer

LayerMultiplex::LayerMultiplex() : _enabledLayer(0) {}
Expand Down
2 changes: 0 additions & 2 deletions core/2d/Layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,6 @@ class AX_DLL LayerRadialGradient : public Node, BlendProtocol
float expand);

private:
void convertColor4B24F(Color& outColor, const Color4B& inColor);

Color4B _startColor = Color4B::BLACK;
Color _startColorRend = Color::BLACK; // start color used in shader

Expand Down

0 comments on commit 451752f

Please sign in to comment.