Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5532: Use the stage texture transform matrix to set up the shader pass
  • Loading branch information
codereader committed Mar 19, 2021
1 parent 67a5348 commit 55f65f6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 56 deletions.
55 changes: 1 addition & 54 deletions radiantcore/rendersystem/backend/OpenGLShaderPass.cpp
Expand Up @@ -155,60 +155,7 @@ void OpenGLShaderPass::setupTextureMatrix(GLenum textureUnit, const IShaderLayer

if (stage)
{
static const Matrix4 transMinusHalf = Matrix4::getTranslation(Vector3(-0.5f, -0.5f, 0));
static const Matrix4 transPlusHalf = Matrix4::getTranslation(Vector3(+0.5f, +0.5f, 0));

Matrix4 tex = Matrix4::getIdentity();

Vector2 scale = stage->getScale();

if (stage->getStageFlags() & IShaderLayer::FLAG_CENTERSCALE)
{
// Center scale, apply translation by -0.5 first, then scale, then translate back
tex.multiplyBy(transMinusHalf);
tex.multiplyBy(Matrix4::getScale(Vector3(scale.x(), scale.y(), 1)));
tex.multiplyBy(transPlusHalf);
}
else
{
// Regular scale, apply translation and scale
tex.multiplyBy(Matrix4::getScale(Vector3(scale.x(), scale.y(), 1)));
}

Vector2 shear = stage->getShear();

if (shear.x() != 0 || shear.y() != 0)
{
Matrix4 shearMatrix = Matrix4::byColumns(
1, shear.y(), 0, 0,
shear.x(), 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
);

tex.multiplyBy(transMinusHalf);
tex.multiplyBy(shearMatrix);
tex.multiplyBy(transPlusHalf);
}

// Rotation
float rotate = stage->getRotation();

if (rotate != 0)
{
float angle = rotate * 2 * static_cast<float>(c_pi);

Matrix4 rot = Matrix4::getRotationAboutZ(angle);

tex.multiplyBy(transMinusHalf);
tex.multiplyBy(rot);
tex.multiplyBy(transPlusHalf);
}

// Apply translation as last step
Vector2 translation = stage->getTranslation();
tex.multiplyBy(Matrix4::getTranslation(Vector3(translation.x(), translation.y(), 0)));

auto tex = stage->getTextureTransform();
glLoadMatrixd(tex);
}
else
Expand Down
18 changes: 16 additions & 2 deletions radiantcore/shaders/ExpressionSlots.cpp
Expand Up @@ -12,9 +12,23 @@ ExpressionSlots::ExpressionSlots(Registers& registers) :
}

ExpressionSlots::ExpressionSlots(const ExpressionSlots& other, Registers& registers) :
std::vector<ExpressionSlot>(other), // copy all expression slots
std::vector<ExpressionSlot>(other.size()),
_registers(registers)
{}
{
for (auto i = 0; i < other.size(); ++i)
{
auto& thisSlot = at(i);
auto& otherSlot = other.at(i);

thisSlot.registerIndex = otherSlot.registerIndex;

if (otherSlot.expression)
{
thisSlot.expression = otherSlot.expression->clone();
thisSlot.expression->linkToSpecificRegister(_registers, thisSlot.registerIndex);
}
}
}

void ExpressionSlots::assign(IShaderLayer::Expression::Slot slot, const IShaderExpression::Ptr& newExpression, std::size_t defaultRegisterIndex)
{
Expand Down

0 comments on commit 55f65f6

Please sign in to comment.