31SDeferredCompositorAA::SDeferredCompositorAA(std::string compositorName) :
SDeferredCompositor(compositorName)
40Ogre::CompositorPtr SDeferredCompositorAA::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* sceneTexture = compositionTechnique->createTextureDefinition(
"scene");
52 sceneTexture->width = 0;
53 sceneTexture->height = 0;
54 Ogre::PixelFormatList pixelFormat;
55 pixelFormat.push_back(Ogre::PF_R8G8B8A8);
56 sceneTexture->formatList = pixelFormat;
59 Ogre::CompositionTargetPass* sceneTargetPass = compositionTechnique->createTargetPass();
60 sceneTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_PREVIOUS);
61 sceneTargetPass->setOutputName(
"scene");
64 Ogre::CompositionTargetPass* compositionTargetPass = compositionTechnique->getOutputTargetPass();
65 compositionTargetPass->setInputMode(Ogre::CompositionTargetPass::IM_NONE);
68 Ogre::CompositionPass* compositionPass = compositionTargetPass->createPass();
69 compositionPass->setType(Ogre::CompositionPass::PT_RENDERQUAD);
72 compositionPass->setMaterial(GenerateCompositorMaterial(gBuffer));
75 compositionPass->setInput(0,
"scene");
81Ogre::MaterialPtr SDeferredCompositorAA::GenerateCompositorMaterial(SGBuffer* gBuffer)
83 Ogre::String matName =
"SO3/Deferred/Compositor/Material/"+
name +
"/"+ gBuffer->GetName();
86 Ogre::MaterialPtr matPtr = Ogre::MaterialManager::getSingleton().create(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
87 Ogre::Pass* pass = matPtr->getTechnique(0)->getPass(0);
88 pass->setCullingMode(Ogre::CULL_NONE);
89 pass->setManualCullingMode(Ogre::MANUAL_CULL_NONE);
90 pass->setDepthFunction(Ogre::CMPF_ALWAYS_PASS);
93 pass->setVertexProgram(GenerateCompositorVertexShader(gBuffer)->getName());
94 pass->setFragmentProgram(GenerateCompositorPixelShader(gBuffer)->getName());
97 Ogre::TextureUnitState* tu = pass->createTextureUnitState();
98 tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
99 tu->setTextureFiltering(Ogre::TFO_TRILINEAR);
100 tu->setTextureCoordSet(0);
105Ogre::GpuProgramPtr SDeferredCompositorAA::GenerateCompositorVertexShader(SGBuffer* gBuffer)
107 Ogre::StringStream ss;
110 ss <<
"void main(float4 Pos: POSITION," << std::endl;
111 ss <<
" out float4 oPos: POSITION," << std::endl;
112 ss <<
" out float2 oTexCoord: TEXCOORD0," << std::endl;
113 ss <<
" uniform float flip)" << std::endl;
114 ss <<
"{" << std::endl;
117 ss <<
" Pos.xy = sign(Pos.xy);" << std::endl;
121 ss <<
" oPos = float4(Pos.xy, 0, 1);" << std::endl;
122 ss <<
" oPos.y *= flip;" << std::endl;
125 ss <<
" oTexCoord.x = 0.5 * (1 + Pos.x); // bound [0:1]" << std::endl;
126 ss <<
" oTexCoord.y = 0.5 * (1 - Pos.y); // bound [1:0]" << std::endl;
127 ss <<
"}" << std::endl;
130 Ogre::String programSource = ss.str();
131 Ogre::String programName =
"SO3/Deferred/Compositor/shader/"+
name +
"/"+ gBuffer->GetName() +
"_vs";
135 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource, Ogre::LML_CRITICAL);
140 Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
"cg", Ogre::GPT_VERTEX_PROGRAM);
141 ptrProgram->setSource(programSource);
142 ptrProgram->setParameter(
"entry_point",
"main");
143 ptrProgram->setParameter(
"profiles",
"vs_1_1 arbvp1");
146 const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters();
147 if (params->_findNamedConstantDefinition(
"flip"))
148 params->setNamedAutoConstant(
"flip", Ogre::GpuProgramParameters::ACT_RENDER_TARGET_FLIPPING);
152 return Ogre::GpuProgramPtr(ptrProgram);
155Ogre::GpuProgramPtr SDeferredCompositorAA::GenerateCompositorPixelShader(SGBuffer* gBuffer)
157 Ogre::StringStream ss;
160 ss << gBuffer->GenerateGBufferCompositorPixelInputStructure();
163 ss <<
"float4 main(float2 texCoord: TEXCOORD0," << std::endl;
164 ss <<
" uniform float4 screenSize," << std::endl;
166 ss <<
" sampler scene : register(s0)" << std::endl;
167 ss <<
" ) : COLOR" << std::endl;
170 ss <<
"{" << std::endl;
172 ss <<
"}" << std::endl;
175 Ogre::String programSource = ss.str();
176 Ogre::String programName =
"SO3/Deferred/Compositor/shader/"+
name +
"/"+ gBuffer->GetName() +
"_ps";
180 Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(programSource, Ogre::LML_CRITICAL);
185 Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(programName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
"cg", Ogre::GPT_FRAGMENT_PROGRAM);
186 ptrProgram->setSource(programSource);
187 ptrProgram->setParameter(
"entry_point",
"main");
188 ptrProgram->setParameter(
"profiles",
"ps_2_0 arbfp1");
191 const Ogre::GpuProgramParametersSharedPtr& params = ptrProgram->getDefaultParameters();
192 if (params->_findNamedConstantDefinition(
"screenSize"))
193 params->setNamedAutoConstant(
"screenSize", Ogre::GpuProgramParameters::ACT_INVERSE_TEXTURE_SIZE);
198 return Ogre::GpuProgramPtr(ptrProgram);
std::string GetName() const
virtual Ogre::String GenerateCompositorPixelShaderImpl()=0