[canvas, gl] use pre-multiplied alpha in draw shader and when compositing batches
This commit is contained in:
parent
ac6a5db209
commit
9cb4aedbc5
|
@ -140,7 +140,7 @@ void mg_gl_canvas_begin(mg_canvas_backend* interface)
|
|||
{
|
||||
mg_gl_canvas_backend* backend = (mg_gl_canvas_backend*)interface;
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
|
||||
void mg_gl_canvas_end(mg_canvas_backend* interface)
|
||||
|
|
|
@ -365,6 +365,8 @@ const char* glsl_draw =
|
|||
"\n"
|
||||
" int shapeIndex = vertexBuffer.elements[i0].shapeIndex;\n"
|
||||
" vec4 color = shapeBuffer.elements[shapeIndex].color;\n"
|
||||
" color.rgb *= color.a;\n"
|
||||
"\n"
|
||||
" ivec4 clip = ivec4(round((shapeBuffer.elements[shapeIndex].clip * vec4(scaling, scaling) + vec4(0.5, 0.5, 0.5, 0.5)) * subPixelFactor));\n"
|
||||
"\n"
|
||||
" mat3 uvTransform = mat3(shapeBuffer.elements[shapeIndex].uvTransform[0],\n"
|
||||
|
@ -437,9 +439,11 @@ const char* glsl_draw =
|
|||
" {\n"
|
||||
" vec3 sampleFP = vec3(vec2(samplePoint).xy/(subPixelFactor*2.), 1);\n"
|
||||
" vec2 uv = (uvTransform * sampleFP).xy;\n"
|
||||
" nextColor *= texture(srcTexture, uv);\n"
|
||||
" vec4 texColor = texture(srcTexture, uv);\n"
|
||||
" texColor.rgb *= texColor.a;\n"
|
||||
" nextColor *= texColor;\n"
|
||||
" }\n"
|
||||
" currentColor[sampleIndex] = sampleColor[sampleIndex]*(1.-nextColor.a) + nextColor.a*nextColor;\n"
|
||||
" currentColor[sampleIndex] = sampleColor[sampleIndex]*(1.-nextColor.a) + nextColor;\n"
|
||||
" currentShapeIndex[sampleIndex] = shapeIndex;\n"
|
||||
" flipCount[sampleIndex] = 1;\n"
|
||||
" }\n"
|
||||
|
|
|
@ -142,6 +142,8 @@ void main()
|
|||
|
||||
int shapeIndex = vertexBuffer.elements[i0].shapeIndex;
|
||||
vec4 color = shapeBuffer.elements[shapeIndex].color;
|
||||
color.rgb *= color.a;
|
||||
|
||||
ivec4 clip = ivec4(round((shapeBuffer.elements[shapeIndex].clip * vec4(scaling, scaling) + vec4(0.5, 0.5, 0.5, 0.5)) * subPixelFactor));
|
||||
|
||||
mat3 uvTransform = mat3(shapeBuffer.elements[shapeIndex].uvTransform[0],
|
||||
|
@ -214,9 +216,11 @@ void main()
|
|||
{
|
||||
vec3 sampleFP = vec3(vec2(samplePoint).xy/(subPixelFactor*2.), 1);
|
||||
vec2 uv = (uvTransform * sampleFP).xy;
|
||||
nextColor *= texture(srcTexture, uv);
|
||||
vec4 texColor = texture(srcTexture, uv);
|
||||
texColor.rgb *= texColor.a;
|
||||
nextColor *= texColor;
|
||||
}
|
||||
currentColor[sampleIndex] = sampleColor[sampleIndex]*(1.-nextColor.a) + nextColor.a*nextColor;
|
||||
currentColor[sampleIndex] = sampleColor[sampleIndex]*(1.-nextColor.a) + nextColor;
|
||||
currentShapeIndex[sampleIndex] = shapeIndex;
|
||||
flipCount[sampleIndex] = 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue