NOISSUE fix various skin rendering issues

This commit is contained in:
Petr Mrázek 2025-01-14 01:44:48 +01:00
parent c7bf4fee76
commit 538c943f10
3 changed files with 16 additions and 11 deletions

View File

@ -424,14 +424,12 @@ void Skins::RenderContext::setTextures(const QImage& skin, const QImage& cape)
m_skinTexture = new QOpenGLTexture(skin);
m_skinTexture->setMinificationFilter(QOpenGLTexture::NearestMipMapNearest);
m_skinTexture->setMagnificationFilter(QOpenGLTexture::Nearest);
m_skinShader->setUniformValue(m_uniforms[1].id, 0);
if(!cape.isNull())
{
m_capeTexture = new QOpenGLTexture(cape);
m_capeTexture->setMinificationFilter(QOpenGLTexture::NearestMipMapNearest);
m_capeTexture->setMagnificationFilter(QOpenGLTexture::Nearest);
m_skinShader->setUniformValue(m_uniforms[2].id, 1);
}
m_skinShader->release();
}
@ -480,6 +478,8 @@ void Skins::RenderContext::render(QMatrix4x4 viewMatrix, QVector3D baseColor, QV
GL.glEnable(GL_DEPTH_TEST);
m_skinShader->bind();
m_skinShader->setUniformValue(m_uniforms[0].id, viewMatrix);
m_skinShader->setUniformValue(m_uniforms[1].id, 0);
m_skinShader->setUniformValue(m_uniforms[2].id, 1);
m_skinTexture->bind(0);
if(m_capeTexture)
{

View File

@ -138,11 +138,19 @@ const QImage & SkinData::getListTexture(Model model) const
auto paintFront = [&](int x, int y, const Skins::TextureMapping& part)
{
auto partTexture = texture.copy(part.front.x, part.front.y, part.front.w, part.front.h);
if(!part.transparent)
{
painter.fillRect(x, y, part.front.w, part.front.w, Qt::black);
}
painter.drawImage(x, y, partTexture.mirrored(part.front.flipX, part.front.flipY));
};
auto paintBack = [&](int x, int y, const Skins::TextureMapping& part)
{
auto partTexture = texture.copy(part.back.x, part.back.y, part.back.w, part.back.h);
if(!part.transparent)
{
painter.fillRect(x, y, part.back.w, part.back.w, Qt::black);
}
painter.drawImage(x, y, partTexture.mirrored(part.back.flipX, part.back.flipY));
};
paintFront(4, 2, head);

View File

@ -85,17 +85,14 @@ bool readSkinFromData(const QByteArray& data, QImage& imageOut, QString& texture
return false;
}
imageOut = img;
if(img.hasAlphaChannel())
auto maskOut = img.pixel(0,0);
if(qAlpha(maskOut) == 0xff)
{
textureIDOut = hashSkin(imageOut);
return true;
auto alphaChannel = img.createMaskFromColor(maskOut, Qt::MaskMode::MaskOutColor);
img.setAlphaChannel(alphaChannel);
}
// No alpha channel -> take top left pixel and replace all matching pixels with transparency
auto alphaChannel = imageOut.createMaskFromColor(imageOut.pixel(0,0), Qt::MaskMode::MaskOutColor);
imageOut.setAlphaChannel(alphaChannel);
textureIDOut = hashSkin(imageOut);
textureIDOut = hashSkin(img);
imageOut = img;
return true;
}