<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>

<chapter name="Video and Graphics 10: Composing the Screen">

<previous name="jitterchapter00k_Building live video effects">Building live video effects</previous>
<next name="jitterchapter01">Playing a Movie</next>
<parent name="jitindex">Jitter Tutorials</parent>

<openfile name="Composing the Screen" patch="jitter_core_-_10_-_Composing_the_screen_1.maxpat"/>

<h1>Video and Graphics Tutorial 10: Composing the Screen</h1>



<h2>Intro</h2>



<p>We’ll look at some new ways of working with with video and geometry together in the render world in this tutorial. From layering and compositing to layout and composition, OpenGL lets us create flexible and dynamic scenes.</p>



<h2>Setup</h2>

<p>Open the patch. You’ll see we have the typical <o>jit.world</o> (with the name <m>thescreen</m>, which we will use later) and a few <o>jit.movie</o> objects with their <i>output_texture</i> attributes enabled. Instead of patching these straight into <o>jit.world</o> as we have been doing, we’ll use each of these in a different way to explore some more possbilities. Turn on <o>jit.world</o> and let’s get started.</p>

<h2>Make Some Layers</h2>

<p>First add a new object, <b>jit.gl.videoplane @depth_enable 0 @blend_enable 1</b>. Add <o>attrui</o> objects for the <i>scale</i>, <i>position</i> and <i>rotatexyz</i> attributes and connect them, then patch the left-most video into it.</p>

<illustration><img src="images/jitter_core - 10a.png"/></illustration>

<p>You’ll see it appear in the GL window just as though you had patched into <o>jit.world</o>. The <o>jit.world</o> actually has an embedded videoplane, but this method gives us some more flexibility. Move the plane around using the <i>position</i> and <i>rotatexyz</i> attributes and rescale it to get a sense of how it works in GL space. Now, duplicate your <o>jit.gl.videoplane</o> setup and connect the second <o>jit.movie</o> object to it.</p>


<p>You will probably notice that the two images overlap, with one obscuring the other. Add a <m>layer $1</m> <o>message</o> box/<o>toggle</o> pair or an <o>attrui</o> to each <o>jit.gl.videoplane</o> object to control the layering behavior. Higher layers are rendered in front (on top) of lower layers. You can now control which image sits above the other. </p>

<illustration><img src="images/jitter_core - 10b.png"/></illustration>

<p>Next let’s add blending. The <i>blend_enable</i> attribute allows blending across layers. The default blend mode will allow the alpha channel information to perform the blend. In this patch we will use a <o>jit.gl.pix</o> object that lets us substitute any plane in our texture for the alpha channel. Add the <b>jit.gl.pix @gen alphy</b> in between the <o>jit.movie</o> and the <o>jit.gl.videoplane</o>. Using the <o>umenu</o>/<o>message</o> box pair to set the <i>plane</i> parameter selects which plane will act as the alpha - red, green, blue, alpha or luminance (the average of R, G and B). Similarly, the <i>amt</i> parameter adjusts the overall transparency of the resulting alpha layer. Add a copy of the <o>jit.gl.pix</o> to the second <o>jit.gl.videoplane</o> and experiment with blending the two images.</p>

<illustration><img src="images/jitter_core - 10c.png"/></illustration>

<p>An OpenGL scene can have any number of video and geometry elements together in a scene. Add a <o>jit.gl.gridshape</o> object with @depth_enable 0 @blend_enable 1 and @lighting_enable 1. Now give it attruis for scale, position, rotatexyz, and layer, just like you did for the videoplanes (you can just copy/paste them). </p>

<p>Now let’s add a <b>jit.gl.texture @name alphy</b> object under the third movie, with the <o>jit.gl.pix</o> alpha patch between them. The <i>@name</i> attribute to <m>alphy</m>will allow us to call on the texture in a moment. </p>

<illustration><img src="images/jitter_core - 10d.png"/></illustration>

<p>Create a <o>message</o> box that contains the message <m>texture alphy</m> and connect it to the <o>jit.gl.gridshape</o> object. When you click it, the movie going into the <o>jit.gl.texture</o> will texture the surface of our geometry. To remove the texture, send your <o>jit.gl.gridshape</o> object the message <m>texture none</m>. If you know you want to keep a texture attached to your shape, simply patch the output of the texture source to the GL object you wish to texture.</p>

<illustration><img src="images/jitter_core - 10e.png"/></illustration>

<p>Using the alpha controls and layer attributes, you can now compose and layer the screen however you want.</p>

<div>
	<techdetail>
		<ul>

			<li><link type="vignette" module="core" name="jitter_layering">Depth Testing vs Layering</link> — Depth Testing vs Layering</li>

		</ul>

	</techdetail>
</div>


<p>A common element to any 3D render space that we have not looked at yet is the camera. Add a <o>jit.gl.camera</o> object with <o>attrui</o> objects for the <i>position</i>, <i>rotatexyz</i>, <i>lookat</i>, and <i>locklook</i> attributes. </p>

<illustration><img src="images/jitter_core - 10f.png"/></illustration>

<p>There are a lot of ways to create sophisticated camera movement, but for now, just try exploring these parameters. The <i>locklook</i> attribute allows you to move the camera while having it focus on a particular point in space no matter where it moves. Notice that the rotation is automatically adjusted when you change the position in this mode. The <i>lookat</i> parameter determines where the camera is focused in virtual space. If you want to remove blending and have layers determined based on depth, set <i>@depth_enable</i> to 1.</p>

<p>Finally, add an <i>enable</i> attribute to your objects to turn them on (1) or off (0).</p>

<h2>Using <o>jit.gl.node</o> and <o>jit.gl.cornerpin</o></h2>

<p> Now that we have composed a scene, let’s look at an object called <o>jit.gl.node</o>, which allows us to render the entire scene as a texture which can then be processed or reused in a number of ways. One way to think of <o>jit.gl.node</o> is that it’s like a small <o>jit.world</o> inside of your <o>jit.world</o>, with the ability to add "child" objects and even more <o>jit.gl.node</o> objects.</p>

<p>Make an object called <b>jit.gl.node @capture 1</b>. Now connect its center outlet to the inlets of our <o>jit.gl.videoplane</o> and <o>jit.gl.gridshape</o> objects. Don’t worry if your objects seem to disappear.</p>

<illustration><img src="images/jitter_core - 10h.png"/></illustration>

<p>Objects connected to the middle outlet of <o>jit.gl.node</o> are all rendered in the node instead of directly to the <o>jit.world</o>. The <i>@capture 1</i> attribute causes <o>jit.gl.node</o> to output the internal render as a texture instead of displaying it in the master context. </p>

<p>Now add a <b>jit.gl.cornerpin thescreen</b> object and connect the left outlet of <o>jit.gl.node</o> to it. You’ll see that your scene shows up again and has 4 targets at the corners of the window. Click and drag a target to adjust the corners, in turn skewing the image to fit in the resulting map. You can hide the corners using the <i>drawcorners</i> attribute. </p>

<illustration><img src="images/jitter_core - 10g.png"/></illustration>

<p>The <o>jit.gl.cornerpin</o> object is ideal for mapping an input texture to an output screen of unconventional dimensions. </p>

<h2>Background color</h2>

<p>You may have noticed that the <o>jit.window</o> has a dark grey background. In many cases you will want to adjust this. You can do so by using the <o>jit.world</o> attribute <i>erase_color</i>. Adjusting the RGBA values will adjust the background color. Try sending the message <m>erase_color 0. 0. 0. 1.</m> to get a black background, or choose a value from 0. - 1. for each of the four values in the list to get any colored background you desire. Note that if you set your alpha value low, you will be able to get a smearing effect when you move objects around. The <i>erase_color</i> attribute is used to determine how much of a given color is removed from the render scene each frame. </p>


<div>
	<techdetail>

		<h2>Explore Further</h2>

		<p>Try creating images (PNG) and videos (compress as Animation, ProRes 4444, etc.) with transparent backgrounds to import into Jitter and use as practice layers with blending enabled. OpenGL objects also have a “blend” attribute that gives even more control over how layers draw, besides the default alphablend mode. Try changing the value of this attribute for more image effects.</p>

		<p>As <o>jit.gl.node</o> allows for capturing scenes to a texture, you can also process this texture like any other image. Try adding <o>jit.gl.slab</o> and <o>jit.gl.pix</o> effects chains after the node output. This opens up the ability to do lots of post-render effects like blurs and glows or image control.</p>


	</techdetail>
</div>





</chapter>
