(C++)Irrlicht 1.1 : Fake Glow,Dream and Night Vision
Since the links on the main post are down I uploaded it here:
http://irrlichtirc.g0dsoft.com/Simson/Demo_N3.rar
It's still for Irrlicht 1.1, so when someone gets the time they should convert it.
Cheers
http://irrlichtirc.g0dsoft.com/Simson/Demo_N3.rar
It's still for Irrlicht 1.1, so when someone gets the time they should convert it.
Cheers
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
-
- Posts: 101
- Joined: Wed Dec 03, 2008 5:33 pm
- Location: ger
i have got a tip for you, since you render the scene multiple times via
you should the camera prevent from receiving input events, so it cant move while the actual effect is not rendered complete.
otherwise, the cam moves, and you can see the effect, but you can also see the original castle, (i noticed it especially in nightvision) a little bit moved away from where the nightvision'ed castle is ... hard to explain, i hope you know what i mean ^^
Code: Select all
driver->beginScene(...);
smgr->drawAll();
driver->endScene()
you should the camera prevent from receiving input events, so it cant move while the actual effect is not rendered complete.
otherwise, the cam moves, and you can see the effect, but you can also see the original castle, (i noticed it especially in nightvision) a little bit moved away from where the nightvision'ed castle is ... hard to explain, i hope you know what i mean ^^
i love skateboarding!
hey
if someone could update this to 1.5 that would be sweet!!
Re: hey
nice effects, i port to 1.6 but not work ...tecan wrote:if someone could update this to 1.5 that would be sweet!!
the code :
http://www.megaupload.com/?d=YRH3LKIY
will be the quads? i am beginner,
please help..!!!
Bennu (Best 2d and 3D dev-tool)
http://bennupack.blogspot.com
Pixtudio (Best 2D development tool)
http://pixtudiopack.blogspot.com
Bennu3D(3D Libs for bennu)
http://3dm8ee.blogspot.com/
Colombian Developers - Blog:
http://coldev.blogspot.com/
http://bennupack.blogspot.com
Pixtudio (Best 2D development tool)
http://pixtudiopack.blogspot.com
Bennu3D(3D Libs for bennu)
http://3dm8ee.blogspot.com/
Colombian Developers - Blog:
http://coldev.blogspot.com/
I guess i'm just confused how it works.
Render the scene to a texture that you then scale slightly in some direction(s) and make transparent (or additive w/ transparent_color_add) then draw the texture repeating the process. This will give a 'blurred' feel i guess.
Then you'd have to render that texture in 2D rather then 3D so you can move the camera fast without losing the filter.
I'll mess with it..
Render the scene to a texture that you then scale slightly in some direction(s) and make transparent (or additive w/ transparent_color_add) then draw the texture repeating the process. This will give a 'blurred' feel i guess.
Then you'd have to render that texture in 2D rather then 3D so you can move the camera fast without losing the filter.
I'll mess with it..
-
- Competition winner
- Posts: 95
- Joined: Wed Nov 30, 2005 8:53 am
- Location: France : midi pyrénées
CEffects.cpp
CEffects.h
main.cpp
Code: Select all
/*-----------------------------------------
Programmed by Fabre Cédric
(Copland/simson) 02/10/2006
Thanks to the Irrlicht team
for this good 3D engine !
This code has not been tested under Linux.
If you find any errors or corrections,
in advance thanks you for any feedbacks.
-------------------------------------------
Contact : cf46@coder3d.com
-----------------------------------------*/
#include <irrlicht.h>
#include "CEffects.h"
using namespace irr;
CQuadSceneNode::CQuadSceneNode(scene::ISceneNode* parent,scene::ISceneManager* mgr,s32 id): scene::ISceneNode(parent, mgr, id)
{
Material.Lighting = false;
Material.Wireframe = false;
Material.ZBuffer = false;
Material.ZWriteEnable = false;
Material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
Material.BackfaceCulling = false;
Material.MaterialTypeParam = 0.01f;
VertexQuad[0].TCoords.set(0.0f, 0.0f);
VertexQuad[1].TCoords.set(1.0f, 0.0f);
VertexQuad[2].TCoords.set(0.0f, 1.0f);
VertexQuad[3].TCoords.set(1.0f, 1.0f);
VertexQuad[0].Color = video::SColor(10,60,60,60);
VertexQuad[1].Color = video::SColor(10,60,60,60);
VertexQuad[2].Color = video::SColor(10,60,60,60);
VertexQuad[3].Color = video::SColor(10,60,60,60);
Indices[0] = 0;
Indices[1] = 1;
Indices[2] = 2;
Indices[3] = 3;
Indices[4] = 2;
Indices[5] = 1;
Box.reset(VertexQuad[0].Pos);
for (s32 i=1; i<4; ++i)
{
Box.addInternalPoint(VertexQuad[i].Pos);
}
AutomaticCullingState = scene::EAC_OFF;
}
void CQuadSceneNode::OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
void CQuadSceneNode::Update()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
scene::ICameraSceneNode *camera = SceneManager->getActiveCamera();
f32 resultat = cos((camera->getFOV()/2));
resultat = 10.001f/resultat;
resultat = (resultat*resultat) - (10.001f*10.001f);
resultat = sqrt(resultat);
f32 ScaleY = resultat;
f32 ScaleX = resultat * camera->getAspectRatio();
core::vector3df Scale3D(ScaleX,ScaleY,0.0f);
VertexQuad[0].Pos = Scale3D*core::vector3df(-1.0f,1.0f,0);//Haut Gauche
VertexQuad[1].Pos = Scale3D*core::vector3df(1.0f,1.0f,0);//Haut Droite
VertexQuad[2].Pos = Scale3D*core::vector3df(-1.0f,-1.0f,0);//Bas Gauche
VertexQuad[3].Pos = Scale3D*core::vector3df(1.0f,-1.0f,0);//Bas Droite
Box.reset(VertexQuad[0].Pos);
for (s32 i=0; i<4; ++i)
Box.addInternalPoint(VertexQuad[i].Pos);
}
void CQuadSceneNode::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
scene::ICameraSceneNode *camera = SceneManager->getActiveCamera();
core::matrix4 mv = camera->getViewMatrix();
mv.makeInverse();
core::matrix4 translation;
translation.setTranslation(core::vector3df(0,0,10.001f+getScale().Z));
mv*=translation;
Update();
driver->setTransform(video::ETS_WORLD, mv);
driver->setMaterial(Material);
driver->drawIndexedTriangleList(&VertexQuad[0], 4, &Indices[0], 2);
}
const core::aabbox3d<f32>& CQuadSceneNode::getBoundingBox() const
{
return Box;
}
u32 CQuadSceneNode::getMaterialCount() const
{
return 1;
}
video::SMaterial& CQuadSceneNode::getMaterial(u32 i)
{
return Material;
}
//Méthode de création du Glow
void CEffects::CreateGlow(scene::ICameraSceneNode* CamGlow,scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 GlowSize=64)
{
//On vérifi que la carte vidéo soit cappable d'utiliser le Render To Texture
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
{
//Ici on creer notre Render Texture
this->RTexGlow=driver->addRenderTargetTexture(core::dimension2d<u32>(GlowSize,GlowSize),"TT1");
//Ici on va créer plusieurs quad pour simuler un effet de Blur
for (int nbquad=0;nbquad<=3;nbquad++)
{
this->QuadGlow[nbquad] = new CQuadSceneNode(smgr->getRootSceneNode(), smgr, -1);
QuadGlow[nbquad]->setScale(irr::core::vector3df(0,0,-nbquad/10.0f));
this->QuadGlow[nbquad]->setMaterialTexture(0,RTexGlow);
this->QuadGlow[nbquad]->drop();
}
}
}
//Méthode de rendu du Glow
void CEffects::RenderGlow(scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 gA=0,s32 gR=0,s32 gG=0,s32 gB=0)
{
//On test si le Render Texture existe bien
if (this->RTexGlow != NULL)
{
for (int i=0;i<=3;i++)
{
if (this->QuadGlow[i] != NULL)
{
this->QuadGlow[i]->setVisible(false);
}
}
//On affiche notre scene
driver->setRenderTarget(this->RTexGlow, true, true, video::SColor(gA,gR,gG,gB));
smgr->drawAll();
driver->setRenderTarget(0);
for (int i=0;i<=3;i++)
{
if (this->QuadGlow[i] != NULL)
{
this->QuadGlow[i]->setVisible(true);
}
}
}
}
//Méthode de suppression du Glow
void CEffects::DeleteGlow()
{
if (RTexGlow){RTexGlow->drop();}
for (int i=0;i<=3;i++)
{
if (QuadGlow[i] != NULL){QuadGlow[i]->remove();}
}
}
//Méthode de création du filtre Dream
void CEffects::CreateDream(scene::ICameraSceneNode* CamDream,scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 DreamSize=64)
{
//On vérifi que la carte vidéo soit cappable d'utiliser le Render To Texture
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
{
//Ici on creer notre Render Texture
this->RTexDream=driver->addRenderTargetTexture(core::dimension2d<u32>(DreamSize,DreamSize),"TT2");
//Ici on va créer plusieurs quad pour simuler un effet de Blur
for (int nbquad=0;nbquad<=6;nbquad++)
{
this->QuadDream[nbquad] = new CQuadSceneNode(smgr->getRootSceneNode(), smgr, -1);
QuadDream[nbquad]->setScale(irr::core::vector3df(0,0,-nbquad/1.5f));
this->QuadDream[nbquad]->setMaterialTexture(0,RTexDream);
this->QuadDream[nbquad]->drop();
}
}
}
//Méthode de rendu du filtre Dream
void CEffects::RenderDream(scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 gA=0,s32 gR=0,s32 gG=0,s32 gB=0)
{
//On test si le Render Texture existe bien
if (this->RTexDream != NULL)
{
for (int i=0;i<=6;i++)
{
if (this->QuadDream[i] != NULL)
{
this->QuadDream[i]->setVisible(false);
}
}
//On affiche notre scene
driver->setRenderTarget(this->RTexDream, true, true, video::SColor(gA,gR,gG,gB));
smgr->drawAll();
driver->setRenderTarget(0);
for (int i=0;i<=6;i++)
{
if (this->QuadDream[i] != NULL)
{
this->QuadDream[i]->setVisible(true);
}
}
}
}
//Méthode de suppression du filtre Dream
void CEffects::DeleteDream()
{
if (RTexDream){RTexDream->drop();}
for (int i=0;i<=6;i++)
{
if (QuadDream[i] != NULL){QuadDream[i]->remove();}
}
}
void CEffects::CreateVision(scene::ICameraSceneNode* CamVision,scene::ISceneManager* smgr,video::IVideoDriver* driver,irr::c8* NoiseFile,s32 VisionSize)
{
irr::video::ITexture* NoiseTexture = driver->getTexture(NoiseFile);
//On vérifi que la carte vidéo soit cappable d'utiliser le Render To Texture
if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
{
//Ici on creer notre Render Texture
this->RTexVision=driver->addRenderTargetTexture(core::dimension2d<u32>(VisionSize,VisionSize),"TT3");
//Ici on va créer plusieurs quad pour simuler un effet de Blur
for (int nbquad=0;nbquad<=1;nbquad++)
{
this->QuadVision[nbquad] = new CQuadSceneNode(smgr->getRootSceneNode(), smgr, -1);
QuadVision[nbquad]->getMaterial(0).DiffuseColor = video::SColor(10,10,120,10);
QuadVision[nbquad]->getMaterial(0).EmissiveColor = video::SColor(10,10,120,10);
QuadVision[nbquad]->getMaterial(0).AmbientColor = video::SColor(10,10,120,10);
QuadVision[nbquad]->getMaterial(0).SpecularColor = video::SColor(10,10,120,10);
QuadVision[nbquad]->getMaterial(0).Lighting=true;
if (nbquad < 1)
{
this->QuadVision[nbquad]->setMaterialTexture(0,RTexVision);
}
else
{
QuadVision[nbquad]->setMaterialTexture(0,NoiseTexture);
}
QuadVision[nbquad]->setScale(irr::core::vector3df(0,0,-0.1f));
this->QuadVision[nbquad]->drop();
}
}
}
void CEffects::RenderVision(scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 gA,s32 gR,s32 gG,s32 gB)
{
//On test si le Render Texture existe bien
if (this->RTexVision != NULL)
{
for (int i=0;i<=1;i++)
{
if (this->QuadVision[i] != NULL)
{
this->QuadVision[i]->setVisible(false);
}
}
//On affiche notre scene
driver->setRenderTarget(this->RTexVision, true, true, video::SColor(gA,gR,gG,gB));
smgr->drawAll();
driver->setRenderTarget(0);
static int o=0;
o++;
if (o>=3)
{
o=0;
}
QuadVision[1]->setScale(irr::core::vector3df(0,0,-o/10.0f));
for (int i=0;i<=1;i++)
{
if (this->QuadVision[i] != NULL)
{
this->QuadVision[i]->setVisible(true);
}
}
}
}
void CEffects::DeleteVision()
{
if (RTexVision){RTexVision->drop();}
for (int i=0;i<=1;i++)
{
if (QuadVision[i] != NULL){QuadVision[i]->remove();}
}
}
void CEffects::RenderNothing()
{
for (int i=0;i<=3;i++)
{
if (this->QuadGlow[i] != NULL)
{
this->QuadGlow[i]->setVisible(false);
}
}
for (int i=0;i<=6;i++)
{
if (this->QuadDream[i] != NULL)
{
this->QuadDream[i]->setVisible(false);
}
}
for (int i=0;i<=1;i++)
{
if (this->QuadVision[i] != NULL)
{
this->QuadVision[i]->setVisible(false);
}
}
}
Code: Select all
/*-----------------------------------------
Programmed by Fabre Cédric
(Copland/simson) 02/10/2006
Thanks to the Irrlicht team
for this good 3D engine !
This code has not been tested under Linux.
If you find any errors or corrections,
in advance thanks you for any feedbacks.
-------------------------------------------
Contact : cf46@coder3d.com
-----------------------------------------*/
#ifndef _CEFFECTS_
#define _CEFFECTS_
#include <irrlicht.h>
using namespace irr;
//Classe QuadSceneNode pour dessiner un Quad perso
class CQuadSceneNode : public scene::ISceneNode
{
public:
CQuadSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id);
virtual void OnRegisterSceneNode();
virtual void render();
virtual const core::aabbox3d<f32>& getBoundingBox() const;
virtual u32 getMaterialCount() const;
virtual video::SMaterial& getMaterial(u32 i);
private :
core::aabbox3d<f32> Box;
video::S3DVertex VertexQuad[4];
u16 Indices[6];
video::SMaterial Material;
void Update();
};
class CEffects
{
public:
void CreateGlow(scene::ICameraSceneNode* CamGlow,scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 GlowSize);
void RenderGlow(scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 gA,s32 gR,s32 gG,s32 gB);
void DeleteGlow();
void CreateDream(scene::ICameraSceneNode* CamDream,scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 DreamSize);
void RenderDream(scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 gA,s32 gR,s32 gG,s32 gB);
void DeleteDream();
void CreateVision(scene::ICameraSceneNode* CamVision,scene::ISceneManager* smgr,video::IVideoDriver* driver,irr::c8* NoiseFile,s32 VisionSize);
void RenderVision(scene::ISceneManager* smgr,video::IVideoDriver* driver,s32 gA,s32 gR,s32 gG,s32 gB);
void DeleteVision();
void RenderNothing();
private:
CQuadSceneNode* QuadGlow[4];
video::ITexture* RTexGlow;
CQuadSceneNode* QuadDream[7];
video::ITexture* RTexDream;
CQuadSceneNode* QuadVision[2];
video::ITexture* RTexVision;
};
#endif
Code: Select all
/*
This Tutorial shows how to load a Quake 3 map into the
engine, create a SceneNode for optimizing the speed of
rendering and how to create a user controlled camera.
Lets start like the HelloWorld example: We include
the irrlicht header files and an additional file to be able
to ask the user for a driver type using the console.
*/
#include <irrlicht.h>
#include <iostream>
//Include the CEffects header
#include "CEffects.h"
/*
As already written in the HelloWorld example, in the Irrlicht
Engine, everything can be found in the namespace 'irr'.
To get rid of the irr:: in front of the name of every class,
we tell the compiler that we use that namespace from now on,
and we will not have to write that 'irr::'.
There are 5 other sub namespaces 'core', 'scene', 'video',
'io' and 'gui'. Unlike in the HelloWorld example,
we do not a 'using namespace' for these 5 other namespaces
because in this way you will see what can be found in which
namespace. But if you like, you can also include the namespaces
like in the previous example. Code just like you want to.
*/
using namespace irr;
/*
Again, to be able to use the Irrlicht.DLL file, we need to link with the
Irrlicht.lib. We could set this option in the project settings, but
to make it easy, we use a pragma comment lib:
*/
#pragma comment(lib, "Irrlicht.lib")
//Init the "RenderEffect" variable
int RenderEffect = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(const SEvent &event)
{
//Test if keyboard event and what key are pressed
if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown == false)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_N: RenderEffect=0;
return true;
case KEY_KEY_G: RenderEffect=1;
return true;
case KEY_KEY_D: RenderEffect=2;
return true;
case KEY_KEY_V: RenderEffect=3;
return true;
}
}
return false;
}
};
/*
Ok, lets start. Again, we use the main() method as start, not the
WinMain(), because its shorter to write.
*/
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType;
printf("Please select the driver you want for this example:\n"\
" (a) Direct3D 9.0c\n (b) OpenGL 1.5\n");
char i;
std::cin >> i;
//select the driver type with "a" or "b"
switch(i)
{
case 'a': driverType = video::EDT_DIRECT3D9;break;
case 'b': driverType = video::EDT_OPENGL; break;
default: return 1;
}
// create device and exit if creation failed
IrrlichtDevice* device = createDevice(driverType, core::dimension2d<u32>(800, 600));
//Class MyEventReceiver for the keyboard
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
if (device == 0)
return 1; // could not create selected driver.
/*
Get a pointer to the video driver and the SceneManager so that
we do not always have to write device->getVideoDriver() and
device->getSceneManager().
*/
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
/*
To display the Quake 3 map, we first need to load it. Quake 3 maps
are packed into .pk3 files wich are nothing other than .zip files.
So we add the .pk3 file to our FileSystem. After it was added,
we are able to read from the files in that archive as they would
directly be stored on disk.
*/
device->getFileSystem()->addZipFileArchive("media/map-20kdm2.pk3");
/*
Now we can load the mesh by calling getMesh(). We get a pointer returned
to a IAnimatedMesh. As you know, Quake 3 maps are not really animated,
they are only a huge chunk of static geometry with some materials
attached. Hence the IAnimated mesh consists of only one frame,
so we get the "first frame" of the "animation", which is our quake level
and create an OctTree scene node with it, using addOctTreeSceneNode().
The OctTree optimizes the scene a little bit, trying to draw only geometry
which is currently visible. An alternative to the OctTree would be a
AnimatedMeshSceneNode, which would draw always the complete geometry of
the mesh, without optimization. Try it out: Write addAnimatedMeshSceneNode
instead of addOctTreeSceneNode and compare the primitives drawed by the
video driver. (There is a getPrimitiveCountDrawed() method in the
IVideoDriver class). Note that this optimization with the Octree is only
useful when drawing huge meshes consiting of lots of geometry.
*/
scene::IAnimatedMesh* mesh = smgr->getMesh("20kdm2.bsp");
scene::ISceneNode* node = 0;
if (mesh)
node = smgr->addOctTreeSceneNode(mesh->getMesh(0));
/*
Because the level was modelled not around the origin (0,0,0), we translate
the whole level a little bit.
*/
if (node)
node->setPosition(core::vector3df(-1300,-144,-1249));
//Add a camera type SceneNodeFPS to the scene
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
//Hide the mouse cursor
device->getCursorControl()->setVisible(false);
//Here you create the effect you want to use
CEffects effect;
effect.CreateGlow(camera,smgr,driver,128);
effect.CreateDream(camera,smgr,driver,128);
effect.CreateVision(camera,smgr,driver,"media/noise.jpg",128);
//initialise the lastFPS variable
int lastFPS = -1;
//Main Loop
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(10,10,10,10));
effect.RenderNothing();
//Get the "RenderEffect" variable to draw the desired effect
switch(RenderEffect)
{
//Here you Render the effect
case 1:effect.RenderGlow(smgr,driver,10,10,10,10);break;
case 2:effect.RenderDream(smgr,driver,10,10,10,10);break;
case 3:effect.RenderVision(smgr,driver,10,10,10,10);
}
//Draw all
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
//Draw the FPS in the window caption
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - Switch keys N.G.D.V [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
//In the end, delete the Irrlicht device.
device->drop();
return 0;
}