I'm confused of the compositor system. Could someone please provide a small sample how to create a user defined compositor by code? I've seen the sample code but I don't get it how to activate it.
I have an DX9 project which I like to move to Ogre 2.0. Of course I could clone and modify the DX9 render system, but this is not an option because the plan is to remove DX9. the program uses a generated shader (__szEffect)
Code: Select all
uniform extern texture textureA;
uniform extern texture textureB;
uniform extern texture textureC;
uniform extern bool bBorder;
sampler samplerA = sampler_state
{
Texture = <textureA>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressV = BORDER;
AddressU = BORDER;
BorderColor = float4(0,0,0,0);
};
sampler samplerB = sampler_state
{
Texture = <textureB>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressV = MIRROR;
AddressU = MIRROR;
BorderColor = float4(0,0,0,0);
};
sampler samplerC = sampler_state
{
Texture = <textureC>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressV = BORDER;
AddressU = BORDER;
BorderColor = float4(0,0,0,0);
};
struct VS_IN
{
float4 pos : POSITION;
float2 tex : TEXCOORD0;
};
struct VS_OUT
{
float4 pos : POSITION;
float2 tex : TEXCOORD0;
};
VS_OUT VS( VS_IN vIn )
{
VS_OUT vOut;
vOut.pos = vIn.pos;
vOut.tex = vIn.tex;
return vOut;
}
float4 PS( VS_OUT vIn ) : COLOR
{
float4 tex = tex2D( samplerB, vIn.tex );
float4 ppp = tex2D( samplerC, vIn.tex );
if( bBorder )
{
tex.x*= 1.02;
tex.x-= 0.01;
tex.y*= 1.02;
tex.y-= 0.01;
}
float4 vOut = tex2D( samplerA, tex.xy );
vOut.rgb*= ppp.rgb;
vOut.rgb*= ppp.a;
vOut.a = 1;
return vOut;
}
technique renderBC
{
pass P0
{
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PS();
}
}
Code: Select all
ID3DXBuffer* err = NULL;
// load and compile effect
HRESULT hr = D3DXCreateEffect( pDevice,
__szEffect,
sizeof( __szEffect),
NULL,
NULL,
0,
NULL,
&renderWindowResources->effect,
&err);
if( FAILED( hr ) )
{
THROW_EXCEPT((char*)err->GetBufferPointer(), "D3D9::acquire");
}
SAFE_RELEASE( err );Code: Select all
DX9PipelineState state( mDevice );
hr = pDevice->SetRenderTarget( 0, renderWindowResources->backBufferReal );
hr = pDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
hr = pDevice->BeginScene();
hr = pDevice->SetViewport( &renderWindowResources->viewPort );
hr = renderWindowResources->effect->SetTechnique( renderWindowResources->effect->GetTechniqueByName( "renderBC" ) );
hr = renderWindowResources->effect->SetTexture( "textureA", renderWindowResources->backBufferTex );
hr = renderWindowResources->effect->SetTexture( "textureB", renderWindowResources->texture1 );
hr = renderWindowResources->effect->SetTexture( "textureC", renderWindowResources->texture2 );
hr = renderWindowResources->effect->SetBool ( "bBorder", false );
UINT uPasses;
renderWindowResources->effect->Begin( &uPasses, 0 );
for( UINT uPass = 0; uPass < uPasses; ++uPass )
{
renderWindowResources->effect->BeginPass( uPass );
pDevice->SetFVF( D3DFVF_CUSTOMVERTEXRHW );
pDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, __vertices, sizeof(__vertices[0]) );
renderWindowResources->effect->EndPass();
}
renderWindowResources->effect->End();
hr = pDevice->EndScene();
I could create the two images required for the original shader and I can compile the shader like this:
Code: Select all
Ogre::HighLevelGpuProgramPtr ps = Ogre::HighLevelGpuProgramManager::getSingletonPtr()->createProgram("special_ps", "General", "hlsl", Ogre::GPT_FRAGMENT_PROGRAM);
ps->setSource("float4 PS() : COLOR\n"
"{\n"
" return float4(0.5, 0.075, 0.075, 1.0);\n"
"}");
ps->load();
Code: Select all
mRoot->initialiseCompositor();
Ogre::CompositorManager2* compMan = mRoot->getCompositorManager2();
const Ogre::String workspaceName = "default scene workspace";
const Ogre::IdString workspaceNameHash = workspaceName;
compMan->createBasicWorkspaceDef(workspaceName, Ogre::ColourValue::Black);
compMan->addWorkspace(mSceneMgr, mWindow, mCamera, workspaceNameHash, true);
Transporter

