OSU CS 519 - Multipass Rendering: Rendering to a Texture

Unformatted text preview:

1mjb – January 4, 2012Multipass Rendering:Rendering to a TextureMike [email protected] State Universitymjb – January 4, 2012Preliminary Background – the OpenGL Rendering ContextThe OpenGL Rendering Context contains all the characteristic information necessary to produce an image from geometry. This includes transformations, colors, lighting, textures, where to send the display, etc.ContextColor Transf.Lighting NormalTexture0Display Dest.Texture1 Texture2 Texture3Whenever you “bind” something in OpenGL, you are docking it into its port in the Context.Some of these characteristics have a default value (e.g., lines are white, the display goes to the screen) and some have nothing (e.g., no textures exist)You can bind an empty texture in GPU memory to the Display Destination port ! This is called Render-to-Texture.mjb – January 4, 2012Render-to-TextureA Rotating 3D Teapot Displayed on a Rotating PlaneSteps:1. Bind an empty GPU memory texture to the Display Destination port2. Render the 3D Teapot to that texture3. Bind the normal screen framebuffer to the Display Destination port.4. Render a quad with the texture of the 3D view of the teapot mapped to itmjb – January 4, 2012##OpenGL GLIBPerspective 90Texture2D 6 1024 1024RenderToTexture 6Background 0. 0.1 0.ClearVertex ovals.vertFragment ovals.fragProgram Ovals \uAd <.01 .2 .5> uBd <.01 .2 .5> \uNoiseAmp <0. 0. 1.> uNoiseFreq <0. 1. 2.> \uTol <0. 0. 1.>TeapotRenderToTextureBackground 0. 0.0 0ClearLookAt 0 0 2.5 0 0 0 0 1 0Vertex texture.vertFragment texture.fragProgram Texture uInUnit 6QuadXY .2 2.twopass.glibRender-to-TextureA Rotating 3D Teapot Displayed on a Rotating Planemjb – January 4, 2012##OpenGL GLIBPerspective 90Texture2D 6 1024 1024RenderToTexture 6Background 0. 0. 0.ClearVertex ovals.vertFragment ovals.fragProgram Ovals \uAd <.01 .2 .5> uBd <.01 .2 .5> \uNoiseAmp <0. 0. 1.> uNoiseFreq <0. 1. 2.> \uTol <0. 0. 1.>TeapotRenderToTextureBackground 0. 0.0 0ClearLookAt 0 0 2.5 0 0 0 0 1 0Vertex image.vertFragment image.fragProgram Filter uInUnit 6 \uEdgeDetect <true> \uTedge <0. 0. 1.> \uTSharp <-3. 1. 10.>QuadXY .2 2.filter.glibRender-to-TextureAn Image-filtered 3D Teapot Displayed on a Fixed Planemjb – January 4, 2012Original Sharpened Edge DetectedNo NoiseNoiseMultipass Algorithm to Render and then Image Process2mjb – January 4, 2012Multipass Algorithm to Implement Conway’s Game of LifePing-pong between two different textures. One texture is being read from (the previous state) and the other is being written into (the next state).mjb – January 4, 2012##OpenGL GLIBPerspective 70# setup the 2 textures:Texture2D 5 paint0.bmpTexture2D 6 512 512# execute the first iteration:RenderToTexture 6Background 0. 0. 0.ClearVertex life.vertFragment life.fragProgram GameOfLife1 uInUnit 5TextureMatrixTranslate 0. 0. -3.08QuadXY .2 2.# render it so we can see it:RenderToTextureBackground 0. .2 0.ClearVertex texture.vertFragment texture.fragProgram Texture1 uInUnit 6ModelViewMatrixTranslate 0. 0. -3.08QuadXY .2 2.SwapBuffers# execute the second iteration:RenderToTexture 5Background 0. 0. 0.ClearVertex life.vertFragmen t life.fragProgram GameOfLife2 uInUnit 6QuadXY .2 2.# render it so we can see it:RenderToTextureBackground .2 0. 0.ClearVertex texture.vertFragment texture.fragProgram Texture uInUnit 5QuadXY .2 2.# repeat:animatelife.glibmjb – January 4, 2012uniform sampler2D uInUnit;in vec2 vST;out vec4 fFragColor;const vec3 DEAD = vec3( 1., 1., 1. );const vec3 ALIVE = vec3( 0., 0., 1. );const float TB = 0.20; // color thresholdconst float TR = 0.20; // color thresholdconst int T1 = 1; // critical # of neighborsconst int T3 = 3; // critical # of neighborsconst int T4 = 4; // critical # of neighborsvoid main( ){ivec2 isize = textureSize( uInUnit, 0 );vec2 st = vST;ivec2 ist = ivec2( st.s*float(isize.s-1) , st.t*float(isize.t-1) ); // 0 -> dimension-1ivec2 istp0 = ivec2( 1, 0 );ivec2 ist0p = ivec2( 0, 1 );ivec2 istpp = ivec2( 1, 1 );ivec2 istpm = ivec2( 1, -1 );vec3 i00 = texelFetch( InUnit, ist, 0 ).rgb; // index using integer indicesvec3 im10 = texelFetch( InUnit, ist-istp0, 0 ).rgb;vec3 i0m1 = texelFetch( InUnit, ist-ist0p, 0 ).rgb;vec3 ip10 = texelFetch( InUnit, ist+istp0, 0 ).rgb;vec3 i0p1 = texelFetch( InUnit, ist+ist0p, 0 ).rgb;vec3 im1m1 = texelFetch( InUnit, ist-istpp, 0 ).rgb;vec3 ip1p1 = texelFetch( InUnit, ist+istpp, 0 ).rgb;vec3 im1p1 = texelFetch( InUnit, ist-istpm, 0 ).rgb;vec3 ip1m1 = texelFetch( InUnit, ist+istpm, 0 ).rgb;life.frag, Imjb – January 4, 2012int sum = 0;if( im10.b > TB && im10.r < TR ) sum++;if( i0m1.b > TB && i0m1.r < TR ) sum++;if( ip10.b > TB && ip10.r < TR ) sum++;if( i0p1.b > TB && i0p1.r < TR ) sum++;if( im1m1.b > TB && im1m1.r < TR ) sum++;if( ip1p1.b > TB && ip1p1.r < TR ) sum++;if( im1p1.b > TB && im1p1.r < TR ) sum++;if( ip1m1.b > TB && ip1m1.r < TR ) sum++;vec3 newcolor = i00;if( sum == T3 ){newcolor = ALIVE;}else if( sum <= T1 || sum >= T4 ){newcolor = DEAD;}fFragColor = vec4( newcolor, 1. );}life.frag,


View Full Document

OSU CS 519 - Multipass Rendering: Rendering to a Texture

Download Multipass Rendering: Rendering to a Texture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Multipass Rendering: Rendering to a Texture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Multipass Rendering: Rendering to a Texture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?