AlphaShader for mapping alpha in pre-render

This commit is contained in:
brunoherbelin
2021-02-22 18:26:00 +01:00
parent ef7722bb5c
commit 27112a2b57
3 changed files with 6 additions and 14 deletions

View File

@@ -8,7 +8,7 @@
#include "ImageShader.h"
ShadingProgram imageShadingProgram("shaders/image.vs", "shaders/image.fs");
ShadingProgram inverseAlphaProgram("shaders/image.vs", "shaders/imageblending.fs");
ShadingProgram imageAlphaProgram ("shaders/image.vs", "shaders/imageblending.fs");
const char* MaskShader::mask_names[3] = { ICON_FA_EXPAND, ICON_FA_EDIT, ICON_FA_SHAPES };
const char* MaskShader::mask_shapes[5] = { "Elipse", "Oblong", "Rectangle", "Horizontal", "Vertical" };
@@ -62,10 +62,10 @@ void ImageShader::accept(Visitor& v) {
}
DivideAlphaShader::DivideAlphaShader(): ImageShader()
AlphaShader::AlphaShader(): ImageShader()
{
// to inverse alpha mode, use dedicated shading program
program_ = &inverseAlphaProgram;
program_ = &imageAlphaProgram;
// reset instance
reset();

View File

@@ -27,11 +27,11 @@ public:
float stipple;
};
class DivideAlphaShader : public ImageShader
class AlphaShader : public ImageShader
{
public:
DivideAlphaShader();
AlphaShader();
};

View File

@@ -22,15 +22,7 @@ void main()
// color texture
vec4 textureColor = texture(iChannel0, texcoord.xy);
vec3 RGB = textureColor.rgb * vertexColor.rgb * color.rgb;
// alpha is a mix of texture, vertex, uniform and mask alpha
float A = textureColor.a * vertexColor.a * color.a;
// post-reversing premultiplication of alpha
float invA = 1.0 / clamp( A , 0.000001, 10.0);
// float invA = 1.0 / (A*A);
// output
FragColor = vec4( RGB * invA, A);
FragColor = vec4( textureColor.a);
}