forked from quickshell/quickshell
		
	widgets/cliprect: fix premultiplied alpha blending
This commit is contained in:
		
							parent
							
								
									8124a63ee4
								
							
						
					
					
						commit
						6dbc310df4
					
				
					 1 changed files with 5 additions and 4 deletions
				
			
		| 
						 | 
					@ -14,11 +14,12 @@ layout(binding = 2) uniform sampler2D content;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vec4 overlay(vec4 base, vec4 overlay) {
 | 
					vec4 overlay(vec4 base, vec4 overlay) {
 | 
				
			||||||
	if (overlay.a == 0.0) return base;
 | 
						if (overlay.a == 0.0) return base;
 | 
				
			||||||
 | 
						if (base.a == 0.0) return overlay;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float baseMul = 1.0 - overlay.a;
 | 
						vec3 rgb = overlay.rgb + base.rgb * (1.0 - overlay.a);
 | 
				
			||||||
	float newAlpha = overlay.a + base.a * baseMul;
 | 
						float a = overlay.a + base.a * (1.0 - overlay.a);
 | 
				
			||||||
	vec3 rgb = (overlay.rgb * overlay.a + base.rgb * base.a * baseMul) / newAlpha;
 | 
					
 | 
				
			||||||
	return vec4(rgb, newAlpha);
 | 
						return vec4(rgb, a);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void main() {
 | 
					void main() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue