31SDeferredCompositorDebug::SDeferredCompositorDebug(std::string compositorName) :
SDeferredCompositor(compositorName)
40Ogre::CompositorPtr SDeferredCompositorDebug::GenerateCompositor(SGBuffer* gBuffer)
42 Ogre::String compoName =
"SO3/Deferred/Compositor/"+
name +
"/"+ gBuffer->
GetName();
45 Ogre::CompositorPtr compositor = Ogre::CompositorManager::getSingleton().create(compoName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
48 Ogre::CompositionTechnique* compositionTechnique = compositor->createTechnique();
51 Ogre::CompositionTechnique::TextureDefinition* gBufferTexture = compositionTechnique->createTextureDefinition(
"mrt_output");
52 gBufferTexture->refCompName =
"SO3/Deferred/Compositor/GBuffer/" + gBuffer->GetName();
53 gBufferTexture->refTexName =
"mrt_output";
56 Ogre::CompositionTargetPass* compositionTargetPass = compositionTechnique->getOutputTargetPass();
57 compositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
60 Ogre::CompositionPass* compositionPass = compositionTargetPass->createPass();
61 compositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
64 compositionPass->setMaterial(GenerateCompositorMaterial(gBuffer));
67 unsigned int numberMrt = gBuffer->GetNumberMrt();
68 for(
unsigned int i = 0; i<numberMrt; i++)
69 compositionPass->setInput(i,
"mrt_output", i);
75Ogre::MaterialPtr SDeferredCompositorDebug::GenerateCompositorMaterial(SGBuffer* gBuffer)
77 Ogre::String matName =
"SO3/Deferred/Compositor/Material/"+
name +
"/"+ gBuffer->GetName();
80 Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().create(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
81 Ogre::Pass* pass = matPtr->getTechnique(0)->getPass(0);
82 pass->setCullingMode(Ogre::CULL_NONE);
83 pass->setManualCullingMode(Ogre::MANUAL_CULL_NONE);
84 pass->setDepthFunction(Ogre::CMPF_ALWAYS_PASS);
87 pass->setVertexProgram(GenerateCompositorVertexShader(gBuffer)->getName());
88 pass->setFragmentProgram(GenerateCompositorPixelShader(gBuffer)->getName());
91 unsigned int numberOfMrt = gBuffer->GetNumberMrt();
92 for (Ogre::uint32 i=0; i<numberOfMrt; i++)
94 Ogre::TextureUnitState* tu = pass->createTextureUnitState();
95 tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
96 tu->setTextureFiltering(Ogre::TFO_NONE);
97 tu->setTextureCoordSet(i);
103Ogre::GpuProgramPtr SDeferredCompositorDebug::GenerateCompositorVertexShader(SGBuffer* gBuffer)
105 Ogre::StringStream ss;
108 ss <<
"void main(float4 Pos: POSITION," << std::endl;
109 ss <<
" out float4 oPos: POSITION," << std::endl;
110 ss <<
" out float2 oTexCoord: TEXCOORD0," << std::endl;
111 ss <<
" out float3 oRay : TEXCOORD1," << std::endl;
112 ss <<
" uniform float3 farCorner," << std::endl;
113 ss <<
" uniform float flip)" << std::endl;
114 ss <<
"{" << std::endl;
117 ss <<
" Pos.xy = sign(Pos.xy);" << std::endl;
120 ss <<
" oPos = float4(Pos.xy, 0, 1);" << std::endl;
121 ss <<
" oPos.y *= flip;" << std::endl;
124 ss <<
" oTexCoord.x = 0.5 * (1 + Pos.x); // bound [0:1]" << std::endl;
125 ss <<
" oTexCoord.y = 0.5 * (1 - Pos.y); // bound [1:0]" << std::endl;
128 ss <<
" oRay = farCorner * float3(Pos.xy, 1);" << std::endl;
129 ss <<
"}" << std::endl;
132 Ogre::String programSource = ss.str();
133 Ogre::String programName =
"SO3/Deferred/Compositor/shader/"+
name +
"/"+ gBuffer->GetName() +
"_vs";
137 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource, Ogre::LML_CRITICAL);
142 Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
"cg", Ogre::GPT_VERTEX_PROGRAM);
143 ptrProgram->setSource(programSource);
144 ptrProgram->setParameter(
"entry_point",
"main");
145 ptrProgram->setParameter(
"profiles",
"vs_1_1 arbvp1");
148 const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters();
149 if (params->_findNamedConstantDefinition(
"flip"))
150 params->setNamedAutoConstant(
"flip", Ogre::GpuProgramParameters::ACT_RENDER_TARGET_FLIPPING);
152 if (params->_findNamedConstantDefinition(
"farCorner"))
153 params->setNamedConstant(
"farCorner", Ogre::Vector3::UNIT_SCALE);
158 return Ogre::GpuProgramPtr(ptrProgram);
161Ogre::GpuProgramPtr SDeferredCompositorDebug::GenerateCompositorPixelShader(SGBuffer* gBuffer)
163 Ogre::StringStream ss;
166 ss << gBuffer->GenerateGBufferCompositorPixelInputStructure();
169 ss <<
"float4 main(float2 texCoord: TEXCOORD0," << std::endl;
170 ss <<
" float2 projCoord: TEXCOORD1," << std::endl;
173 ss <<
" " << gBuffer->GetGBufferCompositorPixelInputStructureTypeName() <<
" gBuffer" << std::endl;
174 ss <<
" ) : COLOR" << std::endl;
177 ss <<
"{" << std::endl;
179 ss <<
"}" << std::endl;
182 Ogre::String programSource = ss.str();
183 Ogre::String programName =
"SO3/Deferred/Compositor/shader/"+
name +
"/"+ gBuffer->GetName() +
"_ps";
187 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource, Ogre::LML_CRITICAL);
192 Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
"cg", Ogre::GPT_FRAGMENT_PROGRAM);
193 ptrProgram->setSource(programSource);
194 ptrProgram->setParameter(
"entry_point",
"main");
195 ptrProgram->setParameter(
"profiles",
"ps_2_0 arbfp1");
199 return Ogre::GpuProgramPtr(ptrProgram);
std::string GetName() const
virtual Ogre::String GenerateCompositorPixelShaderImpl()=0