BltShader: Correct algorithm as provided my /cremno
The color calculation is now actually 99% correct! Fixes #14.
This commit is contained in:
		
							parent
							
								
									b6a299541f
								
							
						
					
					
						commit
						1b0eb2797d
					
				
					 1 changed files with 5 additions and 9 deletions
				
			
		| 
						 | 
					@ -20,18 +20,14 @@ void main()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vec4 resFrag;
 | 
						vec4 resFrag;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float ab = opacity;
 | 
						float co1 = srcFrag.a * opacity;
 | 
				
			||||||
	float as = srcFrag.a;
 | 
						float co2 = dstFrag.a * (1.0 - co1);
 | 
				
			||||||
	float ad = dstFrag.a;
 | 
						resFrag.a = co1 + co2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	float at = ab*as;
 | 
						if (resFrag.a == 0.0)
 | 
				
			||||||
	resFrag.a = at + ad - ad*at;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Sigh...
 | 
					 | 
				
			||||||
	if (ad == 0.0)
 | 
					 | 
				
			||||||
		resFrag.rgb = srcFrag.rgb;
 | 
							resFrag.rgb = srcFrag.rgb;
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		resFrag.rgb = as*srcFrag.rgb + (1.0-at) * ad * dstFrag.rgb;
 | 
							resFrag.rgb = (co1*srcFrag.rgb + co2*dstFrag.rgb) / resFrag.a;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	gl_FragColor = resFrag;
 | 
						gl_FragColor = resFrag;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue