This is going to be our first compositor. We will use the scene and prepare to see its effect.
Ogre3DBeginnersGuide/Comp1:
material Ogre3DBeginnersGuide/Comp1 { technique { pass { texture_unit { } } } }
Ogre3DBeginnersGuide.compositor
.compositor Compositor1 { technique {
texture scene target_width target_height PF_R8G8B8
target scene { input previous }
target_output {
Ogre3DBeginnersGuide/Comp1
and needs our scene target as a texture input:input none pass render_quad { material Ogre3DBeginnersGuide/Comp1 input 0 scene }
} } }
CompositorManager
and the viewport of our camera. Add the code to the createScene()
function:Ogre::CompositorManager::getSingleton().addCompositor(mCamera->getViewport(), "Compositor1"); Ogre::CompositorManager::getSingleton().setCompositorEnabled(mCamera->getViewport(), "Compositor1", true);
We added our first compositor using a compositor file containing our compositor script. Step 1 just created an empty material, which simply rendered everything it got without any added effects. Step 2 created a new file to store our compositor scripts; it's like material files just for compositors. Step 3 is also pretty familiar: we named our first compositor Compositor1
and defined a technique to use just like materials compositors have different techniques for different target graphic cards. The interesting part starts with step 4: here we created a new texture named scene which has the same dimensions as the target texture we are rendering to, and this texture used eight bits for each color part. This is defined by PF_R8G8B8
.
But why do we need to create a new texture in the first place? To understand this, we need to understand how a compositor works. Compositors modify the appearance of a scene after it has been rendered. It's like post processing in movies where they add all the computer effects after the shooting of a movie. To be able to do this, the compositor needs the rendered scene as a texture, so it can be modified further. We created this texture in step 4, and in step 5, we told Ogre 3D to fill this texture with the scene we rendered before. This was done with input previous
. Now we have a texture that contains our scene rendered, the next thing our compositor needs to do is create a new image, which is displayed on the monitor. This is done in step 6 using the keyword output
in combination with a target block. Step 7 defines this output. We don't need any input because we already have our scene in the scene texture. To render the modified texture, we need a quad that covers the whole monitor, onto which we can render the texture with the modified scene. This is achieved with the pass
keyword followed by the render_quad
identifier. There are several other identifiers we can use in combination with the pass
keyword. They can be found in the documentation (http://www.ogre3d.org/docs/manual/manual_32.html#SEC163). Inside the pass block, we define several attributes we want to use for this rendering pass. This is the first material we want the quad to use; here we just use the material we defined beforehand, which renders the texture we are giving it to the quad without modifying it. The next attribute defines additional input like textures; here we say the first texture we want as input should be the scene texture. In fact, this means we want our scene rendered to a texture and applied to a quad that covers the whole screen. With this, we won't see any difference between the rendered scene with or without a compositor. This will change when we add some code to our material, which modifies the incoming texture to add additional effects.
Step 9 adds the compositor to our viewport and then enables it; we add compositors to a viewport and not to our scene because compositors modify the appearance of a scene seen through a camera, and what a camera sees is defined within the viewport. So if we want to modify the appearance of a complete scene, we would add the compositor to the object that defines the appearance of the scene itself.
The following is a simplified diagram showing the workflow of our compositor and an abridged version of the compositor script, which is the code for the step shown by the diagram.
18.117.229.92