Page 2 of 3

Re: LensFlareSceneNode with occlusion query

Posted: Fri Jan 13, 2012 10:23 am
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...

Re: LensFlareSceneNode with occlusion query

Posted: Fri Jan 13, 2012 11:37 am
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 :)

Re: LensFlareSceneNode with occlusion query

Posted: Fri Jan 13, 2012 4:13 pm
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.

Re: LensFlareSceneNode with occlusion query

Posted: Fri Jan 13, 2012 7:06 pm
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

Re: LensFlareSceneNode with occlusion query

Posted: Sat Jan 14, 2012 8:16 am
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.

Re: LensFlareSceneNode with occlusion query

Posted: Wed Jan 18, 2012 11:35 pm
by Mel
A question about point sprites, do they work the same on DX and OpenGL?

Re: LensFlareSceneNode with occlusion query

Posted: Thu Jan 19, 2012 8:15 am
by hybrid
I hope so, but point sprites are also not yet properly tested.

Re: LensFlareSceneNode with occlusion query

Posted: Thu Jan 19, 2012 1:14 pm
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.

Re: LensFlareSceneNode with occlusion query

Posted: Mon Apr 09, 2012 1:42 pm
by fabs
I notice the mediafire link is now disabled. Is there a copy of this node available somewhere?

Re: LensFlareSceneNode with occlusion query

Posted: Mon Apr 09, 2012 4:21 pm
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

Re: LensFlareSceneNode with occlusion query

Posted: Mon Apr 09, 2012 6:34 pm
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).

Re: LensFlareSceneNode with occlusion query

Posted: Tue Apr 10, 2012 4:59 pm
by fabs
Thank you very much for reposting it so quickly! It works beautifully.

Re: LensFlareSceneNode with occlusion query

Posted: Fri Apr 13, 2012 8:49 am
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.)

Re: LensFlareSceneNode with occlusion query

Posted: Mon Apr 16, 2012 5:49 am
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

Re: LensFlareSceneNode with occlusion query

Posted: Thu Apr 19, 2012 1:46 pm
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