Project

General

Profile

SO3Engine
SO3DeferredCompositorLighting.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
28
29namespace SO3
30{
31
35
36Ogre::CompositorPtr SDeferredCompositorLighting::GenerateCompositor(SGBuffer* gBuffer)
37{
38 Ogre::String compoName = "SO3/Deferred/Compositor/"+ name +"/"+ gBuffer->GetName();
39
40 // Create compo
41 Ogre::CompositorPtr compositor = Ogre::CompositorManager::getSingleton().create(compoName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
42
43 // Create the technique
44 Ogre::CompositionTechnique* compositionTechnique = compositor->createTechnique();
45
46 // Reference to gbuffer texture
47 Ogre::CompositionTechnique::TextureDefinition* gBufferTexture = compositionTechnique->createTextureDefinition("mrt_output");
48 gBufferTexture->refCompName = "SO3/Deferred/Compositor/GBuffer/" + gBuffer->GetName();
49 gBufferTexture->refTexName = "mrt_output";
50
51 // Create the output target
52 Ogre::CompositionTargetPass* compositionTargetPass = compositionTechnique->getOutputTargetPass();
53 compositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
54 compositionTargetPass->setShadowsEnabled(false);
55
56 // Create a "clear" pass on the target
57 Ogre::CompositionPass* compositionPass = compositionTargetPass->createPass();
58 compositionPass->setType(Ogre::CompositionPass::PT_CLEAR);
59
60 // render skies and other pre-gbuffer objects
61 compositionPass = compositionTargetPass->createPass();
62 compositionPass->setType(Ogre::CompositionPass::PT_RENDERSCENE);
63 compositionPass->setFirstRenderQueue(1);
64 compositionPass->setLastRenderQueue(SDeferredShading::PRE_GBUFFER_RENDER_QUEUE - 1);
65
66 //Render the lights and their meshes
67 compositionPass = compositionTargetPass->createPass();
68 compositionPass->setType(Ogre::CompositionPass::PT_RENDERCUSTOM);
69 compositionPass->setCustomType("DeferredLight");
70 unsigned int numberMrt = gBuffer->GetNumberMrt();
71 for(unsigned int i = 0; i<numberMrt; i++)
72 compositionPass->setInput(i, "mrt_output", i);
73
74 //Render the objects that skipped rendering into the gbuffer
75 compositionPass = compositionTargetPass->createPass();
76 compositionPass->setType(Ogre::CompositionPass::PT_RENDERSCENE);
77 compositionPass->setFirstRenderQueue(SDeferredShading::PRE_GBUFFER_RENDER_QUEUE);
78 compositionPass->setLastRenderQueue(SDeferredShading::POST_GBUFFER_RENDER_QUEUE - 1);
79 compositionPass->setMaterialScheme("NoGBuffer");
80
81 //Render the post-GBuffer render queue objects
82 compositionPass = compositionTargetPass->createPass();
83 compositionPass->setType(Ogre::CompositionPass::PT_RENDERSCENE);
84 compositionPass->setFirstRenderQueue(SDeferredShading::POST_GBUFFER_RENDER_QUEUE);
85
86 // Compositor is created!
87 return compositor;
88}
89
90}
std::string GetName() const
std::string name
Definition SO3DataScol.h:44
static const Ogre::uint8 PRE_GBUFFER_RENDER_QUEUE
static const Ogre::uint8 POST_GBUFFER_RENDER_QUEUE
unsigned int GetNumberMrt() const