MOTION BLUR
MOTION BLUR
Hi,
I've made the motion blur effect in a more serious way.
You can download the demo here
http://digilander.libero.it/blizzard.3d ... onblur.rar
They are only few Kbytes...
You must have the irrlicht 1.0 dll because I've not the latest version.
Fallow the readme and try the demo
Please, let me know what do you think about the effect.
I've made the motion blur effect in a more serious way.
You can download the demo here
http://digilander.libero.it/blizzard.3d ... onblur.rar
They are only few Kbytes...
You must have the irrlicht 1.0 dll because I've not the latest version.
Fallow the readme and try the demo
Please, let me know what do you think about the effect.
Everyone for the game and the game for everyone
I would use a modulou and a frame integer for capturing images
this resets the frame counter every 1 second and captures every five frames
the five could be a fraction of the fps for dynamic capturing
howver the fraction must be expressed as an integer as modulou's require integers to work
frames=0;
Code: Select all
int frames;
while (1)
{
finish drawing():
frames ++;
if(frames%5==0)
capture():
if (frames==FPS)
frames=0;
}
the five could be a fraction of the fps for dynamic capturing
howver the fraction must be expressed as an integer as modulou's require integers to work
frames=0;
As you wish!
I've not post the code becauseee.... it was too dirty and it's not explained.
So... I'm start to working on another effect that use the same system...
But if you have problems, I hope that you can resolt and optimize with the code
Bye
Giovanni
I've not post the code becauseee.... it was too dirty and it's not explained.
So... I'm start to working on another effect that use the same system...
But if you have problems, I hope that you can resolt and optimize with the code
Code: Select all
/* This tutorials describes how to do special effects. It shows how to use stencil
buffer shadows, the particle system, billboards, dynamic light and the water
surface scene node.
We start like in some tutorials before. Please note that this time, the 'shadows' flag in
createDevice() is set to true, for we want to have a dynamic shadow casted from
an animated character. If your this example runs to slow, set it to false.
The Irrlicht Engine checks if your hardware doesn't support the stencil
buffer, and disables shadows by itself, but just in case the demo runs slow
on your hardware.*/
#include <irrlicht.h>
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <gl\gl.h> // Header File per la libreria OpenGL32
#include <gl\glu.h> // Header File per la libreria GLu32
#include <gl\glaux.h> // Header File per la libreria GLaux
using namespace irr;
#pragma comment(lib, "Irrlicht.lib")
int main()
{
int passes=40;
printf("IRRLICHT MOTION BLUR\n");
printf("By Santostefano <Blizzard> Giovanni\n");
printf("contact: idmgiovanni@libero.it\n\n\n");
printf("INSERT THE NUMBER OF M.BLUR PASSES (DEFAULT 10): ");
scanf("%d",&passes);
IrrlichtDevice *device =
createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480),
32, false, false);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
/*
For our environment, we load a .3ds file. It is a small room I modelled
with Anim8or and exported it into the 3ds format because the Irrlicht Engine
did not support the .an8 format when I wrote this tutorial. I am a very bad
3d graphic artist, and so the texture mapping is not very nice in this model.
Luckily I am a better programmer than artist, and so the Irrlicht Engine
is able to create a cool texture mapping for me: Just use the mesh manipulator
and create a planar texture mapping for the mesh. If you want to see the mapping
I made with Anim8or, uncomment this line. I also did not figure out how to
set the material right in Anim8or, it has an emissive light color which I don't really
like. I'll switch it off too with this code.
*/
scene::IAnimatedMesh* mesh = smgr->getMesh(
"../../media/room.3ds");
smgr->getMeshManipulator()->makePlanarTextureMapping(
mesh->getMesh(0), 0.004f);
scene::ISceneNode* node = 0;
node = smgr->addAnimatedMeshSceneNode(mesh);
node->setMaterialTexture(0, driver->getTexture("../../media/wall.jpg"));
node->getMaterial(0).EmissiveColor.set(0,0,0,0);
node->setMaterialFlag(video::EMF_LIGHTING,false);
/*
Now, for the first special effect: Animated water. It works like this: The
WaterSurfaceSceneNode takes a mesh as input and makes
it wave like a water surface. And if we let this scene node use a nice
material like the EMT_REFLECTION_2_LAYER, it looks really cool. We are
doing this with the next few lines of code. As input mesh, we create a hill
plane mesh, without hills. But any other mesh could be used for this, you could
even use the room.3ds (which would look really strange) if you wanted to.
*/
// add animated water
scene::IAnimatedMesh* mesh1;
mesh1 = smgr->addHillPlaneMesh("myHill",
core::dimension2d<f32>(20,20),
core::dimension2d<s32>(40,40), 0, 0,
core::dimension2d<f32>(0,0),
core::dimension2d<f32>(10,10));
scene::ISceneNode *node1 = smgr->addWaterSurfaceSceneNode(mesh1->getMesh(0), 3.0f, 300.0f, 30.0f);
node1->setPosition(core::vector3df(0,45,0));
node1->setMaterialTexture(0, driver->getTexture("../../media/stones.jpg"));
node1->setMaterialTexture(1, driver->getTexture("../../media/water.jpg"));
node1->setMaterialType(video::EMT_REFLECTION_2_LAYER);
node1->setVisible(false);
/*
The second special effect is very basic, I bet you saw it already in some
Irrlicht Engine demos: A transparent billboard combined with a dynamic light.
We simply create a light scene node, let it fly around, an to make it look
more cool, we attach a billboard scene node to it.
*/
// create light
node = smgr->addLightSceneNode(0, core::vector3df(0,0,0),
video::SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);
scene::ISceneNodeAnimator* anim = 0;
anim = smgr->createFlyCircleAnimator (core::vector3df(0,150,0),250.0f);
node->addAnimator(anim);
anim->drop();
// attach billboard to light
node = smgr->addBillboardSceneNode(node, core::dimension2d<f32>(50, 50));
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
node->setMaterialTexture(0, driver->getTexture("../../media/particlewhite.bmp"));
/*
The next special effect is a lot more interesting: A particle system. The particle
system in the Irrlicht Engine is quit modular and extensible and yet easy to use.
There is a particle system scene node into which you can put particle emitters, which
make particles come out of nothing. These emitters are quite flexible and usually have
lots of parameters like direction, amount and color of the particles they should create.
There are different emitters, for example a point emitter which lets particles pop out
at a fixed point. If the particle emitters available in the engine are not enough for
you, you can easily create your own ones, you'll simply have to create a class derived
from the IParticleEmitter interface and attach it to the particle system using setEmitter().
In this example we create a box particle emitter, which creates particles randomly
inside a box. The parameters define the box, direction of the particles, minimal and
maximal new particles per second, color and minimal and maximal livetime of the particles.
Because only with emitters particle system would be a little bit boring,
there are particle affectors, which modify particles during they fly around. They can
be added to the particle system, simulating additional effects like gravity or wind.
The particle affector we use in this example is an affector, which modifies the color
of the particles: It lets them fade out. Like the particle emitters, additional
particle affectors can also be implemented by you, simply derive a class from
IParticleAffector and add it with addAffector().
After we set a nice material to the particle system, we have a cool looking camp fire.
By adjusting material, texture, particle emitter and affector parameters, it is also
easily possible to create smoke, rain, explosions, snow, and so on.
*/
// create a particle system
scene::IParticleSystemSceneNode* ps = 0;
ps = smgr->addParticleSystemSceneNode(false);
ps->setPosition(core::vector3df(-70,60,40));
ps->setScale(core::vector3df(2,2,2));
ps->setParticleSize(core::dimension2d<f32>(20.0f, 20.0f));
scene::IParticleEmitter* em = ps->createBoxEmitter(
core::aabbox3d<f32>(-7,0,-7,7,1,7),
core::vector3df(0.0f,0.06f,0.0f),
80,100,
video::SColor(0,255,255,255), video::SColor(0,255,255,255),
800,2000);
ps->setEmitter(em);
em->drop();
scene::IParticleAffector* paf =
ps->createFadeOutParticleAffector();
ps->addAffector(paf);
paf->drop();
ps->setMaterialFlag(video::EMF_LIGHTING, false);
ps->setMaterialTexture(0, driver->getTexture("../../media/fire.bmp"));
ps->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
/*
As our last special effect, we want a dynamic shadow be casted from an animated
character. For this we load a DirectX .x model and place it into our world.
For creating the shadow, we simply need to call addShadowVolumeSceneNode().
The color of shadows is only adjustable globally for all shadows, by calling
ISceneManager::setShadowColor(). Voila, here is our dynamic shadow.
Because the character is a little bit too small for this scene, we make it bigger
using setScale(). And because the character is lighted by a dynamic light, we need
to normalize the normals to make the lighting on it correct. This is always necessary if
the scale of a dynamic lighted model is not (1,1,1). Otherwise it would get too dark or
too bright because the normals will be scaled too.
*/
// add animated character
mesh = smgr->getMesh("../../media/dwarf.x");
scene::IAnimatedMeshSceneNode* anode = 0;
anode = smgr->addAnimatedMeshSceneNode(mesh);
anode->setPosition(core::vector3df(-50,20,-60));
anode->setAnimationSpeed(15);
// make the model a little bit bigger and normalize its normals
// because of this for correct lighting
anode->setScale(core::vector3df(2,2,2));
anode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
/*
Finally we simply have to draw everything, that's all.
*/
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
camera->setPosition(core::vector3df(-50,50,-150));
// disable mouse cursor
device->getCursorControl()->setVisible(false);
////////////////////////////////////////////////////////////////////////////////////////////
/////////////////// BEGIN OF M.B. CODE /////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
video::ITexture** t=(video::ITexture**)malloc(sizeof(video::ITexture*) *passes);
int act=0;
driver->beginScene(true, true, 0);
driver->endScene();
for(int i=0; i<passes; i++)
{
t[i] = driver->createRenderTargetTexture(core::dimension2d<s32>(512,512));
driver->setRenderTarget(t[i],true,true);
smgr->drawAll();
}
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0);
glEnable(GL_DEPTH_TEST);
driver->setRenderTarget(t[act],true,true);
smgr->drawAll();
act++;
if(act>passes-1)
act=0;
driver->setRenderTarget(0,true,true);
int count=act;
video::SMaterial *m= new video::SMaterial();
m->Texture1=t[count];
driver->setMaterial(*m);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
//Draw actual frame
glBegin(GL_QUADS);
glTexCoord2f(0,1); glVertex2f(-1,1);
glTexCoord2f(1,1); glVertex2f(1,1);
glTexCoord2f(1,0); glVertex2f(1,-1);
glTexCoord2f(0,0); glVertex2f(-1,-1);
glEnd();
count++;
if(count>passes-1)
count=0;
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1,1,1,0.5);
for(int k=1; k<passes; k++)
{
m->Texture1=t[count];
driver->setMaterial(*m);
count++;
if(count>passes-1)
count=0;
glBegin(GL_QUADS);
glTexCoord2f(0,1); glVertex2f(-1,1);
glTexCoord2f(1,1); glVertex2f(1,1);
glTexCoord2f(1,0); glVertex2f(1,-1);
glTexCoord2f(0,0); glVertex2f(-1,-1);
glEnd();
}
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Irrlicht Engine - SpecialFX example [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}
Giovanni
Everyone for the game and the game for everyone
Hi,
I've made the new effect but it's too too bad.... worse!
I've error on blending systems and the effect is crazy when the camera is moving... don't know why.
So... the source I've released is the functional one! I don't release the new "bad" effect...
But I even show an image
I've made the new effect but it's too too bad.... worse!
I've error on blending systems and the effect is crazy when the camera is moving... don't know why.
So... the source I've released is the functional one! I don't release the new "bad" effect...
But I even show an image
Everyone for the game and the game for everyone
Sorry! I've the GPRS... and for upload more than one mega (irrlicht dll) I'll take half an hour or an hour....Or you could upload the proper dll somewhere? wanna see!
I'll post the source... if you substitute the source to the specialFX sample and link the GL GLu and GLaux libraries you can compile the effect...
For information: I've used the irrlicht 1.0 dll standard. The version is for Win32VisualStudio
Bye
Giovanni
Everyone for the game and the game for everyone