Depth Of Field

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Depth Of Field

Post by sio2 »

I've posted another demo on my website (with source code) for Depth Of Field (based on posttool's DOF demo).
http://sio2.g0dsoft.com

Image

From the Readme:
This is a demo of Depth Of Field, where the viewing camera focuses on a portion of the scene. In this demo camera focus is manually controlled by the user (see Usage).

This demo will operate with with either OpenGL or Direct3D9 (as long as the graphics hardware is capable).

Usage
=====
F1/F2 - alter camera Range
F3/F4 - alter camera Focus
F5/F6 - alter camera Blur0 and Blur1 parameters
F7/F8 - alter camera Distance
WASD keys to move camera.
Alt-F4 or Escape key to exit.

Requirements
============
Drivers:
Latest DirectX 9.0b drivers [www.microsoft.com/directx],
Latest DirectX9 drivers for your graphics hardware [from your HW vendor].
Latest OpenGL drivers for your graphics hardware [from your HW vendor].


Graphics hardware:
Direct3D9: Vertex Shader 2.0 support, or better
Pixel Shader 2.0 support, or better.
OpenGL: Vertex Program 2.0 support, or better
Fragment Program 2.0 support, or better.

Notes
=====
This demo may require the Visual Studio 2005 Redistributable Files installed on your machine. These can be obtained from http://www.sio2.g0dsoft.com in the "Misc" section of "Downloads".

Credits
=======
This is a modified version of a demo by "posttool" from the Irrlicht forums [accessible via http://irrlicht.sourceforge.net]. Support for Direct3D9 was added, shaders converted from GLSL to HLSL, bugfixes and enhancements. Credit also goes to "omaremad" from the Irrlicht forum for the original hdr code which was the inspiration for the "posttool" demo.
Luke
Admin
Posts: 449
Joined: Fri Jul 14, 2006 7:55 am
Location: Australia
Contact:

Post by Luke »

very nice, I'll have a look.
Luke
Admin
Posts: 449
Joined: Fri Jul 14, 2006 7:55 am
Location: Australia
Contact:

Post by Luke »

wow, Nice I like the effect,

One problem, It seems the blur is unaffected by the position of the camera, as I move around when running in direct x. It's fine in openGL.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Luke wrote:wow, Nice I like the effect,

One problem, It seems the blur is unaffected by the position of the camera, as I move around when running in direct x. It's fine in openGL.
Thanks for the feedback. I'll take a look at that.
posttool
Posts: 13
Joined: Thu Dec 07, 2006 5:40 pm
Location: San Francisco
Contact:

thanks for the updates!

Post by posttool »

nice work sio2. i am too happy you provided the docs, fixes and especially the directx shaders!
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

I'm using glsl shaders like in your demo but i dono why I get strange, horible aliasing. Is there some way to antialias it??

Edit
==============

I have loaded u're code into my project and it only make some wired aliasing no effect :( plz help i can't make it running
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

m_krzywy wrote:I'm using glsl shaders like in your demo but i dono why I get strange, horible aliasing. Is there some way to antialias it??

Edit
==============

I have loaded u're code into my project and it only make some wired aliasing no effect :( plz help i can't make it running
Well, I would say you haven't implemented it correctly, then! :wink:

I'd need a project I could compile and test to see what's going on. Or you could do what I do when I have problems (and I have lots of them and have to solve them by myself!) and use PIX.
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

What version of irrlicht have u used ?? I have 1.1.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

m_krzywy wrote:What version of irrlicht have u used ?? I have 1.1.
At least 1.2. I probably whatever Subversion revision was current at the time (this may be in the demo readme).
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

that's problem ?? u think it's because this ??
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

m_krzywy wrote:that's problem ?? u think it's because this ??
The only way to see is to try 1.2 and find out. Is there any reason why you're still using 1.1?
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

I had problems with compiling sth in 1.2. I'll try 1.2 :)
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

Code: Select all

#include <irrlicht.h>
#include <iostream>
#include <string>
#include "shadermaterial.h"
#include "shadergroup.h"


using namespace irr;
using namespace video;
using namespace scene;
using namespace core;
using namespace gui;
int rolka_g = 0;
bool poxl = false;
bool poxr = false;
ShaderGroup* hdr = 0;
//================================================================================
// funkcje kamery :)
void makeCockpit(irr::scene::ICameraSceneNode *camera,
                irr::scene::ISceneNode *node,
                irr::core::vector3df offset)
{
    irr::core::matrix4 m;
    m.setRotationDegrees(node->getRotation());

    irr::core::vector3df frv = irr::core::vector3df (0.0f, 0.0f, 1.0f);
    m.transformVect(frv);

    irr::core::vector3df upv = irr::core::vector3df (0.0f, 1.0f, 0.0f);
    m.transformVect(upv);

    m.transformVect(offset);
   
    offset += node->getPosition();
    camera->setPosition(offset);
   
    camera->setUpVector(upv);
   
    offset += frv;
    camera->setTarget(offset);
   
    camera->updateAbsolutePosition();
}

void move(irr::scene::ISceneNode *node, irr::core::vector3df vel)
{
    irr::core::matrix4 m;
    m.setRotationDegrees(node->getRotation());
    m.transformVect(vel);
    node->setPosition(node->getPosition() + vel);
    node->updateAbsolutePosition();
}

void rotate(irr::scene::ISceneNode *node, irr::core::vector3df rot)
{
    irr::core::matrix4 m;
    m.setRotationDegrees(node->getRotation());
    irr::core::matrix4 n;
    n.setRotationDegrees(rot);
    m *= n;
    node->setRotation( m.getRotationDegrees() );
    node->updateAbsolutePosition();
}
 
void turn(irr::scene::ISceneNode *node, irr::f32 rot)
{
    rotate(node, irr::core::vector3df(0.0f,rot,0.0f) );
}
//==================================================================================


//==================================================================================
// event reciever
bool keys[KEY_KEY_CODES_COUNT];
     
class MyEventReceiver : public IEventReceiver
{
public:
       
    virtual bool OnEvent(SEvent event)
    {
    if(event.EventType == EET_MOUSE_INPUT_EVENT)
    {
    if(event.MouseInput.Wheel > 0)
    {
    rolka_g = 1;
    return true;
    }
    if(event.MouseInput.Wheel < 0)
    {
    rolka_g = 2;
    return true;
    }
    return false;                   
    }   
        if(event.EventType == EET_KEY_INPUT_EVENT)
        {
            keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
            return true;
        }
        return true;
        
    }   
};



int main()
{
    //=============================================================================
    //START SILNIKA   
    MyEventReceiver receiver;
    IrrlichtDevice *device =
      createDevice(video::EDT_OPENGL, core::dimension2d<s32>(1280,1024),32,true,false,false,& receiver);

   
   video::IVideoDriver* driver = device->getVideoDriver();
   scene::ISceneManager* smgr = device->getSceneManager();
   
   device->getCursorControl()->setVisible(false);
   driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
   //===============================================================================


   //===============================================================================
   // DODAWANIE ELEMENTÓW
   ISceneNode* skyboxNode;
                 skyboxNode = smgr->addSkyBoxSceneNode(
		         driver->getTexture("irrlicht2_up.jpg"),
		         driver->getTexture("irrlicht2_dn.jpg"),
		         driver->getTexture("irrlicht2_lf.jpg"),
		         driver->getTexture("irrlicht2_rt.jpg"),
		         driver->getTexture("irrlicht2_ft.jpg"),
		         driver->getTexture("irrlicht2_bk.jpg"));
   
   IAnimatedMesh* mesh1 = smgr->getMesh("czlowiek1.x");
   ISceneNode* node1 = smgr->addAnimatedMeshSceneNode( mesh1 );
   node1->setMaterialFlag(EMF_LIGHTING, false);
   node1->setMaterialTexture( 0, driver->getTexture("czlowiek1.jpg") );
   node1->setPosition(vector3df(0.0f,0.0f,-50.0f));
     
   IAnimatedMesh* mesh2=smgr->getMesh("mapa1.x");
   ISceneNode* node2=smgr->addOctTreeSceneNode(mesh2->getMesh(0));
   //video::ITexture* colorMap = driver->getTexture("Floor11.jpg");	
   //node2->setMaterialTexture(0,	colorMap);
   node2->setMaterialFlag(EMF_LIGHTING, false);
   
hdr = new ShaderGroup(device, smgr);
hdr->add(node2);
   
   
   scene::ICameraSceneNode *camera = device->getSceneManager()->addCameraSceneNode();
   camera->setFarValue(100000);
   //===================================================================================
   //===================================================================================
   // KOLIZJA
   
   scene::ITriangleSelector* selector = 0;	
		selector = smgr->createOctTreeTriangleSelector(mesh2->getMesh(0), node2, 128);
		node2->setTriangleSelector(selector);
		selector->drop();
   
   scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
		selector, node1, core::vector3df(15,50,20),
		core::vector3df(0,-3,0),core::vector3df(0,-50,-5),0.002);
	node1->addAnimator(anim);
	anim->drop();
	

   vector3df poz = vector3df(10,60,-50);
   
   while(device->run())
   {
                       

        hdr->render();
        
        //==============================================================================
        //przesówanie - na boki :)
        if(keys[irr::KEY_KEY_O])
        {  
        hdr->range += .01f;               
        }
        if(keys[irr::KEY_KEY_L])
        {  
        hdr->range -= .01f;               
        }
        if (poxl == true)
        {
        printf("ruch w lewo");
        poxl=false;
        }
        if (poxr == true)
        {
        printf("ruch w prawo");
        poxr = false;     
        }
        
        if (rolka_g == 1)
        {
        if (poz == vector3df(10,60,-10))poz = vector3df(poz.X,poz.Y,poz.Z);
        else poz = vector3df(poz.X,poz.Y,poz.Z+5);
        rolka_g = 0;
        }
        if (rolka_g == 2)
        {
        if (poz == vector3df(10,60,-70))poz = vector3df(poz.X,poz.Y,poz.Z);
        else poz = vector3df(poz.X,poz.Y,poz.Z-5);
        rolka_g = 0;
        }
        if(keys[irr::KEY_KEY_D])
        {
            turn(node1, 1.5);
        }
        if(keys[irr::KEY_KEY_A])
        {
            turn(node1, -1.5);
        }
        // przód i tył
        if(keys[irr::KEY_KEY_W])
        {
         if(keys[irr::KEY_SHIFT])
         {
         move(node1, core::vector3df(0,0,3.0));
         }
         else move(node1, core::vector3df(0,0,1.0));
        }
        if(keys[irr::KEY_KEY_S])
        {
            move(node1, core::vector3df(0,0,-1.0));
        }
        //strafy
        if(keys[irr::KEY_KEY_Q])
        {
        if(keys[irr::KEY_SHIFT])move(node1, core::vector3df(-2.0,0,0));
        else move(node1, core::vector3df(-1.0,0,0));
        }
        if(keys[irr::KEY_KEY_E])
        {
        if(keys[irr::KEY_SHIFT])move(node1, core::vector3df(2.0,0,0));
        else move(node1, core::vector3df(1.0,0,0));
        }
        //===============================================================================
       makeCockpit(camera, node1, poz);
       
    }
    
   device->drop();
   return 1;
}




I can't compile it. It running and then... error :(
I'm using dev-cpp. :(
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

m_krzywy wrote: I can't compile it. It running and then... error :(

If you can't compile it, how can you run it? You've lost me there...
m_krzywy wrote: I'm using dev-cpp. :(
I don't use dev-cpp myself. If it were me I would compile a debug version of Irrlicht, a debug version of my app and run it via the debugger. If it's DX9 I also use PIX (a 3D debugger).
m_krzywy
Posts: 133
Joined: Sat Nov 04, 2006 2:05 pm

Post by m_krzywy »

i've runned it without hdr... now i must implement it :)


EDIT :) :)

I've runned it :) thx for #care :)


GOOD JOB!!
Post Reply