CS 354 Blending, Compositing, Anti-aliasing Mark Kilgard University of Texas February 14, 2012
A Simplified Graphics Pipeline Application Vertex batching & assembly Triangle assembly Triangle clipping Triangle rasterization Fragment shading Depth testing Color update/blending Application- OpenGL API boundary Framebuffer NDC to window space Depth buffer Re-examine framebuffer color update…
A few more steps expanded Application Vertex batching & assembly Lighting View frustum clipping Triangle rasterization Fragment shading Depth testing Color update/blending Application- OpenGL API boundary Framebuffer NDC to window space Depth buffer Vertex transformation User defined clipping Back face culling Perspective divide Triangle assembly Texture coordinate generation
Blending Enabled vs. Disabled pixel color fragment color blend operation pixel color fragment color glDisable ( GL_BLEND ) glEnable ( GL_BLEND )
Why blending? compositing window systems volumetric effects; explosions medical imaging compositing complex art work
Conventional Blend Operation source color destination factor destination color source factor × × + clamp [0,1] pixel color fragment color
Conventional Blend Operation source color destination factor destination color source factor × × + clamp [0,1] pixel color fragment color × × × + + + × × × clamp [0,1] clamp [0,1] clamp [0,1] modulate, add, and clamp operations are vector on RGBA components
Conventional Blend Operation source color destination factor destination color source factor × × + clamp [0,1] pixel color fragment color glBlendFunc ( srcFunc , dstFunc )
Blend Function Parameters where s = min(A s ,1-A d ) (s,s,s,s) GL_SRC_ALPHA_SATURATE (1-A c ,1-A c ,1-A c ,1-A c ) GL_ONE_MINUS_CONSTANT_ALPHA (A c ,A c ,A c ,A c ) GL_CONSTANT_ALPHA (1-R c ,1-G c ,1-B c ,1-A c ) GL_ONE_MINUS_CONSTANT_COLOR (R c ,G c ,B c ,A c ) GL_CONSTANT_COLOR (1-A d ,1-A d ,1-A d ,1-A d ) GL_ONE_MINUS_DST_ALPHA (A d ,A d ,A d ,A d ) GL_DST_ALPHA (1-A s ,1-A s ,1-A s ,1-A s ) GL_ONE_MINUS_SRC_ALPHA (A s ,A s ,A s ,A s ) GL_SRC_ALPHA (1-R d ,1-G d ,1-B d ,1-A d ) GL_ONE_MINUS_DST_COLOR (R d ,G d ,B d ,A d ) GL_DST_COLOR (1-R s ,1-G s ,1-B s ,1-A s ) GL_ONE_MINUS_SRC_COLOR (R s ,G s ,B s ,A s ) GL_SRC_COLOR (1,1,1,1) GL_ONE (0,0,0,0) GL_ZERO ( f r , f g , f b , f a ) Parameter
Blend Color for Factors source color destination factor destination color source factor × × + clamp [0,1] pixel color fragment color glBlendColor (r,g,b,a) blend color
Min/Max Blend Operation source color destination color min or max clamp [0,1] pixel color fragment color glBlendEquation ( GL_MIN ) glBlendEquation ( GL_MAX )