mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-05 15:30:00 +01:00
AlphaShader for mapping alpha in pre-render
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
@@ -27,11 +27,11 @@ public:
|
||||
float stipple;
|
||||
};
|
||||
|
||||
class DivideAlphaShader : public ImageShader
|
||||
class AlphaShader : public ImageShader
|
||||
{
|
||||
|
||||
public:
|
||||
DivideAlphaShader();
|
||||
AlphaShader();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user