140 likes | 487 Views
Frame Buffer Operations. Obscure Tricks and Cool Visual Effects. Operations on Fragments. Depth Test Blending Scissor Test Alpha Test Stencil Test Dithering Logical Operations. Scissor Test. glEnable(GL_SCISSOR_TEST) glScissor ( x, y, width, height)
E N D
Frame Buffer Operations Obscure Tricks and Cool Visual Effects
Operations on Fragments • Depth Test • Blending • Scissor Test • Alpha Test • Stencil Test • Dithering • Logical Operations
Scissor Test • glEnable(GL_SCISSOR_TEST) • glScissor ( x, y, width, height) • integer window coordinates to draw into • x,y = lower left corner ? Uses ?
Alpha Test: syntax • glEnable (GL_ALPHATEST) • glAlphaFunc ( test, compare_value ) • compare_value is float 0 to 1 • test is function such as • GL_LESS - accept fragment if alpha < value • GL_EQUAL - accept fragment is alpha = value • GL_NOTEQUAL - accept fragment if alpha ≠ value • GL_LEQUAL - <= • GL_NEVER - never accept any fragment • GL_ALWAYS - always accept every fragment • etc
Alpha Test: uses • Given our tree made up of a texture of leaves with various alpha values, make the leaves slowly disappear by • slowing changing the alpha values that are accepted. • If you always want something to show up, but still need to use the depth test • draw scene once with depth test on, • then turn depth test off, • turn on alpha test for a particular value, • redraw scene
Alpha Test: uses Gets bigger and bigger • A star texture that changes • create a texture where every texel has the same RGB, • but vary the Alpha values • apply the texture (don't use blending) • during each drawing, use GL_LESS with different value, so that different areas appear Create a texture of wavy lines?
Stenciling: uses Isn't this just the scissor test? • My animation is viewed through a kitchen window, so the window frame and curtains should always show up. • Draw the window pieces once. • Draw the window pieces into the stencil buffer. • Draw the backyard over and over (only the fragments that are on the stencil will so up) http://www.uweb.ucsb.edu/~crashnburnjess/For%20Jess/Kitchen-Window.jpg
Stenciling: uses • Draw Tree and Box • Before drawing shadow, create a mask that matches the front of the box.
Example • Draw a square in the stencil buffer. • The wireframe pink cord is drawn in that mask, so only it appears in the square. • The same pink cord is drawn filled on the scene with a different stencil test. http://www.sulaco.co.za/opengl4.htm#stencil
How Stenciling Operates • for each pixel being drawn into the color buffer • compare a value to the corresponding pixel in stencil buffer • only draw pixels into color buffer that pass the test • perhaps change the stencil buffer pixel based on outcome of that test • programmer indicates the value, the compare test, and what to do if the test passes or fails
Stencil Functions • glEnable ( GL_STENCIL_TEST ) • glStencilFunc(test, compare_value, mask) • glStencilOp (stencil_fail, stencil_pass_depth_fail, stencil_pass_depth_pass) • GL_KEEP, GL_REPLACE, GL_ZERO, GL_INVERT, GL_INCR, etc
Stencil Pseudo-Code • fill stencil buffer with 0s • draw desired shape into stencil buffer with 1s • either use glDrawPixels to write straight into stencil buffer • or draw into the color buffer with polygon functions, using glStencilOp to change the stencil bits • set the reference value to 1 and the test function to equal (only draw pixels into color map where stencil is equal to 1)
Accumulation Buffer Motion Blur - leave an image trail • redraw the scene over and over while moving an object • between each drawing slightly dim the previous scene, glAccum(GL_MULT, decay) • move the accumulation buffer into the color buffer using glAccum(GL_RETURN, 1.0)
Accumulation Buffer Depth of Field - make distant objects a little blury • Draw the scene several times, each with a very slight change in projection. Hence, distant objects will move around a little more than near objects. This is "jittering". • Add each projected scene to the accumulation buffer. For example, draw the scene 10 times with glAccum(GL_ACCUM, 0.1) so that each projection makes up 10% of the final image. • Move the accumulation buffer into the color buffer.