Premultiply alpha for billboards.
This commit is contained in:
parent
6bf67523b9
commit
6936f30b36
@ -12,5 +12,5 @@ varying vec2 uv;
|
||||
void main(void)
|
||||
{
|
||||
vec4 color = texture(tex, uv);
|
||||
FragColor = vec4(color.rgb * color.a, color.a);
|
||||
FragColor = vec4(color.rgb, color.a);
|
||||
}
|
||||
|
@ -315,7 +315,7 @@ void resetTextureTable()
|
||||
AlreadyTransformedTexture.clear();
|
||||
}
|
||||
|
||||
void compressTexture(irr::video::ITexture *tex, bool srgb)
|
||||
void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha)
|
||||
{
|
||||
if (AlreadyTransformedTexture.find(tex) != AlreadyTransformedTexture.end())
|
||||
return;
|
||||
@ -338,7 +338,7 @@ void compressTexture(irr::video::ITexture *tex, bool srgb)
|
||||
}
|
||||
|
||||
size_t w = tex->getSize().Width, h = tex->getSize().Height;
|
||||
char *data = new char[w * h * 4];
|
||||
unsigned char *data = new unsigned char[w * h * 4];
|
||||
memcpy(data, tex->lock(), w * h * 4);
|
||||
tex->unlock();
|
||||
unsigned internalFormat, Format;
|
||||
@ -347,6 +347,17 @@ void compressTexture(irr::video::ITexture *tex, bool srgb)
|
||||
else
|
||||
Format = GL_BGR;
|
||||
|
||||
if (premul_alpha)
|
||||
{
|
||||
for (unsigned i = 0; i < w * h; i++)
|
||||
{
|
||||
float alpha = pow(data[4 * i + 3] / 255., 1. / 2.2);
|
||||
data[4 * i] *= alpha;
|
||||
data[4 * i + 1] *= alpha;
|
||||
data[4 * i + 2] *= alpha;
|
||||
}
|
||||
}
|
||||
|
||||
if (!UserConfigParams::m_texture_compression)
|
||||
{
|
||||
if (srgb)
|
||||
|
@ -181,7 +181,7 @@ public:
|
||||
GLuint getTextureGLuint(irr::video::ITexture *tex);
|
||||
GLuint getDepthTexture(irr::video::ITexture *tex);
|
||||
void resetTextureTable();
|
||||
void compressTexture(irr::video::ITexture *tex, bool srgb);
|
||||
void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha = false);
|
||||
bool loadCompressedTexture(const std::string& compressed_tex);
|
||||
void saveCompressedTexture(const std::string& compressed_tex);
|
||||
void blitFBO(GLuint Src, GLuint Dst, size_t width, size_t height);
|
||||
|
@ -35,7 +35,7 @@ void STKBillboard::render()
|
||||
core::vector3df pos = getAbsolutePosition();
|
||||
glBindVertexArray(billboardvao);
|
||||
video::ITexture *tex = Material.getTexture(0);
|
||||
compressTexture(tex, true);
|
||||
compressTexture(tex, true, true);
|
||||
GLuint texid = getTextureGLuint(tex);
|
||||
setTexture(0, texid, GL_LINEAR, GL_LINEAR);
|
||||
glUseProgram(MeshShader::BillboardShader::Program);
|
||||
|
Loading…
Reference in New Issue
Block a user