FullScreenEffects in TGEA 1.8
by Siddartha · 05/25/2009 (8:36 pm) · 6 comments
Hi,
I followed firstly this resource
http://www.garagegames.com/community/resources/view/9104
then I integrated the available TGEA 1.7 code update to enable fullscreen effects in TGEA 1.8.
then I modified the files gametsctrl files.
Step 1 : First open GameTSCtrl.h
Step 2 : add the following parameters after the shader parameters
GFXShaderConstBufferRef mConsts;
GFXShaderConstHandle* mModelViewProj;
Step 3 : Open GameTSCtrl.cpp
Step 4 : Goto constructor GameTSCtrl
Step 5 : add this
mConsts = NULL;
Step 6 : In same constructor add as follow
if( mExampleEffectShader )
{
mExampleEffectShader->initShader();
mConsts = mExampleEffectShader->mShader->allocConstBuffer(); //newly added line
if (mConsts)
mExampleEffectShader->mapSamplerNames(mConsts);
Con::errorf("mExampleEffectShader LOADED!!");
}
Step 7 : Add this at the end of constructor
GFXVideoMode vm;
const String resString = Con::getVariable("$pref::Video::mode");
vm.parseFromString(resString);
for (int i =0; i < 3; i++)
mSurface[i].set( vm.resolution.x, vm.resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - mSurface[i] (line %d)", __FUNCTION__, __LINE__), 1 );
Step 8 : Now goto renderWorldEffect function and modify the function as follows
FrameAllocator::setWaterMark(0);
// TGEA 1.8 MOD - Begin
if (mRenderTarget == NULL)
mRenderTarget = GFX->allocRenderToTextureTarget();
/* Point2I cursize = gClientSceneGraph->getDisplayTargetResolution();
for (int i =0; i < 3; i++)
{
if (mSurface[i].isNull())
mSurface[i] = GFX->getTextureManager()->createTexture(cursize.x, cursize.y,32,bits,GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile);
} */
// TGEA 1.8 MOD - End
// rectangle points for calcs later
Point2I a = updateRect.point;
Point2I b = updateRect.point + updateRect.extent;
GFXStateBlockDesc desc;
desc.setZEnable( true );
desc.stencilFunc = GFXCmpLessEqual;
GFXStateBlockRef block;
block = GFX->createStateBlock(desc);
//GFX->setZEnable( true ); //glEnable(GL_DEPTH_TEST);
//GFX->setZFunc( GFXCmpLessEqual ); //glDepthFunc(GL_LEQUAL);
// Update the dynamic cubemaps on reflective objects
SimSet *reflectSet = dynamic_cast<SimSet*>( Sim::findObject( "reflectiveSet" ) );
for( SimSetIterator itr(reflectSet); *itr; ++itr )
{
if( *itr )
{
SceneObject *obj = (SceneObject*) *itr;
obj->updateReflection();
}
}
// Need to consoldate to one clear call // glClear(GL_DEPTH_BUFFER_BIT);
//GFX->setCullMode( GFXCullNone );//glDisable(GL_CULL_FACE);
//GFX->setFillMode(fMode);
desc.setCullMode( GFXCullNone );
desc.fillMode = fMode ;
block = GFX->createStateBlock(desc);
// TGEA 1.8 MOD - Begin
GFX->pushActiveRenderTarget();
// Set a starting texture so we can bind w/o any nulls.
mRenderTarget->attachTexture(GFXTextureTarget::Color0, mSurface[0]);
mRenderTarget->attachTexture(GFXTextureTarget::DepthStencil, GFXTextureTarget::sDefaultDepthStencil);
GFX->setActiveRenderTarget(mRenderTarget);
// TGEA 1.8 MOD - End
// if it's wireframe we have to clear every frame
if (fMode == GFXFillWireframe)
{
GFX->clear( GFXClearTarget, ColorI(0.5,0.5,0.5,0.5), 1.0f, 0 );
}
// assign the render mask if one came in
if (objMask)
{
gClientSceneGraph->renderScene( objMask );
}
else
{
gClientSceneGraph->renderScene( );
}
//GFX->setFillMode(GFXFillSolid);
desc.fillMode = GFXFillSolid ;
block = GFX->createStateBlock(desc);
// TGEA 1.8 MOD - Begin
mRenderTarget->attachTexture(GFXTextureTarget::Color0, NULL);
mRenderTarget->attachTexture(GFXTextureTarget::DepthStencil, NULL);
GFX->popActiveRenderTarget();
// TGEA 1.8 MOD - End
// set the clip
GFX->setClipRect(updateRect);
// turn off z clipping
//GFX->setZEnable( false );
desc.setZEnable(false);
block = GFX->createStateBlock(desc);
//************************************
//************************************
//************************************
mModelViewProj = mEffectShader->mShader->getShaderConstHandle(ShaderGenVars::modelview);
//after this is all surfaces
//**************************************
// set ortho projection matrix
// this makes ur view of the effect appears as directly above
MatrixF proj = GFX->getProjectionMatrix();
MatrixF newMat(true);
GFX->setProjectionMatrix( newMat );
GFX->pushWorldMatrix();
GFX->setWorldMatrix( newMat );
mConsts->set(mModelViewProj, newMat);
GFX->setStateBlock(block);
// GFX->SetVertexShaderConstantF( 0, (float*)&newMat, 4 ); // send the matrix to the shader
//**********************************
// ortho geometry
GFXVertexBuffer *vb=NULL;
PrimBuild::color4f( mFilterColor.red , mFilterColor.green , mFilterColor.blue, mFilterColor.alpha );
PrimBuild::beginToBuffer( GFXTriangleFan, 4 );
PrimBuild::texCoord2f( 0.0, 1.0 );
PrimBuild::vertex3f( -1.0 , -1.0 , 0.0 );
PrimBuild::texCoord2f( 0.0, 0.0 );
PrimBuild::vertex3f( -1.0 , 1.0 , 0.0 );
PrimBuild::texCoord2f( 1.0, 0.0 );
PrimBuild::vertex3f( 1.0 , 1.0 , 0.0 );
PrimBuild::texCoord2f( 1.0, 1.0 );
PrimBuild::vertex3f( 1.0 , -1.0 , 0.0 );
U32 numPrims;
vb = PrimBuild::endToBuffer( numPrims );
mEffectShader->mShader->process();
GFX->setShaderConstBuffer(mConsts);
GFX->setTexture( 0, mSurface[0] );
GFX->setVertexBuffer( vb );
GFX->drawPrimitive( GFXTriangleFan, 0, 2 );
GFX->disableShaders();
//**********************************************
// render state cleanup
/*GFX->setAlphaBlendEnable( false );
GFX->setCullMode( GFXCullNone );
GFX->setLightingEnable( false );
GFX->setZWriteEnable( true );
GFX->setTextureStageColorOp( 0, GFXTOPDisable );*/
desc.alphaTestEnable = false ;
desc.setCullMode( GFXCullNone );
desc.ffLighting = false ;
desc.zWriteEnable = true ;
desc.samplers[0].textureColorOp = GFXTOPDisable ;
//desc.samplers[1].textureColorOp = GFXTOPDisable ;
//desc.samplers[2].textureColorOp = GFXTOPDisable ;
//desc.samplers[3].textureColorOp = GFXTOPDisable ;
block = GFX->createStateBlock(desc);
GFX->setStateBlock(block);
GFX->disableShaders();
GFX->popWorldMatrix();
FrameAllocator::setWaterMark(0);
Step 9: Now again follow the http://www.garagegames.com/community/resources/view/9104 instructions to play shaders through console editor.
Any Queries regarding are welcomed ..........
:)
I followed firstly this resource
http://www.garagegames.com/community/resources/view/9104
then I integrated the available TGEA 1.7 code update to enable fullscreen effects in TGEA 1.8.
then I modified the files gametsctrl files.
Step 1 : First open GameTSCtrl.h
Step 2 : add the following parameters after the shader parameters
GFXShaderConstBufferRef mConsts;
GFXShaderConstHandle* mModelViewProj;
Step 3 : Open GameTSCtrl.cpp
Step 4 : Goto constructor GameTSCtrl
Step 5 : add this
mConsts = NULL;
Step 6 : In same constructor add as follow
if( mExampleEffectShader )
{
mExampleEffectShader->initShader();
mConsts = mExampleEffectShader->mShader->allocConstBuffer(); //newly added line
if (mConsts)
mExampleEffectShader->mapSamplerNames(mConsts);
Con::errorf("mExampleEffectShader LOADED!!");
}
Step 7 : Add this at the end of constructor
GFXVideoMode vm;
const String resString = Con::getVariable("$pref::Video::mode");
vm.parseFromString(resString);
for (int i =0; i < 3; i++)
mSurface[i].set( vm.resolution.x, vm.resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - mSurface[i] (line %d)", __FUNCTION__, __LINE__), 1 );
Step 8 : Now goto renderWorldEffect function and modify the function as follows
FrameAllocator::setWaterMark(0);
// TGEA 1.8 MOD - Begin
if (mRenderTarget == NULL)
mRenderTarget = GFX->allocRenderToTextureTarget();
/* Point2I cursize = gClientSceneGraph->getDisplayTargetResolution();
for (int i =0; i < 3; i++)
{
if (mSurface[i].isNull())
mSurface[i] = GFX->getTextureManager()->createTexture(cursize.x, cursize.y,32,bits,GFXFormatR8G8B8X8, &GFXDefaultRenderTargetProfile);
} */
// TGEA 1.8 MOD - End
// rectangle points for calcs later
Point2I a = updateRect.point;
Point2I b = updateRect.point + updateRect.extent;
GFXStateBlockDesc desc;
desc.setZEnable( true );
desc.stencilFunc = GFXCmpLessEqual;
GFXStateBlockRef block;
block = GFX->createStateBlock(desc);
//GFX->setZEnable( true ); //glEnable(GL_DEPTH_TEST);
//GFX->setZFunc( GFXCmpLessEqual ); //glDepthFunc(GL_LEQUAL);
// Update the dynamic cubemaps on reflective objects
SimSet *reflectSet = dynamic_cast<SimSet*>( Sim::findObject( "reflectiveSet" ) );
for( SimSetIterator itr(reflectSet); *itr; ++itr )
{
if( *itr )
{
SceneObject *obj = (SceneObject*) *itr;
obj->updateReflection();
}
}
// Need to consoldate to one clear call // glClear(GL_DEPTH_BUFFER_BIT);
//GFX->setCullMode( GFXCullNone );//glDisable(GL_CULL_FACE);
//GFX->setFillMode(fMode);
desc.setCullMode( GFXCullNone );
desc.fillMode = fMode ;
block = GFX->createStateBlock(desc);
// TGEA 1.8 MOD - Begin
GFX->pushActiveRenderTarget();
// Set a starting texture so we can bind w/o any nulls.
mRenderTarget->attachTexture(GFXTextureTarget::Color0, mSurface[0]);
mRenderTarget->attachTexture(GFXTextureTarget::DepthStencil, GFXTextureTarget::sDefaultDepthStencil);
GFX->setActiveRenderTarget(mRenderTarget);
// TGEA 1.8 MOD - End
// if it's wireframe we have to clear every frame
if (fMode == GFXFillWireframe)
{
GFX->clear( GFXClearTarget, ColorI(0.5,0.5,0.5,0.5), 1.0f, 0 );
}
// assign the render mask if one came in
if (objMask)
{
gClientSceneGraph->renderScene( objMask );
}
else
{
gClientSceneGraph->renderScene( );
}
//GFX->setFillMode(GFXFillSolid);
desc.fillMode = GFXFillSolid ;
block = GFX->createStateBlock(desc);
// TGEA 1.8 MOD - Begin
mRenderTarget->attachTexture(GFXTextureTarget::Color0, NULL);
mRenderTarget->attachTexture(GFXTextureTarget::DepthStencil, NULL);
GFX->popActiveRenderTarget();
// TGEA 1.8 MOD - End
// set the clip
GFX->setClipRect(updateRect);
// turn off z clipping
//GFX->setZEnable( false );
desc.setZEnable(false);
block = GFX->createStateBlock(desc);
//************************************
//************************************
//************************************
mModelViewProj = mEffectShader->mShader->getShaderConstHandle(ShaderGenVars::modelview);
//after this is all surfaces
//**************************************
// set ortho projection matrix
// this makes ur view of the effect appears as directly above
MatrixF proj = GFX->getProjectionMatrix();
MatrixF newMat(true);
GFX->setProjectionMatrix( newMat );
GFX->pushWorldMatrix();
GFX->setWorldMatrix( newMat );
mConsts->set(mModelViewProj, newMat);
GFX->setStateBlock(block);
// GFX->SetVertexShaderConstantF( 0, (float*)&newMat, 4 ); // send the matrix to the shader
//**********************************
// ortho geometry
GFXVertexBuffer *vb=NULL;
PrimBuild::color4f( mFilterColor.red , mFilterColor.green , mFilterColor.blue, mFilterColor.alpha );
PrimBuild::beginToBuffer( GFXTriangleFan, 4 );
PrimBuild::texCoord2f( 0.0, 1.0 );
PrimBuild::vertex3f( -1.0 , -1.0 , 0.0 );
PrimBuild::texCoord2f( 0.0, 0.0 );
PrimBuild::vertex3f( -1.0 , 1.0 , 0.0 );
PrimBuild::texCoord2f( 1.0, 0.0 );
PrimBuild::vertex3f( 1.0 , 1.0 , 0.0 );
PrimBuild::texCoord2f( 1.0, 1.0 );
PrimBuild::vertex3f( 1.0 , -1.0 , 0.0 );
U32 numPrims;
vb = PrimBuild::endToBuffer( numPrims );
mEffectShader->mShader->process();
GFX->setShaderConstBuffer(mConsts);
GFX->setTexture( 0, mSurface[0] );
GFX->setVertexBuffer( vb );
GFX->drawPrimitive( GFXTriangleFan, 0, 2 );
GFX->disableShaders();
//**********************************************
// render state cleanup
/*GFX->setAlphaBlendEnable( false );
GFX->setCullMode( GFXCullNone );
GFX->setLightingEnable( false );
GFX->setZWriteEnable( true );
GFX->setTextureStageColorOp( 0, GFXTOPDisable );*/
desc.alphaTestEnable = false ;
desc.setCullMode( GFXCullNone );
desc.ffLighting = false ;
desc.zWriteEnable = true ;
desc.samplers[0].textureColorOp = GFXTOPDisable ;
//desc.samplers[1].textureColorOp = GFXTOPDisable ;
//desc.samplers[2].textureColorOp = GFXTOPDisable ;
//desc.samplers[3].textureColorOp = GFXTOPDisable ;
block = GFX->createStateBlock(desc);
GFX->setStateBlock(block);
GFX->disableShaders();
GFX->popWorldMatrix();
FrameAllocator::setWaterMark(0);
Step 9: Now again follow the http://www.garagegames.com/community/resources/view/9104 instructions to play shaders through console editor.
Any Queries regarding are welcomed ..........
:)
About the author
WebSites: www.siddartha.info Myblogs: http://schoolofgaming.blogspot.com http://techtoolsreviewer.blogspot.com http://coolgamescreens.blogspot.com
#2
What Konrad is strongly hinting at is that you should edit and make use of the [ code ] tags -- it will certainly make things look nicer and easier to follow.
EDIT: have to ask since it doesn't show, but are you an owner and have a license?
05/26/2009 (7:54 am)
Will have to give this a try. What Konrad is strongly hinting at is that you should edit and make use of the [ code ] tags -- it will certainly make things look nicer and easier to follow.
EDIT: have to ask since it doesn't show, but are you an owner and have a license?
#3
05/26/2009 (9:40 am)
video?
#4
05/26/2009 (10:19 am)
cool
#6
05/27/2009 (5:07 am)
- nevermind - :) 
Associate Konrad Kiss
Bitgap Games