Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Let There Be Light 2  (Read 131874 times)

0 Members and 1 Guest are viewing this topic.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Let There Be Light 2
« Reply #90 on: October 11, 2015, 05:46:34 pm »
The sprite (the rectangle) should cover the screen. Try setting the dimensions to the screen size and positioning it so that it is centered on the screen.
okay, but it's still just a giant square covering the screen. I thought it was supposed to be a directional light?

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: Let There Be Light 2
« Reply #91 on: October 11, 2015, 05:48:41 pm »
Directional light is like sunlight. So if you don't have any occluders, all you will see is a white screen  ;)
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Let There Be Light 2
« Reply #92 on: October 11, 2015, 05:50:03 pm »
ah ok, i thought it was supposed to be a light like from a flashlight :)

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Let There Be Light 2
« Reply #93 on: October 11, 2015, 05:54:28 pm »
Btw, i notice the light system eats alot of fps. Does it take more fps than LTBL1 or is it around the same? And what are the advantages of LTBL2 compared to the first LTBL?

I'm using the first one in my game right now together with box2d, but i'm getting occasional stuttering which seems to be the cause of LTBL1.

It could also be from Box2d but i don't see any stuttering when i remove the light system, but that might be because i have 2000 fps instead of 800 fps when i remove LTBL1 so if the cause of stuttering is from box2d it might not show at that high fps.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Let There Be Light 2
« Reply #94 on: October 11, 2015, 06:38:05 pm »
Why on earrh don't you limit the framerate to something sensible - like 60 or 75?
Why waste power rendering frames the users eyes cannot percieve?

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Let There Be Light 2
« Reply #95 on: October 11, 2015, 06:44:18 pm »
Why on earrh don't you limit the framerate to something sensible - like 60 or 75?
Why waste power rendering frames the users eyes cannot percieve?
I do limit the framerate to 60 fps, but it's good to unlimit it to check your performance and how much computing power certain things take. Someone with a worse computer might not even get 60 fps if you don't care about looking how fast your app actually can run and optimizing it. Also your fps might drop from 800 fps to a much lower fps briefly (stuttering), which is my problem.

Sayuri

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Let There Be Light 2
« Reply #96 on: October 24, 2015, 02:01:21 am »
I hope lolz123 does not mind me posting this here:

For those interested in better LTBL2 performance and lights that can be switched on/off:
I've made a few small changes in the LTBL2 code by adding two boolean member variables (_isAwake and _isTurnedOn) aswell as appropiate get/set/toggle methods to the QuadtreeOccupant object.

Both the occluders aswell as the lights are initialized as both awake and on by default (so nothing changed in the behaviour of LTBL2 unless you manually switch them off/make them sleep).

namespace ltbl {
        class QuadtreeOccupant {

        public:
                bool _isAwake;
                bool _isTurnedOn;

                QuadtreeOccupant()
                        : _pQuadtreeNode(nullptr), _pQuadtree(nullptr), _isAwake(true), _isTurnedOn(true)
                {}


                bool isAwake();
                void setAwake(bool);
                void toggleAwake();

                void setTurnedOn(bool);
                bool isTurnedOn();
                void toggleTurnedOn();
        };
}

And then each time in the code when i found LTBL2 looping through all the Quadtree occupants (occluders and light objects) to do shadow/light calculations or rendering i inserted a single if-statement that first checks if the occluder/lightobject is actually active AND switched on before actually doing AABB-checks, any shadow calculations or any rendering.

Example in the render method:
void LightDirectionEmission::render(const sf::View &view, sf::RenderTexture &lightTempTexture, sf::RenderTexture &antumbraTempTexture, const std::vector<QuadtreeOccupant*> &shapes, sf::Shader &unshadowShader, float shadowExtension) {
        lightTempTexture.setView(view);

        LightSystem::clear(lightTempTexture, sf::Color::White);

        // Mask off light shape (over-masking - mask too much, reveal penumbra/antumbra afterwards)
        for (int i = 0; i < shapes.size(); i++) {
                LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);
        //Check if Light is awake and turned on
                if (pLightShape->isAwake() && pLightShape->isTurnedOn()) {
        //...
        // Down here comes all the calculate/render stuff, which only gets done if light is awake and on
        //...
 

What's the advantage?
Turning lights/shadows on and off
Well, first of all you can turn lights and occluders(and thus shadows) on and off by using the
      void setTurnedOn(bool);
      void toggleTurnedOn();
methods, without having to delete the lights/occluders just to turn the light off or remove the shadow casting occluder. You can use for example light switches in your game that have a pointer/reference to the light object and by activating the switch you invoke the toggleTurnedOn() method of the pointed-to light.

Performance boost by putting offscreen/not-in-same-room LTBL2-objects to sleep
In addition to that, you can put your lights and occluders to sleep (similar to sleep/awake in Box2d) by using the
      void setAwake(bool);
      void toggleAwake();.
methods.
These methods allow LTBL2 to skip calculations for the light/occluder without modifying whether the light/shadow, from the game world perspective, is switched on or off (by a light switch in the level, for example).

How would we use that?
Lets say you have a game with several rooms or zones, which all have light objects. It'd be very inefficient if the game calculates and AABB-checks all the lights of your loaded level if you are not in the same room/zone of the light/occluder, regardless whether they are switched on or off (by switches in the level).
For that there is the "setAwake(bool)" method:
If you leave a room or zone then, on room/zone change, you could invoke a method that loops through all the lights/occluders in said room/zone and setAwake(false) for each of it. In the now new entered room/zone you would then loop through all occluders/lights and invoke setAwake(true) on each.
That way only the lights/occluders that are in the players zone/room get calculated/AABB-checked/rendered.

Example code:
(click to show/hide)


In short:
By using these modifications your game
-allows turning on/off of lights/occluders without having to constantly create/delete them
-the game keeps memorized which lights are turned on and off, since you don't create/destroy them all the time but just turn them off/on
-can get a huge performance boost by putting out-of-zone/out-of-room LTBL2 objects to sleep via setAwake(false) and only setAwake(true) if they are near the player/in the same zone or room as the player.

You can download the modified version here
https://www.dropbox.com/s/amk8v17btth6lmq/ltbl2_toggleable.zip?dl=0

Feel free to leave feedback or any errors (i couldn't find any, it's only about 15~20 lines of code that i added).
« Last Edit: October 24, 2015, 06:19:10 am by Sayuri »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10791
    • View Profile
    • development blog
    • Email
Let There Be Light 2
« Reply #97 on: October 24, 2015, 09:04:03 am »
Why not make a pull request? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sayuri

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Let There Be Light 2
« Reply #98 on: October 24, 2015, 09:37:00 am »
Why not make a pull request? ;)
Good idea, for some reason i didn't think about that option, thank you.
I'll do it later after work (and a bit of code cleanup, i accidently forgot to remove some unneccessary commented out code).
« Last Edit: October 24, 2015, 09:41:59 am by Sayuri »

DJuego

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: Let There Be Light 2
« Reply #99 on: October 24, 2015, 12:57:11 pm »
Your contribution seems promising! Thanks! Let's hope that lolz123 can evaluate it soon.  :)

DJuego

P.S: a powerful post, Sayuri  ;D
« Last Edit: October 24, 2015, 12:58:57 pm by DJuego »

Wolv

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Let There Be Light 2
« Reply #100 on: October 31, 2015, 02:33:52 pm »
I'm using VS2015 and i cant get it to work :( I made with Cmake and compilator dll file. Then in my project I linked to source folder in C++/Include Directory. I add every file into my project and i get this error:

Quote
LightSystem.obj : error LNK2019: unresolved external symbol "public: __thiscall ltbl::QuadtreeNode::QuadtreeNode(class sf::Rect<float> const &,int,class ltbl::QuadtreeNode *,class ltbl::Quadtree *)" (??0QuadtreeNode@ltbl@@QAE@ABV?$Rect@M@sf@@HPAV01@PAVQuadtree@1@@Z) referenced in function "class std::unique_ptr<class ltbl::QuadtreeNode,struct std::default_delete<class ltbl::QuadtreeNode> > __cdecl std::make_unique<class ltbl::QuadtreeNode,class sf::Rect<float> const &,int,std::nullptr_t,class ltbl::DynamicQuadtree * const>(class sf::Rect<float> const &,int &&,ltbl::$T$$QBQAVDynamicQuadtree &&)" (??$make_unique@VQuadtreeNode@ltbl@@ABV?$Rect@M@sf@@H$$TQAVDynamicQuadtree@2@@std@@YA?AV?$unique_ptr@VQuadtreeNode@ltbl@@U?$default_delete@VQuadtreeNode@ltbl@@@std@@@0@ABV?$Rect@M@sf@@$$QAH$$QA$$T$$QBQAVDynamicQuadtree@ltbl@@@Z)
1>DynamicQuadtree.obj : error LNK2001: unresolved external symbol "public: __thiscall ltbl::QuadtreeNode::QuadtreeNode(class sf::Rect<float> const &,int,class ltbl::QuadtreeNode *,class ltbl::Quadtree *)" (??0QuadtreeNode@ltbl@@QAE@ABV?$Rect@M@sf@@HPAV01@PAVQuadtree@1@@Z)
1>DynamicQuadtree.obj : error LNK2019: unresolved external symbol "private: void __thiscall ltbl::QuadtreeNode::removeForDeletion(class std::unordered_set<class ltbl::QuadtreeOccupant *,struct std::hash<class ltbl::QuadtreeOccupant *>,struct std::equal_to<class ltbl::QuadtreeOccupant *>,class std::allocator<class ltbl::QuadtreeOccupant *> > &)" (?removeForDeletion@QuadtreeNode@ltbl@@AAEXAAV?$unordered_set@PAVQuadtreeOccupant@ltbl@@U?$hash@PAVQuadtreeOccupant@ltbl@@@std@@U?$equal_to@PAVQuadtreeOccupant@ltbl@@@4@V?$allocator@PAVQuadtreeOccupant@ltbl@@@4@@std@@@Z) referenced in function "private: void __thiscall ltbl::DynamicQuadtree::contract(void)" (?contract@DynamicQuadtree@ltbl@@AAEXXZ)
1>DynamicQuadtree.obj : error LNK2019: unresolved external symbol "public: void __thiscall ltbl::QuadtreeNode::add(class ltbl::QuadtreeOccupant *)" (?add@QuadtreeNode@ltbl@@QAEXPAVQuadtreeOccupant@2@@Z) referenced in function "public: virtual void __thiscall ltbl::DynamicQuadtree::add(class ltbl::QuadtreeOccupant *)" (?add@DynamicQuadtree@ltbl@@UAEXPAVQuadtreeOccupant@2@@Z)
1>StaticQuadtree.obj : error LNK2001: unresolved external symbol "public: void __thiscall ltbl::QuadtreeNode::add(class ltbl::QuadtreeOccupant *)" (?add@QuadtreeNode@ltbl@@QAEXPAVQuadtreeOccupant@2@@Z)
1>Quadtree.obj : error LNK2019: unresolved external symbol "public: void __thiscall ltbl::QuadtreeNode::pruneDeadReferences(void)" (?pruneDeadReferences@QuadtreeNode@ltbl@@QAEXXZ) referenced in function "public: void __thiscall ltbl::Quadtree::pruneDeadReferences(void)" (?pruneDeadReferences@Quadtree@ltbl@@QAEXXZ)
1>QuadtreeOccupant.obj : error LNK2019: unresolved external symbol "private: void __thiscall ltbl::QuadtreeNode::update(class ltbl::QuadtreeOccupant *)" (?update@QuadtreeNode@ltbl@@AAEXPAVQuadtreeOccupant@2@@Z) referenced in function "public: void __thiscall ltbl::QuadtreeOccupant::quadtreeUpdate(void)" (?quadtreeUpdate@QuadtreeOccupant@ltbl@@QAEXXZ)
1>QuadtreeOccupant.obj : error LNK2019: unresolved external symbol "private: void __thiscall ltbl::QuadtreeNode::remove(class ltbl::QuadtreeOccupant *)" (?remove@QuadtreeNode@ltbl@@AAEXPAVQuadtreeOccupant@2@@Z) referenced in function "public: void __thiscall ltbl::QuadtreeOccupant::quadtreeRemove(void)" (?quadtreeRemove@QuadtreeOccupant@ltbl@@QAEXXZ)
1>MapLoaderPrivate.obj : error LNK2019: unresolved external symbol __imp__inflate referenced in function "private: bool __thiscall tmx::MapLoader::Decompress(char const *,class std::vector<unsigned char,class std::allocator<unsigned char> > &,int,int)" (?Decompress@MapLoader@tmx@@AAE_NPBDAAV?$vector@EV?$allocator@E@std@@@std@@HH@Z)
1>MapLoaderPrivate.obj : error LNK2019: unresolved external symbol __imp__inflateEnd referenced in function "private: bool __thiscall tmx::MapLoader::Decompress(char const *,class std::vector<unsigned char,class std::allocator<unsigned char> > &,int,int)" (?Decompress@MapLoader@tmx@@AAE_NPBDAAV?$vector@EV?$allocator@E@std@@@std@@HH@Z)
1>MapLoaderPrivate.obj : error LNK2019: unresolved external symbol __imp__inflateInit2_ referenced in function "private: bool __thiscall tmx::MapLoader::Decompress(char const *,class std::vector<unsigned char,class std::allocator<unsigned char> > &,int,int)" (?Decompress@MapLoader@tmx@@AAE_NPBDAAV?$vector@EV?$allocator@E@std@@@std@@HH@Z)
1>c:\users\wolv\desktop\Projekty\MapLoader\Debug\MapLoader.exe : fatal error LNK1120: 9 unresolved externals

DJuego

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: Let There Be Light 2
« Reply #101 on: October 31, 2015, 03:42:32 pm »
From LTBL2 README

Quote
If you are using Visual Studio, you may have to set your startup project to the ERL project, and you may have to add the source files to the project.

So there are not ltbl2 libs for Visual Studio at the moment. :-/ Sorry.

DJuego

Strikerklm96

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Let There Be Light 2
« Reply #102 on: November 14, 2015, 08:27:43 pm »
For some reason this code:

        vector<sf::Vector2f> points;
        points.push_back(sf::Vector2f(0, 0));
        points.push_back(sf::Vector2f(0, 100));
        points.push_back(sf::Vector2f(100, 100));
        points.push_back(sf::Vector2f(100, 0));

        std::shared_ptr<ltbl::LightShape> lightShape = std::make_shared<ltbl::LightShape>();
        lightShape->_shape.setPointCount(points.size());
        for(int j = 0; j < points.size(); j++)
                lightShape->_shape.setPoint(j, (points[j]));
        lightShape->_shape.setPosition(Simple2D::b2ToSf(Vec2(3,3)));

        ls.addShape(lightShape);
produces a backwards occluder. I tried defining them CCW also. 

Edit: I just realized, is this the intended functionality? How could I just make a line segment that blocks light?
« Last Edit: November 16, 2015, 08:21:53 pm by Strikerklm96 »

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: Let There Be Light 2
« Reply #103 on: November 17, 2015, 10:16:24 pm »
@Strikerklm96: This is intentional. If you want to make the inside of the occluder dark, change the occluder's _renderLightOverShape property to false.

Also you should be able to make a line segment with a thin box. I am not sure why you would want it though.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Let There Be Light 2
« Reply #104 on: December 23, 2015, 11:17:00 pm »
I successfully port LTBL2 on Android, it works but not fine.

What's the problem? The lights and occluders works well but the lightRender blinks (in dark) , i tried a lot of thinks to fix it but all failed.

I have to say that all workarounds that i made work fine on PC (windows) without any problems.

I tested the .apk on a Xperia E3 and a Samsung Galaxy tab 4. In both present the same problem.

I will attach a set of images from my Xperia.

http://s000.tinyupload.com/index.php?file_id=05700573672291255943
I would like a spanish/latin community...
Problems building for Android? Look here

 

anything