here is an other effect, it is Glow effects.
Screenshots , the left faerie has glow effect ,the right one has not.
Code: Select all
/****************************************************
Glow effect with CG
based on (Real-Time "TRON 2.0" Glow in Half-Life)
http://collective.valve-erc.com/index.php?go=tron1
adapted By Emil Halim
****************************************************/
#include <MagicIncludes.h>
// global declration of Irrlicht interfaces
IrrlichtDevice* device;
IVideoDriver* driver;
ISceneManager* smgr;
bool ProgramRun;
int main()
{
device = createDevice(EDT_OPENGL, dimension2d<s32>(640, 480), 32);
bool rslt = InitMagic(device);
if(rslt == false)
printf("Magic Library will only work with OpenGL driver");
driver = device->getVideoDriver();
smgr = device->getSceneManager();
TCGShader* cgProg = new TCGShader;
cgProg->AddToVertexProgram("void main( float4 position : POSITION, ");
cgProg->AddToVertexProgram(" float4 color : COLOR, ");
cgProg->AddToVertexProgram(" float2 texCoord : TEXCOORD, ");
cgProg->AddToVertexProgram(" out float4 oPosition : POSITION, ");
cgProg->AddToVertexProgram(" out float4 oColor : COLOR, ");
cgProg->AddToVertexProgram(" out float2 oTexCoord0 : TEXCOORD0, ");
cgProg->AddToVertexProgram(" out float2 oTexCoord1 : TEXCOORD1, ");
cgProg->AddToVertexProgram(" out float2 oTexCoord2 : TEXCOORD2, ");
cgProg->AddToVertexProgram(" out float2 oTexCoord3 : TEXCOORD3, ");
cgProg->AddToVertexProgram(" out float2 oTexCoord4 : TEXCOORD4, ");
cgProg->AddToVertexProgram(" uniform float XOffset, ");
cgProg->AddToVertexProgram(" uniform float YOffset, ");
cgProg->AddToVertexProgram(" uniform float4x4 ModelViewProj) ");
cgProg->AddToVertexProgram("{ ");
cgProg->AddToVertexProgram(" oPosition = mul(ModelViewProj,position); ");
cgProg->AddToVertexProgram(" oColor = color; ");
cgProg->AddToVertexProgram(" oTexCoord0 = texCoord + float2(XOffset,YOffset); ");
cgProg->AddToVertexProgram(" oTexCoord1 = texCoord + float2(XOffset*2,YOffset*2); ");
cgProg->AddToVertexProgram(" oTexCoord2 = texCoord - float2(XOffset,YOffset); ");
cgProg->AddToVertexProgram(" oTexCoord3 = texCoord - float2(XOffset*2,YOffset*2); ");
cgProg->AddToVertexProgram(" oTexCoord4 = texCoord; ");
cgProg->AddToVertexProgram("} ");
cgProg->setVertexProfile(CG_PROFILE_ARBVP1);
cgProg->CompileVertexProgram("main");
printf("%s \n", cgProg->GetCompiledVertexProgram());
cgProg->AddToPixelProgram("void main( float2 TexCoord0 : TEXCOORD0, ");
cgProg->AddToPixelProgram(" float2 TexCoord1 : TEXCOORD1, ");
cgProg->AddToPixelProgram(" float2 TexCoord2 : TEXCOORD2, ");
cgProg->AddToPixelProgram(" float2 TexCoord3 : TEXCOORD3, ");
cgProg->AddToPixelProgram(" float2 TexCoord4 : TEXCOORD4, ");
cgProg->AddToPixelProgram(" out float4 color : COLOR, ");
cgProg->AddToPixelProgram(" uniform sampler2D txtr0 : texunit0, ");
cgProg->AddToPixelProgram(" uniform sampler2D txtr1 : texunit1) ");
cgProg->AddToPixelProgram("{ ");
cgProg->AddToPixelProgram(" float4 col1 = tex2D(txtr0, TexCoord0) / 2.0f; ");
cgProg->AddToPixelProgram(" float4 col2 = tex2D(txtr0, TexCoord1) / 2.0f; ");
cgProg->AddToPixelProgram(" float4 col3 = tex2D(txtr0, TexCoord2) / 2.0f; ");
cgProg->AddToPixelProgram(" float4 col4 = tex2D(txtr0, TexCoord3) / 2.0f; ");
cgProg->AddToPixelProgram(" float4 avg1 = (col1 + col2) / 2.0f; ");
cgProg->AddToPixelProgram(" float4 avg2 = (col3 + col4) / 2.0f; ");
cgProg->AddToPixelProgram(" float4 blur = avg1 + avg2; ");
cgProg->AddToPixelProgram(" float4 newCol = tex2D(txtr0, TexCoord4); ");
cgProg->AddToPixelProgram(" float4 dark = newCol * newCol ; ");
cgProg->AddToPixelProgram(" color = dark+blur; ");
cgProg->AddToPixelProgram("} ");
cgProg->setPixelProfile(CG_PROFILE_ARBFP1);
cgProg->CompilePixelProgram("main");
printf("%s \n", cgProg->GetCompiledPixelProgram());
CGparameter XOffsetParam = cgProg->GetVertexVariable("XOffset");
CGparameter YOffsetParam = cgProg->GetVertexVariable("YOffset");
CGparameter ModelViewProjParam = cgProg->GetVertexVariable("ModelViewProj");
TCGAnimatedMesh* node = new TCGAnimatedMesh("../../media/faerie.md2",smgr->getRootSceneNode(), smgr, -1);
node->setMaterialFlag(EMF_LIGHTING, false);
node->setAnimationSpeed(0.05 );
node->setShaderProgram(cgProg);
node->setRotation(core::vector3df(0,90,0));
node->setPosition(core::vector3df(-15,10,0));
node->setMaterialTexture( 0, driver->getTexture("../../media/Faerie5.bmp") );
TCGAnimatedMesh* node1 = new TCGAnimatedMesh("../../media/faerie.md2",smgr->getRootSceneNode(), smgr, -1);
node1->setMaterialFlag(EMF_LIGHTING, false);
node1->setAnimationSpeed(0.05 );
node1->setRotation(core::vector3df(0,90,0));
node1->setPosition(core::vector3df(15,10,0));
node1->setMaterialTexture( 0, driver->getTexture("../../media/Faerie5.bmp") );
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS(0, 10.0f, 10.0f);
cam->setPosition(core::vector3df(0,30,-70));
cam->setTarget(core::vector3df(0,0,0));
HideMouse();
ProgramRun = true;
int lastFPS = -1;
while(device->run()&& ProgramRun)
{
driver->beginScene(true, true, SColor(0,200,200,200));
if(KeyDown(KEY_ESCAPE))ProgramRun=false;
cgGLSetStateMatrixParameter(ModelViewProjParam,CG_GL_MODELVIEW_PROJECTION_MATRIX,
CG_GL_MATRIX_IDENTITY);
cgGLSetParameter1f(XOffsetParam,0.002f);
cgGLSetParameter1f(YOffsetParam,0.002f);
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
wchar_t tmp[1024];
swprintf(tmp, 1024, L"Glow effect with CG (%s)(fps:%d)",driver->getName(), fps);
device->setWindowCaption(tmp);
lastFPS = fps;
}
}
device->drop();
return 0;
}