LensFlareSceneNode with occlusion query

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.

Re: LensFlareSceneNode with occlusion query

Postby tbw » Fri Jan 13, 2012 10:23 am

if youu change the sample codein main.cpp to:

cpp Code: Select all
        // create the sun node as a sphere scene node.
        scene::IMeshSceneNode* sunMeshNode = smgr->addSphereSceneNode(1, 16, smgr->getRootSceneNode());
        sunMeshNode->setMaterialTexture(0, driver->getTexture("media/sun/mesh.png"));
        sunMeshNode->setMaterialType(video::EMT_SOLID);
        sunMeshNode->setMaterialFlag(video::EMF_LIGHTING, false);
        sunMeshNode->setScale(core::vector3d<f32>(600, 600, 600));
        sunMeshNode->setPosition(core::vector3df(8000, 4000, 750));
 
        // add a billboard to the sun node
        //scene::IBillboardSceneNode* sunBillboardNode = smgr->addBillboardSceneNode(sunMeshNode);
        //sunBillboardNode->setMaterialTexture(0, driver->getTexture("media/sun/sun.png"));
        //sunBillboardNode->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
        //sunBillboardNode->setMaterialFlag(video::EMF_LIGHTING, false);
        //sunBillboardNode->setSize(core::dimension2d<f32>(4000, 4000));
       
        // add the lensflare to the sun
        scene::CLensFlareSceneNode* lensFlareNode = new scene::CLensFlareSceneNode(sunMeshNode, smgr);
        lensFlareNode->setMaterialTexture(0, driver->getTexture("media/lensflare/flare.png"));
       
        // create a follow camara animator for the sun
        //scene::CSceneNodeAnimatorFollowCamera* sunAnim = new scene::CSceneNodeAnimatorFollowCamera(core::vector3df(-8000, 4000, 750));
        //sunMeshNode->addAnimator(sunAnim);
        //sunAnim->drop();
       
        // some lenses, halos and circles
    lensFlareNode->getFlareData().clear();
    lensFlareNode->getFlareData().push_back(scene::SFlareData(scene::EFT_LENS, -0.15f, 0.15f, video::SColor(255, 60, 60, 90)));
    lensFlareNode->getFlareData().push_back(scene::SFlareData(scene::EFT_HALO, -0.3f, 0.3f, video::SColor(120, 60, 255, 180)));
        lensFlareNode->getFlareData().push_back(scene::SFlareData(scene::EFT_HALO, -0.4f, 0.2f, video::SColor(220, 80, 80, 98)));
    lensFlareNode->getFlareData().push_back(scene::SFlareData(scene::EFT_CIRCLE, -0.45f, 0.1f, video::SColor(220, 80, 80, 85)));
    lensFlareNode->getFlareData().push_back(scene::SFlareData(scene::EFT_RING, -0.42f, 0.3f, video::SColor(180, 60, 255, 110)));
 
 


you can see how the node works. What you should see is a black sphere with only a few flares (disappearing the more of the sphere is occluded).

then if you add a build in animator

cpp Code: Select all
        scene::ISceneNodeAnimator * sunAnim = smgr->createFlyCircleAnimator(
                core::vector3df(8000, 4000, 750), 5000);
               
                new scene::CSceneNodeAnimatorFollowCamera(core::vector3df(-8000, 4000, 750));
        sunMeshNode->addAnimator(sunAnim);
        sunAnim->drop();

the sphere rotates and the flare are diasappearing when the sphere is occluded

I hope that you get the same behaviour.

a point that is important are the two lines
cpp Code: Select all
                        // update strength of the lensflare
                        if(occlusionQueryResult!= 0xffffffff)
                                lensFlareNode->setStrength(f32(occlusionQueryResult)/8000.f);



8000 means that nearly 8000 pixels of the sphere are visible, if it is not occluded. If you don't have a constant distance to the lensflare (or the helper mesh) you have to adapt this value. The more distance you have got between the camera and the helper mesh (sphere) the less pixels are visible in case of no occlusion.
I hope this will help you...
tbw
 
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: LensFlareSceneNode with occlusion query

Postby Mel » Fri Jan 13, 2012 11:37 am

You could try also to place the lens flare with regard a light direction instead of a light position, that could make the lens flare behave like the sun. Fairly neat looking, btw :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
User avatar
Mel
Competition winner
 
Posts: 2224
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: LensFlareSceneNode with occlusion query

Postby 3DModelerMan » Fri Jan 13, 2012 4:13 pm

Yeah, light direction lens flares are a really useful thing to have. I used them in Unity 3D alot and they really added a nice touch to the render for not very much work at all. This would be perfect to put into the Irrlicht core.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModelerMan/replicator#tipjar
User avatar
3DModelerMan
 
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Re: LensFlareSceneNode with occlusion query

Postby Granyte » Fri Jan 13, 2012 7:06 pm

my code works like this

cpp Code: Select all
 
Node = smgr->addSphereSceneNode(TRadius,256);
scene::CLensFlareSceneNode* lensFlareNode = new scene::CLensFlareSceneNode(Node, smgr);
lensFlareNode->setMaterialTexture(0, driver->getTexture("media/lensflare/flare.png"));
driver->addOcclusionQuery(Node, static_cast<IMeshSceneNode*>(Node)->getMesh());
 


and this is what i mean by odd behaviour the lens seem to be aligned with the center of the screen and an arbitrary randoom position
the error becomes more then more obvious as you move around it

Image
Granyte
 
Posts: 846
Joined: Tue Jan 25, 2011 11:07 pm

Re: LensFlareSceneNode with occlusion query

Postby hendu » Sat Jan 14, 2012 8:16 am

Just a note, point sprites would be very useful for a lens flare, you'd only set one position and size instead of four. Also no need to set identity matrices.
hendu
 
Posts: 2587
Joined: Sat Dec 18, 2010 12:53 pm

Re: LensFlareSceneNode with occlusion query

Postby Mel » Wed Jan 18, 2012 11:35 pm

A question about point sprites, do they work the same on DX and OpenGL?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
User avatar
Mel
Competition winner
 
Posts: 2224
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: LensFlareSceneNode with occlusion query

Postby hybrid » Thu Jan 19, 2012 8:15 am

I hope so, but point sprites are also not yet properly tested.
hybrid
Admin
 
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany

Re: LensFlareSceneNode with occlusion query

Postby hendu » Thu Jan 19, 2012 1:14 pm

I think DX and OGL have different equations for the distance scaling. But that's not often useful anyway, it's not accurate for pretend-billboards with a 3d position, and a lens flare would be constant size.
hendu
 
Posts: 2587
Joined: Sat Dec 18, 2010 12:53 pm

Re: LensFlareSceneNode with occlusion query

Postby fabs » Mon Apr 09, 2012 1:42 pm

I notice the mediafire link is now disabled. Is there a copy of this node available somewhere?
fabs
 
Posts: 18
Joined: Sun Jun 25, 2006 1:41 pm

Re: LensFlareSceneNode with occlusion query

Postby RdR » Mon Apr 09, 2012 4:21 pm

fabs wrote:I notice the mediafire link is now disabled. Is there a copy of this node available somewhere?


Found the download on my machine (not sure if its the latest version)

http://www.mediafire.com/?76m6vch5aps3atz
User avatar
RdR
Competition winner
 
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm

Re: LensFlareSceneNode with occlusion query

Postby tbw » Mon Apr 09, 2012 6:34 pm

Changed the download link to:

http://www.van-helsing-band.de/irrlicht/lensflare.zip

I compiled it against the latest irrlicht version (trunk).
tbw
 
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: LensFlareSceneNode with occlusion query

Postby fabs » Tue Apr 10, 2012 4:59 pm

Thank you very much for reposting it so quickly! It works beautifully.
fabs
 
Posts: 18
Joined: Sun Jun 25, 2006 1:41 pm

Re: LensFlareSceneNode with occlusion query

Postby REDDemon » Fri Apr 13, 2012 8:49 am

another possible usage is to show visible items. For example in the Witcher if you press ALT visible items will show their names. I don't know if CDPROJECT used occlusion queries OR software raytracing, but you can achieve the same effect easily with occlusion queries, if you get problems with raytracing. Of course there will be 1 query when you press ALT, and if you keep ALT pressed down then further updates can be done every 1/2 seconds.

This will help to prevent exploiting: for example if a treasure chest is behind a wall and you forget to add that wall as collision for raytracing (maybe just because you want the player able to move over that wall) the name of the chest will not show up until the player see it with occlusion queries.. without occlusion queries can happens that the name of the chest is showed up indipendently if it is behind the wall or not.)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
User avatar
REDDemon
Developer
 
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: LensFlareSceneNode with occlusion query

Postby wing64 » Mon Apr 16, 2012 5:49 am

- When i removed skybox why background not clear or len flare need sky all the time ?
- If i disable driver->runAllOcclusionQueries(false); background will clear ok but it's disable lensFlareNode->setStrength() too. How should i fix it ?
Image
wing64
Competition winner
 
Posts: 240
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand

Re: LensFlareSceneNode with occlusion query

Postby wing64 » Thu Apr 19, 2012 1:46 pm

I'm not sure this is bug or not ?
When used runAllOcclusionQueries() i need draw somethink after that (maybe for restore colormask) then engine will render correct (in lenflare example background will right clear) e.g.
cpp Code: Select all
driver->setMaterial( video::SMaterial() );
driver->draw3DLine( core::vector3df(0), core::vector3df(1) ); 
or
cpp Code: Select all
driver->setMaterial( driver->getMaterial2D() );
driver->draw2DLine( core::vector2di(0), core::vector2di(1) ); 

ps. I don't know this problem depend on disable all colormask when driver run occlusion :?: If u know please notice me. :?

Image
wing64
Competition winner
 
Posts: 240
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand

PreviousNext

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest