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.
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: LensFlareSceneNode with occlusion query

Post by tbw »

if youu change the sample codein main.cpp to:

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

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

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...
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: LensFlareSceneNode with occlusion query

Post by Mel »

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
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Re: LensFlareSceneNode with occlusion query

Post by 3DModelerMan »

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/3DModel ... tor#tipjar
Granyte
Posts: 850
Joined: Tue Jan 25, 2011 11:07 pm
Contact:

Re: LensFlareSceneNode with occlusion query

Post by Granyte »

my code works like this

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
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: LensFlareSceneNode with occlusion query

Post by hendu »

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.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: LensFlareSceneNode with occlusion query

Post by Mel »

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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: LensFlareSceneNode with occlusion query

Post by hybrid »

I hope so, but point sprites are also not yet properly tested.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: LensFlareSceneNode with occlusion query

Post by hendu »

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.
fabs
Posts: 18
Joined: Sun Jun 25, 2006 1:41 pm

Re: LensFlareSceneNode with occlusion query

Post by fabs »

I notice the mediafire link is now disabled. Is there a copy of this node available somewhere?
RdR
Competition winner
Posts: 273
Joined: Tue Mar 29, 2011 2:58 pm
Contact:

Re: LensFlareSceneNode with occlusion query

Post by RdR »

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
tbw
Posts: 59
Joined: Sat Jan 15, 2011 9:51 am
Location: Germany

Re: LensFlareSceneNode with occlusion query

Post by tbw »

Changed the download link to:

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

I compiled it against the latest irrlicht version (trunk).
fabs
Posts: 18
Joined: Sun Jun 25, 2006 1:41 pm

Re: LensFlareSceneNode with occlusion query

Post by fabs »

Thank you very much for reposting it so quickly! It works beautifully.
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: LensFlareSceneNode with occlusion query

Post by REDDemon »

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
wing64
Competition winner
Posts: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Re: LensFlareSceneNode with occlusion query

Post by wing64 »

- 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: 242
Joined: Wed Jul 23, 2008 2:35 am
Location: Thailand
Contact:

Re: LensFlareSceneNode with occlusion query

Post by wing64 »

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.

Code: Select all

driver->setMaterial( video::SMaterial() );
driver->draw3DLine( core::vector3df(0), core::vector3df(1) ); 
or

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
Post Reply