SFML community forums

General => SFML projects => Topic started by: lolz123 on November 29, 2014, 10:59:36 pm

Title: Let There Be Light 2
Post by: lolz123 on November 29, 2014, 10:59:36 pm
Hello everyone,

As I mentioned in the original LTBL thread, I am currently (finally) remaking LTBL with clean code, more features, higher performance, and greater ease of use. It now uses only SFML as a dependency.

New features include:
- Directional lights
- Codeless light types
- Antumbras
- Superior performance
- Transparency

Follow the repository here: https://github.com/222464/LTBL2 (https://github.com/222464/LTBL2)

Demo available here: https://drive.google.com/file/d/0B2btNvgW7MHUQ0JfQTQ4ZndmNHc/view?usp=sharing (https://drive.google.com/file/d/0B2btNvgW7MHUQ0JfQTQ4ZndmNHc/view?usp=sharing)

(http://i1218.photobucket.com/albums/dd401/222464/tmxltbl.png)

Here is an example of antumbra rendering so far (this was impossible in the original LTBL):

(http://i1218.photobucket.com/albums/dd401/222464/antumbra.png)
Title: Re: Let There Be Light 2
Post by: p5ych0 on November 30, 2014, 12:24:42 am
Looks great so far! Keep up the good work. :)
Title: Re: Let There Be Light 2
Post by: Jabberwocky on November 30, 2014, 12:42:07 am
Looks great!
What is a Codeless light type?  Is that a data-driven light, such as how you can load a hull from file in LTBL1?
Title: Re: Let There Be Light 2
Post by: Jabberwocky on November 30, 2014, 03:16:34 am
Lolz, what are your thoughts on combining LTBL with a sprite per-pixel lighting shader (normal map), such as seen here:  http://en.sfml-dev.org/forums/index.php?topic=16830.0

I can think of a few approaches.
1.  LTBL only renders modulative shadows instead of additive lighting, and you render your sprites with a light shader.
2.  LTBL renders exactly as it does now, the composition texture is applied to the ground / background texture to render shadows, and all other sprites are rendered with a light shader.
3.  LTBL embeds light-direction data in the composition texture, and then the light shader can sample this composition texture to calculate the per-pixel lighting.

Thoughts?
Title: Re: Let There Be Light 2
Post by: lolz123 on November 30, 2014, 03:30:01 am
Jabberwocky,

I have thought of doing that actually, specifically the last approach you suggested. I will add it, it shouldn't be too hard.

The codeless light types allow you to make things like spotlights and light beams and such without using code. It only requires texture work now. There are 2 kinds of emitters: Point and directional. From these you can make all the lights in the original LTBL quite easily and more.

Any other features you would like to see? I might actually run a kickstarter for this, depending on how many features I end up adding.
Title: Re: Let There Be Light 2
Post by: lolz123 on November 30, 2014, 06:29:45 am
Progress shot of the day:

(http://i1218.photobucket.com/albums/dd401/222464/tmxltbl.png)

I used fallahn's tmx (Tiled) loader to load the map.
The tile set is from here: http://opengameart.org/content/platformer-tiles-4 (http://opengameart.org/content/platformer-tiles-4)
Title: Re: Let There Be Light 2
Post by: Hiura on November 30, 2014, 08:41:38 am
That's a very appealing demo you've got there!  :D

Looking forward to toying with it.
Title: Re: Let There Be Light 2
Post by: DJuego on November 30, 2014, 03:13:04 pm
I do not have words to describe the happiness that inspire this news for me. Thank you, lolz123!

DJuego
Title: Re: Let There Be Light 2
Post by: dabbertorres on November 30, 2014, 05:44:40 pm
Holy hell man, that looks beautiful.
Title: Re: Let There Be Light 2
Post by: StormWingDelta on November 30, 2014, 06:47:34 pm
Just wondering if anyone is or has worked on a C# port of this wonderful lighting system? :)
Title: Re: Let There Be Light 2
Post by: eXpl0it3r on November 30, 2014, 07:17:47 pm
It's neither finished nor released yet, how would someone work on a C# port already? :D
Title: Re: Let There Be Light 2
Post by: Jabberwocky on November 30, 2014, 10:54:05 pm
Jabberwocky,

I have thought of doing that actually, specifically the last approach you suggested. I will add it, it shouldn't be too hard.

Cool.
Would you need multiple composition textures to support multiple lights?

Any other features you would like to see? I might actually run a kickstarter for this, depending on how many features I end up adding.

My best guess, you are going to have 2 kinds of users:
1.  Users who want per-pixel lighting with normal maps.
2.  Users who don't.

I am (1), and I would happy contribute to a kickstarter for a project that supported this. 

In case you need to generate some normal maps to test this functionality, I believe both CrazyBump (http://www.crazybump.com/) and PixPlant (http://www.pixplant.com/download.php) have 30-day free trials.  Or you may just be able to find some free sample art from a google search.  Let me know if I can help with any of that.

In case you decide not to run a kickstarter, I'd still be happy to contribute a donation directly, just let me know.
Title: Re: Let There Be Light 2
Post by: lolz123 on November 30, 2014, 11:56:01 pm
Quote
In case you need to generate some normal maps to test this functionality, I believe both CrazyBump and PixPlant have 30-day free trials.  Or you may just be able to find some free sample art from a google search.  Let me know if I can help with any of that.

Don't worry about that  ;) I have my own self-made normal map generator. I used it for my 3D engine. Also Gimp has a plugin for it as well, and it is quite good.
Title: Let There Be Light 2
Post by: The Terminator on December 01, 2014, 04:09:37 pm
This is great! For the game I've just started I was disappointed that LTBL wasn't updated, but here it is now. Thanks a lot for the hard work.
Title: Re: Let There Be Light 2
Post by: Verra on December 02, 2014, 01:20:22 am
And God said, “Let there be light,” and there was light. God saw that the light was good, and he separated the light from the darkness. And our lord lolz123 spoke and he said, "Have a soley SFML dependent version of LTBL. I will cast out the evil dependencies and your programs will be blessed."

But seriously I've been waiting for this for a long time. Awesome work dude.
Title: Re: Let There Be Light 2
Post by: lolz123 on December 04, 2014, 04:35:27 am
I want to try Kickstarter, it should be ready by tomorrow! Then I can spend time adding all the features you guys want  ;)

Update screenshot:

(http://i1218.photobucket.com/albums/dd401/222464/ltblscreenshot2-1.png)
Title: Re: Let There Be Light 2
Post by: Sub on December 04, 2014, 06:13:00 am
Looking good!
Title: AW: Let There Be Light 2
Post by: eXpl0it3r on December 04, 2014, 07:45:11 am
Are you sure about Kickstarter? I don't really see how such a project will do well over there...

What can you give in return to your backers? Is your target audience enough big? Do you have the time for all the paperwork and preparation? Etc.

Kickstarter isn't or at least shouldn't be something you can just try out. But well I'm not stopping you...
Title: Re: Let There Be Light 2
Post by: Jabberwocky on December 04, 2014, 08:30:12 am
Looks great, lolz!
Title: Re: Let There Be Light 2
Post by: lolz123 on December 04, 2014, 08:15:53 pm
@Sub, Jabberwocky: Thanks!

@eXpl0it3r:

Quote
What can you give in return to your backers?

Other than the end result, I just have simple things planned, like animated gifs of names lit up by the lighting system.

Quote
Is your target audience enough big?

Well, if it isn't, then nothing is really lost, since it just falls through and nobody is charged. I also plan to add a lot more features then there currently are, hopefully making the project more attractive. Also keep in mind that I am not doing just the SFML version, but also a generic OpenGL version.

Quote
Do you have the time for all the paperwork and preparation?

Already done  ;) It's not so bad really.
Title: Re: Let There Be Light 2
Post by: lolz123 on December 05, 2014, 08:13:13 am
Another progress shot!

Two new features are shown here. One is the requested ability to render light over occluders properly, and the other is the use of custom light textures.

(http://i1218.photobucket.com/albums/dd401/222464/ltblspooky.png)
Title: Re: Let There Be Light 2
Post by: Grimshaw on December 05, 2014, 12:59:55 pm
Again a fantastic job mate !

How hard would it be to convert the rendering code into a new platform, say raw OpenGL or some other wrapper around low level rendering API's?
Title: Re: Let There Be Light 2
Post by: lolz123 on December 06, 2014, 03:30:12 am
@Grimshaw: A raw OpenGL version is planned!
Title: Re: Let There Be Light 2
Post by: Xafi on December 06, 2014, 03:28:54 pm
Is open source?
Title: Re: Let There Be Light 2
Post by: Grimshaw on December 06, 2014, 04:29:26 pm
I might integrate this into my game tools if it can be done seamlessly (aka able to integrate with my low level abstract renderer, which by itself can be DX/GL/Other).

You're really good at rendering man, you never fail to impress!
Title: Re: Let There Be Light 2
Post by: Kheartz on December 07, 2014, 02:50:21 am
Definitely looking forward to LTBL2. I thought the this project was dead for sure.

Looks like it's time for me to start taking down LTBL1  ::)
Title: Re: Let There Be Light 2
Post by: Jungletoe on December 18, 2014, 02:55:55 pm
I will keep posting updates here, the first version (2.0) should be done in about 3 days.

*cough*
Title: Re: Let There Be Light 2
Post by: Tank on December 18, 2014, 05:08:15 pm
Also, where's the kickstarter? :)
Title: Re: Let There Be Light 2
Post by: lolz123 on December 19, 2014, 12:16:33 am
Maybe I should adopt the "when it's done™" ;)

The first version I have now is very basic, but still heaps better than the original. The Kickstarter will come! The verification process takes some time. Also I had to make enough demos for there to be something to show in the video  ;D

I will upload it in the next 2 hours. For real!
Title: Re: Let There Be Light 2
Post by: lolz123 on December 19, 2014, 02:29:54 am
Here it is! Keep in mind that it is NOT yet ready for use. But now you can see how it develops!

https://github.com/222464/LTBL2 (https://github.com/222464/LTBL2)
Title: Re: Let There Be Light 2
Post by: Jabberwocky on December 19, 2014, 04:56:38 pm
Cool!  Great to see this committed to github, lolz. 
Title: Re: Let There Be Light 2
Post by: herrybiscuit on January 01, 2015, 12:12:43 am
is it possible to detect if an object is inside of the shadow? i have not played with this tool yet but i wanted to know before i get my hands dirty.
Title: Re: Let There Be Light 2
Post by: lolz123 on January 01, 2015, 02:55:50 am
Yes, it is possible to detect if something is in the shadow.
Title: Re: Let There Be Light 2
Post by: stulleman on January 30, 2015, 08:42:20 pm
Hey just out of curiosity, do know when you will release something we can experiment with?
Title: Re: Let There Be Light 2
Post by: Pridexs on February 10, 2015, 10:29:03 pm
This looks amazing! I messed around with LTBL1 when I was working in a top down shooter a few months back and I really liked it. Can't wait to see this improved version in action!
Title: Re: Let There Be Light 2
Post by: StormWingDelta on February 10, 2015, 10:54:34 pm
Might use this in my maze game when the first small release of code we can break turns up. :)   Good work as usual too. :D
Title: Re: Let There Be Light 2
Post by: Voroz on February 25, 2015, 01:33:51 pm
Hi. Nice that you're working on a new version. I'm using LTBL 1 right now and i like it alot. I've gotten it to work quite well but there are some bugs that you have to work around and it takes alot of testing to set it up correctly.
Title: Re: Let There Be Light 2
Post by: eXpl0it3r on February 25, 2015, 01:36:53 pm
Did you try my version of LTBL (https://github.com/eXpl0it3r/LTBL)? Or better yet switch to LTBL2. ;)
Title: Re: Let There Be Light 2
Post by: Voroz on February 25, 2015, 01:46:23 pm
Did you try my version of LTBL (https://github.com/eXpl0it3r/LTBL)? Or better yet switch to LTBL2. ;)
I didn't think LTBL2 is ready for use yet. I just saw the thread though. And no, i didn't try your version. Mine works, it's just a bit weird to get it to work, and there are no directional lights.
Title: Re: Let There Be Light 2
Post by: Voroz on February 25, 2015, 01:56:50 pm
Just checked that github link. He hasn't updated it since he posted it 2 months ago and then he said that "It's NOT ready for use", so i guess i will wait until he develops it further.
Title: Re: Let There Be Light 2
Post by: yhu420 on February 27, 2015, 01:41:04 am
Holy sh** this looks so nice.. I had never heard of LTBL before that post but damn it looks good.. Is there a "tech demo" available for download somewhere around here?
Title: Re: Let There Be Light 2
Post by: fakepotato on February 28, 2015, 10:39:14 pm
Wanna ask one question.
How to make everything on the window darkened except places with light? I have trouble with this..
Title: Re: Let There Be Light 2
Post by: lolz123 on March 06, 2015, 07:19:35 am
Hello everyone,

I'm not dead! I have just been busy with some other things lately, but I decided to set aside some time to finish up LTBL2.

A "usable" version is now on GitHub. I haven't tested it extensively, but from the few tests that I did do it looked fine, minus some minor shadow bugs that should get fixed soon.
Title: Re: Let There Be Light 2
Post by: JohnGreek on March 07, 2015, 08:36:23 pm
Hello, i try to compile your library with CMAKE but i run into std::make_unique error not defined. I did a bit
of research and it turned out that this is an upcoming c++14 function. Instead of injecting a template snippet in every *.h file is there an other way?

My OS is Win7 x64,
I tried with GCC 4.8.0 and 4.8.1.
Should i bother to try with 4.9.0?

Thanks :)
Title: Re: Let There Be Light 2
Post by: Jesper Juhl on March 07, 2015, 08:46:19 pm
Use a compiler with C++14 support or just add your own implementation.
You can grab STL (http://nuwen.net/stl.html)'s implementation (which is what got adopted in C++14 IIRC) from N3656 (http://isocpp.org/files/papers/N3656.txt).
Title: Re: Let There Be Light 2
Post by: JohnGreek on March 07, 2015, 09:46:44 pm
What flags and what executable i must use? With MinGW i just used mingw32-make on the bin folder of the project and i got it compiled. I searched a bit and found out i must provide the *.cpp files manualy?
Don't get me wrong, i don't want anybody to build it for me, i just want to learn how to do it.
Thanks :)


Edit: I got some progress but still.. Now i get undefined references to __gxx_personality and some other which means i use wrong exception handling DW/SJLJ or smth?
Title: AW: Let There Be Light 2
Post by: eXpl0it3r on March 08, 2015, 05:44:52 pm
IIRC GCC 4.9.x supports std::make_unique. Thus you should get a newer MinGW version, I can recommend the MinGW Builds which are by now part of the MinGW-w64 project.

To use C++14 features you need to add -std=c++14 to the build command.

As for your error, if you don't get exactly the same compiler as your binaries are built with, you'll have to do a clean rebuild with the new compiler (e.g. recompile SFML).
Title: Re: Let There Be Light 2
Post by: Jabberwocky on March 08, 2015, 10:01:11 pm
I'm very happy to see you back lolz! 
Your lighting stuff is great.
Title: Re: Let There Be Light 2
Post by: lolz123 on April 26, 2015, 07:37:57 am
Hello everyone,

LTBL is now almost at what I would call version 2.0! Just looking to fix some minor bugs now and improve performance. I will update the repository again with proper instructions tomorrow, stay tuned!

Antumbras now function properly alongside umbras as well now ;)

For now, here is another beauty-shot  :D

(http://i1218.photobucket.com/albums/dd401/222464/ltbl2spooky.png)
Title: Re: Let There Be Light 2
Post by: DJuego on April 26, 2015, 01:57:06 pm
Uops!! Precisely yesterday I took a  preliminary look and i tried the example: The application crashed  in the wood bridge ;D

Actually, I miss documentation   A documented API. :'(. At least, I think an exhaustive relation of features would be interesting. For example; does it cover all functionality of the original LTBL (1.5.1)? 
 
In any case, I want you to know that this news has brightened my day a lot,  8) Thanks! lolz123

DJuego
Title: Re: Let There Be Light 2
Post by: lolz123 on April 27, 2015, 07:42:05 am
New version with bug fixes and instructions is up! I will work on the instructions a bit more later, they are pretty basic right now. But hopefully they are enough to get started!

Also, a demo project is on the way!
Title: Re: Let There Be Light 2
Post by: DJuego on April 27, 2015, 06:43:58 pm
Ok lolz123!



**************************************************************************************
First:

(building with mingw-builds gcc 4.9.2 sjlj)

cmake -G 'MSYS Makefiles' -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=$DIRECTORIO_LOCAL -D SFML_ROOT=$DIRECTORIO_LOCAL ../..

[...]
-- Detecting CXX compile features - done
-- Found SFML 2.2 in v:/MinGW-Builds/mingw32/msys/local/include
CMake Error at CMakeLists.txt:14 (target_link_libraries):
  Cannot specify link libraries for target "LTBL2" which is not built by this
  project.

-----------

(building with msvc 18.0.31101.0 )

cmake -G 'NMake Makefiles' -D CMAKE_BUILD_TYPE=Debug -D CMAKE_INSTALL_PREFIX=$DIRECTORIO_INSTALACION_LIBRERIA -D SFML_ROOT=$DIRECTORIO_INSTALACION/SFML ../..

-- Found SFML 2.2 in w:/Archivos_de_programa/MSVC2013/x32/SFML/include
CMake Error at CMakeLists.txt:14 (target_link_libraries):
  Cannot specify link libraries for target "LTBL2" which is not built by this
  project.


------


It requires to add_library. I had to modify the CMakeLists.txt file:

set( SOURCE_PATH "${PROJECT_SOURCE_DIR}/source" )
set( SOURCES
        "${SOURCE_PATH}/ltbl/Math.h"
        "${SOURCE_PATH}/ltbl/Math.cpp" 
        "${SOURCE_PATH}/ltbl/lighting/LightDirectionEmission.cpp"
        "${SOURCE_PATH}/ltbl/lighting/LightDirectionEmission.h"
        "${SOURCE_PATH}/ltbl/lighting/LightPointEmission.cpp"
        "${SOURCE_PATH}/ltbl/lighting/LightPointEmission.h"
        "${SOURCE_PATH}/ltbl/lighting/LightShape.cpp"
        "${SOURCE_PATH}/ltbl/lighting/LightShape.h"
        "${SOURCE_PATH}/ltbl/lighting/LightSystem.cpp"
        "${SOURCE_PATH}/ltbl/lighting/LightSystem.h"
        "${SOURCE_PATH}/ltbl/quadtree/DynamicQuadtree.cpp"
        "${SOURCE_PATH}/ltbl/quadtree/DynamicQuadtree.h"
        "${SOURCE_PATH}/ltbl/quadtree/Quadtree.cpp"
        "${SOURCE_PATH}/ltbl/quadtree/Quadtree.h"
        "${SOURCE_PATH}/ltbl/quadtree/QuadtreeNode.cpp"
        "${SOURCE_PATH}/ltbl/quadtree/QuadtreeNode.h"
        "${SOURCE_PATH}/ltbl/quadtree/QuadtreeOccupant.cpp"
        "${SOURCE_PATH}/ltbl/quadtree/QuadtreeOccupant.h"
        "${SOURCE_PATH}/ltbl/quadtree/StaticQuadtree.cpp"
        "${SOURCE_PATH}/ltbl/quadtree/StaticQuadtree.h"
)

add_library( LTBL2 SHARED ${SOURCES} )
set_target_properties( LTBL2 PROPERTIES DEBUG_POSTFIX -d )

target_link_libraries(LTBL2 ${SFML_LIBRARIES})


*************************************************************************************
Second:

(building with mingw-builds gcc 4.9.2 sjlj)

[ 10%] Building CXX object CMakeFiles/LTBL2.dir/source/ltbl/Math.cpp.obj
p:/Plataformas/x32-x64/TRABAJO_MINGW_x32/LTBL2/LTBL2/source/ltbl/Math.cpp: In fu
nction 'float ltbl::vectorMagnitude(const Vector2f&)':
p:/Plataformas/x32-x64/TRABAJO_MINGW_x32/LTBL2/LTBL2/source/ltbl/Math.cpp:60:9:
error: 'sqrt' is not a member of 'std'
  return std::sqrt(vector.x * vector.x + vector.y * vector.y);
         ^

It requires to modify Math.cpp.

#include <cmath>

*********************************************************************************
Third:

(building with mingw-builds gcc 4.9.2 sjlj)

[ 20%] Building CXX object CMakeFiles/LTBL2.dir/source/ltbl/lighting/LightDirect
ionEmission.cpp.obj
In file included from v:/MinGW-Builds/mingw32/i686-w64-mingw32/include/c++/array
:35:0,
                 from P:/Plataformas/x32-x64/TRABAJO_MINGW_x32/LTBL2/LTBL2/sourc
e/ltbl/quadtree/QuadtreeOccupant.h:9,
                 from P:/Plataformas/x32-x64/TRABAJO_MINGW_x32/LTBL2/LTBL2/sourc
e/ltbl/lighting/LightDirectionEmission.h:4,
                 from p:/Plataformas/x32-x64/TRABAJO_MINGW_x32/LTBL2/LTBL2/sourc
e/ltbl/lighting/LightDirectionEmission.cpp:1:
v:/MinGW-Builds/mingw32/i686-w64-mingw32/include/c++/bits/c++0x_warning.h:32:2:
error: #error This file requires compiler and library support for the ISO C++ 20
11 standard. This support is currently experimental, and must be enabled with th
e -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^

It requires to modify CMakeLists.txt.

# Compiler-specific flags and definitions
if(CMAKE_COMPILER_IS_GNUCXX)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")

endif()
 

*******************************************************************************
Fourth:



(building with mingw-builds gcc 4.9.2 sjlj)
(building with msvc 18.0.31101.0) <- No import libs unfortunately. :-| Will we have official solution in the future?

(SHARED libraries) - Success!!!

Thanks lolz123!



DJuego
Title: Re: Let There Be Light 2
Post by: lolz123 on April 27, 2015, 07:13:48 pm
Thanks DJuego!

I'll admit, I was packaging up the library in a hurry yesterday, it was 3AM   ::) (edit - err, today  ;) )

I will fix up the build!
Title: Re: Let There Be Light 2
Post by: lolz123 on May 03, 2015, 10:25:59 pm
Hello!

I created a little demo for LTBL2!

Controls:
QWOP: move
Space: sprint

There is no goal, it's just a simple environment with some lighting to look at.

https://drive.google.com/file/d/0B2btNvgW7MHUQ0JfQTQ4ZndmNHc/view?usp=sharing (https://drive.google.com/file/d/0B2btNvgW7MHUQ0JfQTQ4ZndmNHc/view?usp=sharing)
Title: Re: Let There Be Light 2
Post by: Kori on July 09, 2015, 06:09:56 pm
Does anyone here already build LTBL2 under Linux? After succesfull cmake, during "make" i have this error:

Code: [Select]
[size=10pt]Scanning dependencies of target LTBL2
[ 10%] Building CXX object CMakeFiles/LTBL2.dir/source/ltbl/Math.cpp.o
[ 20%] Building CXX object CMakeFiles/LTBL2.dir/source/ltbl/lighting/LightDirectionEmission.cpp.o
In file included from /home/lord/dev/SFM_THOR_BOX2D/LTBL2-master/LTBL2/source/ltbl/lighting/LightSystem.h:3:0,
                 from /home/lord/dev/SFM_THOR_BOX2D/LTBL2-master/LTBL2/source/ltbl/lighting/LightDirectionEmission.cpp:5:
/home/lord/dev/SFM_THOR_BOX2D/LTBL2-master/LTBL2/source/ltbl/quadtree/DynamicQuadtree.h:3:36: fatal error: ltbl/Quadtree/Quadtree.h: Nie ma takiego pliku ani katalogu  // mean no such file or directory
 #include <ltbl/Quadtree/Quadtree.h>
                                    ^
compilation terminated.
make[2]: *** [CMakeFiles/LTBL2.dir/source/ltbl/lighting/LightDirectionEmission.cpp.o] Błąd 1 // mean error1
make[1]: *** [CMakeFiles/LTBL2.dir/all] Błąd 2 // mean error 2
make: *** [all] Błąd 2 //mean error 2 [/size]



thank you in advance :)
Title: Re: Let There Be Light 2
Post by: dabbertorres on July 09, 2015, 11:53:04 pm
Looks like a Windows "case does not matter" vs Unix "case does matter" issue to me.

Take a look at the folder name in "#include <ltbl/Quadtree/Quadtree.h>" and compare it to the folder name in ".../ltbl/quadtree/DynamicQuadtree.h:3:36". :)

(click to show/hide)
Title: Re: Let There Be Light 2
Post by: Kori on July 10, 2015, 10:18:42 am
Thanks, but unfortunately no  :-\
But I find something interesting. My folders CMakeFiles/LTBL2.dir/source/ltbl/lighting  and  CMakeFiles/LTBL2.dir/source/ltbl/Quadtree are empty. Maybe this is the problem, now, how to fix it.
Title: Re: Let There Be Light 2
Post by: eXpl0it3r on July 10, 2015, 10:33:55 am
Download the source again or if you used git, you can just go to the base directory and use git checkout ./
Title: Re: Let There Be Light 2
Post by: Rhimlock on July 10, 2015, 10:36:26 am
I had the same problem.

The cause was Quadtree/quadtree (case sensitive). So i changed the include-tags and everything worked.

But that was a few month ago.
Title: Re: Let There Be Light 2
Post by: Kori on July 11, 2015, 12:48:54 am
I download the code again, then in C::B change 'Q' and 'q', solve some problems with c++14 standard, and now everything work. Thanks to all!
Ps. If anyone have any exemple code, maybe send me via priv/mail or paste here. It will be propably more helpful than "quick start" on github.
Title: Re: Let There Be Light 2
Post by: Guido_Ion on July 15, 2015, 03:57:51 pm
Hey lolz123, nice demo! I would like to use this for my game, I was able to compile and add to my project but I'm having some troubles:

This is my code for the creation of a light (to test):

Quote
   // lights setup
   sf::Shader unshadowShader;
   sf::Shader lightOverShapeShader;
   unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag");
   lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag");
   sf::Texture penumbraTexture;
   penumbraTexture.loadFromFile("resources/penumbraTexture.png");
   penumbraTexture.setSmooth(true);

   ltbl::LightSystem ls;
   ls.create(sf::FloatRect(-1000.0f, -1000.0f, 1000.0f, 1000.0f), Game::GetWindow().getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

   std::shared_ptr<ltbl::LightDirectionEmission> light = std::make_shared<ltbl::LightDirectionEmission>();

   light->_emissionSprite.setTexture(penumbraTexture);
   light->_castDirection = sf::Vector2f(25.f, 25.f);

   ls.addLight(light);

That's all I do and the light won't show, am I missing something? Maybe a call to draw every frame to show the light?

I followed your quick start (https://github.com/222464/LTBL2), I don't understand which texture I have to use in this line "light->_emissionSprite.setTexture(penumbraTexture);" one of your textures?
Title: Re: Let There Be Light 2
Post by: Rhimlock on July 16, 2015, 02:42:52 pm
The textures are also in the github repository, where you found the quick start guide.

https://github.com/222464/LTBL2/tree/master/LTBL2/resources (https://github.com/222464/LTBL2/tree/master/LTBL2/resources)
Title: Re: Let There Be Light 2
Post by: Guido_Ion on July 21, 2015, 04:22:42 am
Thanks Glosa, I'm using those textures but still not showing any light.

Lolz, it would be nice to see the source code of the demo so we can see how exactly to use this. I'm creating light and then drawing it with Nrender but nothing happens  :-\

Cmake generated without errors, the sln compiled without problems and this is my code:

Sector.h:
Code: [Select]
...

#include <ltbl/lighting/LightSystem.h>

class Sector
{
public:
Sector(int mapNumber, int sectorNumber);
~Sector();
        ...

private:
...

ltbl::LightSystem ls;
sf::Shader unshadowShader;
sf::Shader lightOverShapeShader;
};

Sector.cpp (Constructor):
Code: [Select]
Sector::Sector(int mapNumber, int sectorNumber)
: static_objects_counter(0), enemies_counter(0), pickup_counter(0), _name(NumberToStr(sectorNumber))
{
belongsToMapNumber = mapNumber;

enemies.clear();
enemiesToRemove.clear();

unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag");
lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag");

sf::Texture penumbraTexture;
penumbraTexture.loadFromFile("resources/penumbraTexture.png");
penumbraTexture.setSmooth(true);

ls.create(sf::FloatRect(-1000.0f, -1000.0f, 1000.0f, 1000.0f), Game::GetWindow().getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

// Below is an example for creating one point light and one directional light:
std::shared_ptr<ltbl::LightPointEmission> plight = std::make_shared<ltbl::LightPointEmission>();

sf::Texture pointLightTexture;
pointLightTexture.loadFromFile("resources/pointLightTexture.png");
pointLightTexture.setSmooth(true);

plight->_emissionSprite.setOrigin(sf::Vector2f(0.f, 0.f));
plight->_emissionSprite.setTexture(pointLightTexture);
plight->_emissionSprite.setColor(sf::Color::Blue);
plight->_emissionSprite.setPosition(sf::Vector2f(100, 100));
plight->_localCastCenter = sf::Vector2f(0.f, 0.f); // This is where the shadows emanate from relative to the sprite

ls.addLight(plight);

std::shared_ptr<ltbl::LightDirectionEmission> dlight = std::make_shared<ltbl::LightDirectionEmission>();

sf::Texture directionLightTexture;
directionLightTexture.loadFromFile("resources/directionLightTexture.png");
directionLightTexture.setSmooth(true);

dlight->_emissionSprite.setTexture(directionLightTexture);
dlight->_castDirection = sf::Vector2f(10.f, 10.f);

ls.addLight(dlight);
}

Sector.cpp (update):
Code: [Select]
void Sector::update(sf::Time timeElapsedSinceLastUpdate)
{
        ...

ls.render(Game::GetWindow().getView(), unshadowShader, lightOverShapeShader);
}

Textures and shaders load fine (I checked), update is called, render is called, I'm not drawing the map over the lights, so I don't know what is the problem, any ideas?
Title: Re: Let There Be Light 2
Post by: Sayuri on July 28, 2015, 05:03:53 am
Thank you sooooo much for this project, it's really great!

I have a few questions, though:
To keep track of which lights and occluders belong to which object i not only use the "lightsystem.addLight(<light>)" to put a shared_ptr into the lightsystem but i also put shared_ptr of that same light in certain objects. For example for the flashlight of my player i currently have it like that:

Code: [Select]
class Player {
    std::shared_ptr<ltbl::LightPointEmission> flashlight;
}


And when creating the light i put a shared_ptr in both the LTBL2 lightsystem object aswell as my player flashlight pointer, like that:

Code: [Select]
Player::Player() {
    this->flashlight = std::make_shared<ltbl::LightPointEmission>();
    ...
    this->game->getLightsystem().addLight(light);
}

Effectively both the player and the light system have now each a shared_ptr that point to the light object.
The problem is now: how do i actually delete/deactivate/turn off the lights (for example turn off a flashlight or turn off a light in a room)? For example if i want to switch the flashlight off with a toggleFlashlight method, how would i do that?
This doesn't work (in Player.cpp):

Code: [Select]
void Player::toggleFlashlight() {
    this->game->getLightsystem().removeLight(this->flashlight);
}

because the shared_ptr from the player and the shared_ptr in the lightsystem are different, and the "removeLight()" method, as far as i can understand it, only checks for equality of the pointer (which isn't true, since the flashlight pointer of the player and the flashlight pointer in the light system have different adresses), not the actual light object that these pointers point to.

Do you have any suggestions how one could make lights that can be toggled on/off, and suggestions how to make object keep track of lights which belong to them while also being able to remove them at any time?
The only quick, but probably not smart, solution i found right now while writing this would be to set the scale to "0 ,0"
Code: [Select]
this->flashlight->_emissionSprite.setScale(0,0);This causes the light sprite to be too small to be rendered, virtually making it invisible and thus "turn off", and then, when "turning the light back on", i would turn the scale back to what it was.
But that seems kinda silly, since then i'd have to keep track of the original sprite scale and still have many lights that still need to be calculated, just with a (0,0) scale.

Another wierd alternative would be, instead of turning the scale to (0,0), to set the sprite color to sf::Color::Transparent, in order to make the sprite invisible, and then sf::Color::White to make the light visible again.

Do you have any suggestions which one to choose, or even alternatives for turning lights on/off?


In addition to that, may i suggest an "setActive(bool)" method, similar to Box2Ds system, for lights and occluders?
In Box2d you can set bodies to active or inactive, and if they're set to "setActive(false)" then these bodies won't be used for almost any calculation.
Could maybe something similar be done with LTBL2, where we can toggle lights and occluders on and off via "setActive(bool)" method, and inactive lights won't be drawn/inactive occluders won't make any shadows?
This could give us more control over the lights while also possibly saving performance by ignoring inactive lights/occluders in the render/quadtree calculations?

This is a really great project.
Again, thank you so much for creating it! I hope you will continue working on it.
Title: Re: Let There Be Light 2
Post by: Targa on July 29, 2015, 12:41:41 am
Dear,

First of all, thank you so much for sharing your code and hard work!
I would like to ask a question though, which has been asked before.

I do everything stated in the documentation, but no light seems to appear when I run my application.

I have an easy test project setup so I'll post the code I'm using at the moment.

This is the initialization of everything.
(click to show/hide)
The lights should be rendered here:
(click to show/hide)

I am looking forward to your answer!
Thanks in advance.
Title: Re: Let There Be Light 2
Post by: lolz123 on August 01, 2015, 02:33:39 pm
Hello,

Calling ls.render only renders the lights to an internal texture. You must then render the internal texture after calling ls.render. You can do this with ls.getLightingTexture. Make sure that the blending is set to multiplicative before you draw it on top of your scene!

Title: Re: Let There Be Light 2
Post by: DJuego on August 01, 2015, 09:53:38 pm
lolz123 Happy to read you this way again!

Your work has been VERY useful for me. SFML, Thor and LTBL2 are my Holy Trinity  ;D

Frankly, I am eager about new things in the LTBL2 project. ;D Please! please! please!.

A humble and very briefly explained tribute:

A multimedia application: Virtual ants in a virtual environment expel a pheromone trail in order that robotic ants follow it in a physic environment.

The virtual environment (tcp/ip-and-bluetooth server view) is a representation of physic environment  The multiple ants are controlled by human "players" in a local network. LTBL2 plays an important role here. Thanks again!

(http://i.imgur.com/4Up8OHxl.jpg)

The physic environment (global view). The robotic ants request info (bluetooth) to server about the amount of pheromone in a ground cell. Pheromone weakens with time. The pheromone only is visible in the virtual environment. In fact it was implemented with the particle system of Thor (Thanks Nexus;D).

(http://i.imgur.com/AIenoQpl.jpg)

The physic environment with the ant hole in foreground. Multiple robotic ants transport food to the anthill simultaneously  (stigmergic behavior (https://en.wikipedia.org/wiki/Stigmergy)).

(http://i.imgur.com/4U5oQDnl.jpg)

Sorry for my English!

[And of course MANY thanks to the SFML Team  :-* but this was a tribute for lolz123  :P]

DJuego
Title: Re: Let There Be Light 2
Post by: Guido_Ion on August 05, 2015, 12:07:38 am
Hello,

Calling ls.render only renders the lights to an internal texture. You must then render the internal texture after calling ls.render. You can do this with ls.getLightingTexture. Make sure that the blending is set to multiplicative before you draw it on top of your scene!

Hey Lolz, thanks for the answer, I've been able to render lights like this:

Code: [Select]
lightSystem.render(Game::GetWindow().getView(), unshadowShader, lightOverShapeShader);

lightsSprite.setTexture(lightSystem.getLightingTexture());
Game::GetWindow().draw(lightsSprite, sf::BlendMultiply);

and works good except it doesn't update the view when I move my player (even when I'm passing it to the render()), you can see this on the right of the screen capture attached (don't mind the crappy graphics, they are temporary  :P).

Am I missing something?
Title: Re: Let There Be Light 2
Post by: mashedtatoes on August 15, 2015, 02:36:33 am
Am I missing something?

You need to set the position of lightSprite when you move the camera.
lightSprite.setPosition(view.getCenter());
You will also need to set the sprite's origin so that the center of the sprite matches the center of he view.
lightSprite.setOrigin(view.getSize().x / 2.0f, view.getSize().y / 2.0f);
Do this before running the game.
Title: Re: Let There Be Light 2
Post by: Cupcake26699 on August 15, 2015, 11:56:25 am
Hey can anyone help me figure out why my programs don't compile even after successfully building with CMake on Visual Studio 2013?

I do the whole CMake thing, it compiles just fine with these settings:

Where is the source code: C:/Users/Me/Desktop/Main/LTBL2-master/LTBL2
Where to build the binaries: C:/Users/Me/Desktop/Main/LTBL2-master/LTBL2
I add the SFML_ROOT entry and point it to C:/SFML/SFML-2.2.

I specify the generator as Visual Studio 12 2013, after configuring I hit generate and it completes with no errors at all.

Then I go into a Visual Studio project that I know works with SFML 2.2 as I test opening a window.

I add these to the properties:

> C/C++
    >General

            > Additional Include Directories: C:\Users\Me\Desktop\Main\LTBL2-master\LTBL2\source\

> Linker
    >General

            > Additional Library Directories: C:\Users\Me\Desktop\Main\LTBL2-master\LTBL2\source\

After all that I finally make paste this simple piece of code into the Main.cpp file:

#include <SFML/Graphics.hpp>
#include <ltbl/lighting/LightSystem.h>

int main()
{

        sf::RenderWindow window(sf::VideoMode(600, 600), "SFML works!");

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                window.clear();
                window.display();
        }

        return 0;
}

And this code compiles just fine. However, if I add any type of ltbl object (such as ltbl::LightSystem) anywhere in the code, the compiler just gives me three LNK2001 errors.

How do I fix this?

Title: Re: Let There Be Light 2
Post by: Laurent on August 15, 2015, 12:17:00 pm
You set an additional library directory to the linker, so that it will know where to find the library, but you don't add the library itself (Linker > Input > Additional libraries).
Title: Re: Let There Be Light 2
Post by: Cupcake26699 on August 15, 2015, 12:41:09 pm
Thanks. I think I understand what you mean Laurent, however I don't see how I'm meant to actually include the library itself. There isn't a "Additional Libraries" section in the that section of the properties either.
Title: Re: Let There Be Light 2
Post by: Laurent on August 15, 2015, 01:51:53 pm
It was "Additional dependencies".
Title: Re: Let There Be Light 2
Post by: Cupcake26699 on August 15, 2015, 03:58:40 pm
I still don't know what to do to fix the bug, cant find any files that I believe would make sense going into additional dependencies.
Title: Re: Let There Be Light 2
Post by: DJuego on August 15, 2015, 05:29:22 pm
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.

Have you added the LTBL2 .cpp files to your project? Unfortunately there are not .lib files for LTBL2 in Visual Studio( :-[)

DJuego
Title: Re: Let There Be Light 2
Post by: mashedtatoes on August 15, 2015, 05:44:43 pm
I still don't know what to do to fix the bug, cant find any files that I believe would make sense going into additional dependencies.

I didn't use CMake at all. Just added the source files to my project. Edited some of the #includes because visual studio was complaining. Then compiled. Pretty simple.
Title: Re: Let There Be Light 2
Post by: Guido_Ion on August 15, 2015, 08:50:09 pm
Am I missing something?

You need to set the position of lightSprite when you move the camera.
lightSprite.setPosition(view.getCenter());
You will also need to set the sprite's origin so that the center of the sprite matches the center of he view.
lightSprite.setOrigin(view.getSize().x / 2.0f, view.getSize().y / 2.0f);
Do this before running the game.

Thanks! It is working now. LTBL2 is great :D

And this code compiles just fine. However, if I add any type of ltbl object (such as ltbl::LightSystem) anywhere in the code, the compiler just gives me three LNK2001 errors.

How do I fix this?

You need to add all cpp files of LTBL2 (those on /lighting, those on /quadtree and Math.cpp) to your project, you don't need to add anything to the Linker part, just to the C/C++ part "Additional Include Directories: C:\Users\Me\Desktop\Main\LTBL2-master\LTBL2\source\" as you did.
Title: Re: Let There Be Light 2
Post by: Cupcake26699 on August 16, 2015, 06:07:57 am
Thanks guys. It's working great now after following all your advice :)
Title: Re: Let There Be Light 2
Post by: Kori on August 24, 2015, 07:20:32 pm
I have an interesting problem. Normally lights is falling into obiect from side. In side-scroller it's perfect, but how to make a sun light in a top-down game, something like that :

(click to show/hide)
not like that:
 
(click to show/hide)
Illusion of light from above, without this long penubra shadow. Any ideas?
Title: Re: Let There Be Light 2
Post by: Hapax on August 25, 2015, 03:05:09 pm
The main part of the shadow seems to be exactly what you were aiming for but you have a faint shadow extending from it. You could try increasing the size of the light (or using many, multiple lights, probably in a circle) and/or increasing the strength of the lights.
Title: Re: Let There Be Light 2
Post by: Kori on August 25, 2015, 06:33:04 pm
I just make two light systems, first is normal, second is with modified penubra texture (i just cut out this bright part :D ). But, i don't know how it will be works with more lights on scene (performance).
 Especially, that i can't remove lights (don't know why, just removeLight() not working), so i holding pretty lot of them at once. 

Title: Re: Let There Be Light 2
Post by: Hapax on August 25, 2015, 06:54:20 pm
I don't know how LTBL works. Does it provide you with a greyscale channel to multiply over the scene? If so, you can use adjustment on the channel to 'bump up' the light greys to white, thus removing all of the slight lighting.
Title: Re: Let There Be Light 2
Post by: Kori on August 25, 2015, 07:13:45 pm
I think that this can make shadows very low intense and deformed. 2 light systems will be enought with posibility of deleting unusable lights.

This is my main problem. Does anyone know how to delete light and light Shape? In my opinion there is properly implemented remove function in code, but does nothing, or in some cases there is an error somewhere in QuadTree. Maybe just use ltbl 1.5?
Title: Re: Let There Be Light 2
Post by: lolz123 on September 12, 2015, 07:55:00 pm
Sorry for showing up here so rarely, I have been very busy lately (with AI related things! Info here for those interested: https://cireneikual.wordpress.com/2015/09/03/htsl2-evolving-the-neocortex-and-human-like-reinforcement-learning/ (https://cireneikual.wordpress.com/2015/09/03/htsl2-evolving-the-neocortex-and-human-like-reinforcement-learning/)).

I have hopefully fixed the removal bug. I also merged eXpl0it3r's changes (thanks for the help :) ).

Try pulling the latest!
Title: Re: Let There Be Light 2
Post by: Voroz on October 11, 2015, 05:06:15 pm
I'm trying to spawn a light for testing purposes, but i'm just seeing a hard rectangle shape instead of a smooth light. The rectangle is the same color as the light is supposed to be, but i only see the rectangle if i clear with white instead of standard black clear color.

This is the code i'm using:

#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <ltbl/lighting/lightSystem.h>

using namespace std;

int main(){
sf::ContextSettings Settings;
Settings.depthBits         = 24; // Request a 24 bits depth buffer
Settings.stencilBits       = 8;  // Request a 8 bits stencil buffer
Settings.antialiasingLevel = 0;  // Request 2 levels of antialiasing
// Set Screen Size
sf::Vector2<double> screenSize;
screenSize.x = 1000;
screenSize.y = 800;

//Create the Window
sf::RenderWindow App(sf::VideoMode(screenSize.x, screenSize.y, 32), "Test LTBL2", sf::Style::Close, Settings);

//Frame Limit
App.setFramerateLimit(0);

//Vertical sync
App.setVerticalSyncEnabled(true);

// lights setup
sf::Texture pointLightTexture;

if (!pointLightTexture.loadFromFile("resources/directionLightTexture.png"));

pointLightTexture.setSmooth(true);

sf::Texture penumbraTexture;

if (!penumbraTexture.loadFromFile("resources/penumbraTexture.png"));

penumbraTexture.setSmooth(true);

ltbl::LightSystem ls;

sf::Shader unshadowShader;
sf::Shader lightOverShapeShader;

if (!unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag"));
if (!lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag"));

ls.create(ltbl::rectFromBounds(sf::Vector2f(-1000.0f, -1000.0f), sf::Vector2f(1000.0f, 1000.0f)), App.getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

std::shared_ptr<ltbl::LightPointEmission> light = std::make_shared<ltbl::LightPointEmission>();

light->_emissionSprite.setOrigin(sf::Vector2f(pointLightTexture.getSize().x * 0.5f, pointLightTexture.getSize().y * 0.5f));
light->_emissionSprite.setTexture(pointLightTexture);
light->_emissionSprite.setScale(sf::Vector2f(1.0f, 1.0f));
light->_emissionSprite.setColor(sf::Color(255, 230, 200));
light->_emissionSprite.setPosition(sf::Vector2f(500, 400));

ls.addLight(light);

while (App.isOpen()){
    sf::Event Event;
    while (App.pollEvent(Event)){
        // Window closed
        if (Event.type == sf::Event::Closed){
            App.close();
        }
        // Key Pressed
        if (Event.type == sf::Event::KeyPressed){
            //Quit
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
                App.close();
            }
        }
        if (Event.type == sf::Event::KeyReleased){
        }
    }



    App.clear(sf::Color(255,255,255));
    ls.render(App.getDefaultView(), unshadowShader, lightOverShapeShader);

    sf::Sprite sprite;
    sprite.setTexture(ls.getLightingTexture());

    sf::RenderStates lightRenderStates;
    lightRenderStates.blendMode = sf::BlendMultiply;

    App.draw(sprite, lightRenderStates);
    App.display();
}

return 0;
}
Title: Re: Let There Be Light 2
Post by: lolz123 on October 11, 2015, 05:09:05 pm
Hello Voroz,

It seems like you are loading the directional light texture instead of the point light one  ;)
Title: Re: Let There Be Light 2
Post by: Voroz on October 11, 2015, 05:11:03 pm
Hello Voroz,

It seems like you are loading the directional light texture instead of the point light one  ;)
woah, that was a fast reply :). Yeah you're right, now it works :D.
Title: Re: Let There Be Light 2
Post by: Voroz on October 11, 2015, 05:15:30 pm
In your example of using directional light i got the same result with the rectangle light btw. This is from your example:

        sf::Texture pointLightTexture;

        pointLightTexture.loadFromFile("resources/directionLightTexture.png");

        pointLightTexture.setSmooth(true);

        sf::Texture penumbraTexture;

        penumbraTexture.loadFromFile("resources/penumbraTexture.png");

        penumbraTexture.setSmooth(true);

        ltbl::LightSystem ls;

        sf::Shader unshadowShader;

        unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag");

        ls.create(ltbl::rectFromBounds(sf::Vector2f(-1000.0f, -1000.0f), sf::Vector2f(1000.0f, 1000.0f)), window.getSize(), penumbraTexture, unshadowShader);

        std::shared_ptr<ltbl::LightDirectionEmission> light = std::make_shared<ltbl::LightDirectionEmission>();

        light->_emissionSprite.setOrigin(sf::Vector2f(pointLightTexture.getSize().x * 0.5f, pointLightTexture.getSize().y * 0.5f));
        light->_emissionSprite.setTexture(pointLightTexture);
        light->_emissionSprite.setScale(sf::Vector2f(6.0f, 6.0f));
        light->_emissionSprite.setColor(sf::Color(255, 230, 200));
        light->_emissionSprite.setPosition(sf::Vector2f(0.0f, 0.0f));
        light->_castDirection = ltbl::vectorNormalize(sf::Vector2f(-0.1f, 0.6f));
ls.addLight(light);
Title: Re: Let There Be Light 2
Post by: Voroz on October 11, 2015, 05:22:46 pm
I seem to have trouble with the directional light. This code is following your example and i only get a rectangle:
#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <ltbl/lighting/lightSystem.h>

using namespace std;

int main(){
sf::ContextSettings Settings;
Settings.depthBits         = 24; // Request a 24 bits depth buffer
Settings.stencilBits       = 8;  // Request a 8 bits stencil buffer
Settings.antialiasingLevel = 0;  // Request 2 levels of antialiasing
// Set Screen Size
sf::Vector2<double> screenSize;
screenSize.x = 1000;
screenSize.y = 800;

//Create the Window
sf::RenderWindow App(sf::VideoMode(screenSize.x, screenSize.y, 32), "Test LTBL2", sf::Style::Close, Settings);

//Frame Limit
App.setFramerateLimit(0);

//Vertical sync
App.setVerticalSyncEnabled(true);

// lights setup
sf::Texture directionLightTexture;

if (!directionLightTexture.loadFromFile("resources/directionLightTexture.png"));

directionLightTexture.setSmooth(true);

sf::Texture penumbraTexture;

if (!penumbraTexture.loadFromFile("resources/penumbraTexture.png"));

penumbraTexture.setSmooth(true);

ltbl::LightSystem ls;

sf::Shader unshadowShader;
sf::Shader lightOverShapeShader;

if (!unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag"));
if (!lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag"));

ls.create(ltbl::rectFromBounds(sf::Vector2f(-1000.0f, -1000.0f), sf::Vector2f(1000.0f, 1000.0f)), App.getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);

std::shared_ptr<ltbl::LightDirectionEmission> light = std::make_shared<ltbl::LightDirectionEmission>();

light->_emissionSprite.setOrigin(sf::Vector2f(directionLightTexture.getSize().x * 0.5f, directionLightTexture.getSize().y * 0.5f));
light->_emissionSprite.setTexture(directionLightTexture);
light->_emissionSprite.setScale(sf::Vector2f(1.0f, 1.0f));
light->_emissionSprite.setColor(sf::Color(255, 230, 200));
light->_emissionSprite.setPosition(sf::Vector2f(500, 400));
light->_castDirection = ltbl::vectorNormalize(sf::Vector2f(-0.1f, 0.6f));

ls.addLight(light);

while (App.isOpen()){
    sf::Event Event;
    while (App.pollEvent(Event)){
        // Window closed
        if (Event.type == sf::Event::Closed){
            App.close();
        }
        // Key Pressed
        if (Event.type == sf::Event::KeyPressed){
            //Quit
            if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
                App.close();
            }
        }
        if (Event.type == sf::Event::KeyReleased){
        }
    }



    App.clear(sf::Color(255,255,255));
    ls.render(App.getDefaultView(), unshadowShader, lightOverShapeShader);

    sf::Sprite sprite;
    sprite.setTexture(ls.getLightingTexture());

    sf::RenderStates lightRenderStates;
    lightRenderStates.blendMode = sf::BlendMultiply;

    App.draw(sprite, lightRenderStates);
    App.display();
}

return 0;
}
Title: Re: Let There Be Light 2
Post by: lolz123 on October 11, 2015, 05:40:04 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.
Title: Re: Let There Be Light 2
Post by: Voroz 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?
Title: Re: Let There Be Light 2
Post by: lolz123 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  ;)
Title: Re: Let There Be Light 2
Post by: Voroz on October 11, 2015, 05:50:03 pm
ah ok, i thought it was supposed to be a light like from a flashlight :)
Title: Re: Let There Be Light 2
Post by: Voroz 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.
Title: Re: Let There Be Light 2
Post by: Jesper Juhl 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?
Title: Re: Let There Be Light 2
Post by: Voroz 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.
Title: Re: Let There Be Light 2
Post by: Sayuri 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).
Title: Let There Be Light 2
Post by: eXpl0it3r on October 24, 2015, 09:04:03 am
Why not make a pull request? ;)
Title: Re: Let There Be Light 2
Post by: Sayuri 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).
Title: Re: Let There Be Light 2
Post by: DJuego 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
Title: Re: Let There Be Light 2
Post by: Wolv 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
Title: Re: Let There Be Light 2
Post by: DJuego 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
Title: Re: Let There Be Light 2
Post by: Strikerklm96 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.  (http://s1.postimg.org/8k7t5519b/thing.png)

Edit: I just realized, is this the intended functionality? How could I just make a line segment that blocks light?
Title: Re: Let There Be Light 2
Post by: lolz123 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.
Title: Re: Let There Be Light 2
Post by: DarkRoku12 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 (http://s000.tinyupload.com/index.php?file_id=05700573672291255943)
Title: Re: Let There Be Light 2
Post by: mashedtatoes on January 23, 2016, 03:12:23 am
Anybody run into this problem?

(https://i.imgur.com/aW5Nvni.png)

This is a trace over where the occluders are. The only light source is the red square.

(https://i.imgur.com/zWRGn1R.png)

The first occluder (the yellow line directly above the red square) is not stopping the light. It still does this if I make the light smaller (half the size). As long as the edge of the light gets past the opening, light shows through.

I also just noticed you can see occluders through other occluders when renderLightOverShape is set to true (https://i.imgur.com/dvoFIIN.png)
Title: Re: Let There Be Light 2
Post by: Breush on January 25, 2016, 12:41:49 pm
Hi everyone,

I noticed there was no change to 222464's repository of LBTL2 for the last few months and that none of the pull requests were accepted.

So I decided to fork LTBL2 in order to improve it.
This message is for any developer who wants to help the project to grow a little bit faster:
https://github.com/JumpingToasts/LTBL2 (https://github.com/JumpingToasts/LTBL2)

My main concerns are:

I'll be glad to receive suggestions or (even better) pull requests via the repository issue system.

Please note that this version is in active development, and really not ready for use.
Thank you for reading.
Title: Re: Let There Be Light 2
Post by: DarkRoku12 on January 31, 2016, 06:41:37 pm
Hi everyone,

I noticed there was no change to 222464's repository of LBTL2 for the last few months and that none of the pull requests were accepted.

So I decided to fork LTBL2 in order to improve it.
This message is for any developer who wants to help the project to grow a little bit faster:
https://github.com/JumpingToasts/LTBL2 (https://github.com/JumpingToasts/LTBL2)

My main concerns are:
  • Speed. I'm starting to improve the overall performance even if it requires to change the library interface. My aims are better data locality and as much as precomputing we can so that the render() loop can be the lightest of all. I think this is critical for games to run smoothly.
  • Abilities. I'm really interested about what can LTBL offer to the user. Today, I added a feature to handle normal maps. An example can be found in the example folder.
  • Interface. I was not really a big fan of original LTBL2 interface, as shared pointers add some computing penalty and no (easy) precise control of memory. I'm fully open to suggestions in order to improve the user experience.

I'll be glad to receive suggestions or (even better) pull requests via the repository issue system.

Please note that this version is in active development, and really not ready for use.
Thank you for reading.

Really happy to hear (see) this.

I use LTBL/LTBL2 on my projects. If i can contribute in something let me know.
Title: Re: Let There Be Light 2
Post by: Jabberwocky on February 03, 2016, 11:47:46 am
Cool stuff, Breush!
I'd be interested to hear about any ongoing work you do, and really appreciate you sharing.
Title: Re: Let There Be Light 2
Post by: Breush on February 04, 2016, 04:05:24 pm
Cool stuff, Breush!
I'd be interested to hear about any ongoing work you do, and really appreciate you sharing.

Thanks Jabberwocky and DarkRoku.

Here's a quick sum-up of my thoughts:

Finally, for people who want to help but don't want to get their hands too dirty (@DarkRoku), I guess one thing you can do is to create a tricky example and try if things goes wrong. And if so, report an issue (and try debug it yourself if you can).
I also wanted to add a small SFML sandbox application to make test things quickly. (For instance, a right click creates a box you can resize, a left click creates a light, and you can drag'n drop things around.) But, I don't think I will do it right now, but I'll be glad to see someone doing that for the project. :)

But I don't have so much time right now, so it has been basic changes so far.
(I'll soon launch a Greenlight trailer for the game I'm developing, hopefully LTBL will make it shine! :)) )
Afterwards, I will surely add a clear TODO list.
Title: Re: Let There Be Light 2
Post by: DarkRoku12 on February 05, 2016, 03:19:12 am

people who want to help but don't want to get their hands too dirty (@DarkRoku)


I´m re-mastering my game engine, and i had implement LTBL1 and LTBL2 (yes both), i will hard test your implementation.

I´m very insterested on the speed and interface part.

Hope you get all the success.
Title: Re: Let There Be Light 2
Post by: Jabberwocky on February 06, 2016, 11:38:39 am
A small thing I'm doing is getting rid of std::shared_ptr<> in the interface, as the shared pointer is not stored internally in the library, I really don't get why there is this restriction. Doing so, I'm using offering a way to let LTBL manage the lights memory for the user, using some pre-allocated memory pool.

I got rid of the shared_pointers in the interface, too.

I added a way to have the light react to normals, but one can imagine more (specularity/depth maps). And I've been doing so just for point lights, it needs to be extended to directional lights.

This is an interesting one.  I've been considering doing the same thing.

Since LTBL just spits out a texture you overlay onto the scene, I'd be interested how you accomplished this.  Do you output a second texture of light direction, which can be used in a shader to combine with the normals?  The only problem there is that you couldn't combine these textures in the same way LTBL combines its light textures into a composite overlay texture.

I am not an expert in that domain, but I was wondering if I could compute some parts of the code in parallel.

Neither am I.  Although it does seem like the kind of code which could be run in parallel.

There's no doubt LTBL has a significant impact on performance.  Although I haven't measured whether that performance is primarily CPU or GPU (in which case running the code in parallel wouldn't matter). 

I'll soon launch a Greenlight trailer for the game I'm developing, hopefully LTBL will make it shine! :)

Awesome, and good luck!  Make sure you post a link here so we can upvote.
Title: Re: Let There Be Light 2
Post by: Breush on February 06, 2016, 12:08:14 pm
I added a way to have the light react to normals, but one can imagine more (specularity/depth maps). And I've been doing so just for point lights, it needs to be extended to directional lights.

This is an interesting one.  I've been considering doing the same thing.

Since LTBL just spits out a texture you overlay onto the scene, I'd be interested how you accomplished this.  Do you output a second texture of light direction, which can be used in a shader to combine with the normals?  The only problem there is that you couldn't combine these textures in the same way LTBL combines its light textures into a composite overlay texture.

There is a dedicated example in the repository.
I do have a separate RenderTexture for the normals.
The idea is that each time you draw something,you also draw the normals version of it to the normals texture:

        head.setTexture(headTexture);
        window.draw(head);
        head.setTexture(headNormalsTexture);
        ls.normalsTargetDraw(head);

That way, whatever your scene graph is, you'll get a full representation of your scene in normals.
I think this is flexible enough to adapt to each system.

Afterwards, when the light system renders its lights, it will use the full normals texture for each composite part.
And you get the usual LTBL light texture to add to your scene (but with normals matching your scene!).
Title: Re: Let There Be Light 2
Post by: Jabberwocky on February 06, 2016, 03:36:33 pm
There is a dedicated example in the repository.
I do have a separate RenderTexture for the normals.
The idea is that each time you draw something,you also draw the normals version of it to the normals texture:

        head.setTexture(headTexture);
        window.draw(head);
        head.setTexture(headNormalsTexture);
        ls.normalsTargetDraw(head);

That way, whatever your scene graph is, you'll get a full representation of your scene in normals.
I think this is flexible enough to adapt to each system.

Afterwards, when the light system renders its lights, it will use the full normals texture for each composite part.
And you get the usual LTBL light texture to add to your scene (but with normals matching your scene!).

Ahh, right, that totally makes sense.

I was thinking about it in the wrong way (storing the light direction in a texture, not the scene normals).  It kind of works like a 3D deferred rendering pipeline.

Cool!
Title: Re: Let There Be Light 2
Post by: R23MJ on February 07, 2016, 02:49:35 am
If anything, I just want to be able to build this for windows; last time I checked it didn't work well and my only option was to add the files to my project. Which got clustered quickly. Anywho, I guess it's cool someone picked up the project.
Title: Re: Let There Be Light 2
Post by: DJuego on February 07, 2016, 01:43:46 pm
A lot of cheers and luck with your initiative, Breush!

I also am very interested in a ultimate 2D lighting system!  ;D

DJuego
Title: Re: Let There Be Light 2
Post by: Breush on February 07, 2016, 04:56:33 pm
If anything, I just want to be able to build this for windows; last time I checked it didn't work well and my only option was to add the files to my project. Which got clustered quickly. Anywho, I guess it's cool someone picked up the project.

I checked on Windows with MinGW32 and it did not worked. But I just fixed it.
The fact is that the compiler was confused because of the name Math.h, which it believed to be the standard include <math.h>. Strange but hey...
I don't have Visual Studio to test, but I know you'd need a recent version in order to have decent C++11 features.
Title: Re: Let There Be Light 2
Post by: DarkRoku12 on February 07, 2016, 07:06:08 pm
If anything, I just want to be able to build this for windows; last time I checked it didn't work well and my only option was to add the files to my project. Which got clustered quickly. Anywho, I guess it's cool someone picked up the project.

I checked on Windows with MinGW32 and it did not worked. But I just fixed it.
The fact is that the compiler was confused because of the name Math.h, which it believed to be the standard include <math.h>. Strange but hey...
I don't have Visual Studio to test, but I know you'd need a recent version in order to have decent C++11 features.

I can test it on Visual Studio 2013.

Want to i tried it know or better wait some days?
Title: Re: Let There Be Light 2
Post by: DJuego on February 07, 2016, 11:31:43 pm
If you allow me, I will partner with you in this beautiful purpose.

I can test it on Visual Studio 2015 when Breush considers the moment has come.

DJuego
Title: Re: Let There Be Light 2
Post by: Breush on February 08, 2016, 09:50:22 am
I can test it on Visual Studio 2013.
Want to i tried it know or better wait some days?
If you allow me, I will partner with you in this beautiful purpose.
I can test it on Visual Studio 2015 when Breush considers the moment has come.
Well, even if the project is not ready for release, I think the sooner, the better.
Because if there are some things I have to be careful about when coding, I'd like to know right now.

The repository has a CMake. It should be easy for you guys to test.
Let me know via an issue on GitHub or a pull request if you can fix it.

Thanks.
Title: Re: Let There Be Light 2
Post by: DarkRoku12 on February 08, 2016, 02:13:28 pm
I can test it on Visual Studio 2013.
Want to i tried it know or better wait some days?
If you allow me, I will partner with you in this beautiful purpose.
I can test it on Visual Studio 2015 when Breush considers the moment has come.
Well, even if the project is not ready for release, I think the sooner, the better.
Because if there are some things I have to be careful about when coding, I'd like to know right now.

The repository has a CMake. It should be easy for you guys to test.
Let me know via an issue on GitHub or a pull request if you can fix it.

Thanks.

I patched the sf::Color( r , g , b , a ) paramter. VS++ gime and error for requering narrowing conversion.
Also noexcept with

#ifndef _MSC_VER
   #define NOEXCEPT noexcept
#else
   #define NOEXCEPT
#endif
 


But, there are no __declspec(dllexport) to create shared libraries. The compiler (VS2013) only generates the .dll, cause there is no exports, .lib archive is not generated.
Title: Re: Let There Be Light 2
Post by: Cleroth on February 08, 2016, 03:44:52 pm
#if !defined(_MSC_VER) || _MSC_VER >= 1900
   #define NOEXCEPT noexcept
#else
   #define NOEXCEPT
#endif
 
Title: Re: Let There Be Light 2
Post by: DJuego on February 08, 2016, 03:47:26 pm
Well.  I tested with Microsoft Visual Studio 2015 (x64)  and MinGW ( x86-64-win32-seh-rev0 gcc 5.3.0). Both attempts failed.  :-[

My system is Windows 10. It was used the last SFML (from git repository).

I attached the nmake and make outputs.

DJuego
Title: Re: Let There Be Light 2
Post by: Breush on February 08, 2016, 04:04:43 pm
My system is Windows 10. It was used the last SFML (from git repository).

I attached the nmake and make outputs.

This just look like SFML not being linked in the program you're running.
Can you try with the option SFML_STATIC_LIBS set to true?
Title: Re: Let There Be Light 2
Post by: R23MJ on February 08, 2016, 04:34:16 pm
My apologies, I could have informed you that it was the lack of __declspec(dllexport). The only problems I had when building LTBL2 was the .lib was never built.
Title: Re: Let There Be Light 2
Post by: Breush on February 08, 2016, 04:53:17 pm
But, there are no __declspec(dllexport) to create shared libraries. The compiler (VS2013) only generates the .dll, cause there is no exports, .lib archive is not generated.
My apologies, I could have informed you that it was the lack of __declspec(dllexport). The only problems I had when building LTBL2 was the .lib was never built.
OK, I'm really not used to Windows environments.
Can either of you do a pull request or send me (via PM) a diff (git diff or svn diff)?
Title: Re: Let There Be Light 2
Post by: Axcelsior on February 17, 2016, 07:25:33 pm
Hi, just found this and it looks amazing! I want to try and implement LTBL2 into a game im working on. Can anyone explain to me how i include it it my project? I know i can include the directory directly in my project but is there a way to include it as a library / additional include ?
When I just add the files to my project I have to change #include <LTBL\xxxxx> to #"include <LTBL\xxxxx>"

I am using VS btw.
Title: Re: Let There Be Light 2
Post by: Axcelsior on February 28, 2016, 10:13:52 pm
1>Math.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::ConvexShape::ConvexShape(class sf::ConvexShape &&)" (__imp_??0ConvexShape@sf@@QAE@$$QAV01@@Z) referenced in function "class sf::ConvexShape __cdecl ltbl::shapeFromRect(class sf::Rect<float> &)" (?shapeFromRect@ltbl@@YA?AVConvexShape@sf@@AAV?$Rect@M@3@@Z)


I get this when i try to compile in VS 2015
Title: Re: Let There Be Light 2
Post by: scayze on June 27, 2016, 10:49:57 pm
Is there any way to use LTBL with vs 2015?
im trying to get it to work since some time. without any success. the .lib file wont generate & including all the source files into the project didnt work for me either :/
Title: Re: Let There Be Light 2
Post by: R23MJ on June 30, 2016, 07:58:42 pm
Is there any way to use LTBL with vs 2015?
im trying to get it to work since some time. without any success. the .lib file wont generate & including all the source files into the project didnt work for me either :/

It won't make windows files correctly, not sure why; including source files is your only option. We need to know what errors you are getting not "Didn't work for me either :/". What didn't work
Title: Re: Let There Be Light 2
Post by: Cleroth on June 30, 2016, 08:06:31 pm
Is there any way to use LTBL with vs 2015?
im trying to get it to work since some time. without any success. the .lib file wont generate & including all the source files into the project didnt work for me either :/
We need to know what errors you are getting not "Didn't work for me either :/". What didn't work

You mean like "It won't make windows files correctly, not sure why"?
Title: Re: Let There Be Light 2
Post by: R23MJ on July 02, 2016, 01:19:15 am
You mean like "It won't make windows files correctly, not sure why"?

I am not asking for help, he is. I have my version working.
Title: Re: Let There Be Light 2
Post by: tony_kero on July 13, 2016, 01:41:51 pm
Hey ! you have done a really great job, i want to use it in my game engine but when compiling in VS2015 i got weird errors
Debug Win32:


G:\Projets\Node\Repository\external\LTBL2-master\LTBL2\source\ltbl\quadtree\QuadtreeOccupant.cpp(15): error C2248: 'ltbl::Quadtree::_outsideRoot' : impossible d'accéder à protected membre déclaré(e) dans la classe 'ltbl::Quadtree'

G:\Projets\Node\Repository\external\LTBL2-master\LTBL2\source\ltbl\quadtree\QuadtreeOccupant.cpp(25): error C2248: '
ltbl::Quadtree::_outsideRoot' : impossible d'accéder à protected membre déclaré(e) dans la classe 'ltbl::Quadtree'
 

this lines say "impossible to reach protected member in class ltbl::QuadTree" from QuadtreeOccupant.cpp(15 and 25)

EDIT: Solved but i had to edit l 54 of Quadtree.h and add "friend class QuadtreeOccupant;"
Anyway great work keep on !
Title: Re : Let There Be Light 2
Post by: Cmdu76 on September 18, 2016, 11:51:52 pm
Hi !

While working on my engine I wanted to improve as much as possible LTBL2.
I forked the main repository and reviewed ALL the code.

Changes (compared to the actual version) :

Here is the repository :
https://github.com/Cmdu76/LTBL2

Feel free to suggest or pull request

(The next feature I might add is normals)

If lolz123 can see this, can you tell me if I need to make a pull request ? As it changes almost all files, I wasn't sure you'll accept it..
Title: Re: Let There Be Light 2
Post by: Retrospital on September 19, 2016, 05:46:29 pm
Thank you so much for your work Cmdu76 !!!
I'm speaking in the name of all our dev team here, we were looking forward to the implementation of the Sayuri awake/turned on system within the LTBL because we couldn't figure out how to do it by ourselves...And it's also a very good news that you got rid of the shared pointers !

Hopefully this will help us resolve our performance issues haha !

Thanks again !

Title: Re: Let There Be Light 2
Post by: DJuego on September 20, 2016, 11:28:45 pm
Yes. Thanks Cmdu76. Thanks. Thanks. Thanks! Any evolution of this extension is a great news.

In my opinion LTBL2 is one of the more interesting projects in the SFML cosmos (yes thor too  :P). Damn! It is one of the more interesting projects in the 2D graphics universe (!).  :D

Your changes seem fantastic. I will try to test them so soon be possible for me in Mingw-builgs gcc 6.2.0 and Visual Studio 2015.

I like very much the header-only proposal but if you need to add the LetThereBeLight.hpp & LetThereBeLight.cpp... is it header-only?  ??? Anyway i am happy. This is the joy of the day for me.  8)

DJuego

Title: Re : Let There Be Light 2
Post by: Cmdu76 on September 21, 2016, 08:32:40 am
I worked using VS2015 and I haven't tested it elsewhere yet.

Okay that is not really header-only, I read that having .cpp is better for compilation time.

I hope people will test it and give me some feedback.

I'm also working on the normals, I'm getting inspired by the implementation of Breush, here : https://github.com/JumpingToasts/LTBL2

The normals aren't in the two files, yet. I'm waiting a good implementation for normals

Title: Re: Let There Be Light 2
Post by: Guido_Ion on September 25, 2016, 07:46:08 pm
Thanks Cmdu76! I've been using LTBL2 for some time now ( video: https://youtu.be/CPy467vARa4 [EDIT: new better video] ) It's great, the main problem I have is the performance though. I'm going to try your version and give you some feedback.
Title: Re: Let There Be Light 2
Post by: Cmdu76 on September 29, 2016, 12:19:41 am
Today, I added my version of LTBL2 in my engine.

The previous version of a demo game using the main version of LTBL2 was running at 45 FPS,
The new version of this demo game using my version of LTBL2 is running at 55 FPS.

That is a small improvement but still good anyway. (+22%)


There is still something uncool with it, I was working on normals, but I'm not a graphical expert. I haven't succeed in adding that functionnality.
I added some code an interface to provide it but there is still a problem somewhere that don't render the normals...
It would be so great if anyone can help there :D

Title: Re: Let There Be Light 2
Post by: R23MJ on September 29, 2016, 03:15:48 am
First off: Thank you Cmdu76 for picking this project up!

Secondly, maybe this has been mentioned before, and there is probably a simple answer for it, but shouldn't the light be blocked by the side of the object that is facing it? I took some screenshots to help explain that. Look at the following.

(click to show/hide)

Everything looks fine when you draw whatever is blocking the light. Check out what happens when you don't though.

(click to show/hide)

The side of the box opposite to the light is blocking the light.. For most people this probably isn't a problem; however, in my project, I don't plan to draw the light blockers. Maybe this is intentional, I'm not sure, maybe you could look at it Cmdu76?

To further explain what I mean, I edited the second image to produce what I would expect the result to be.
(Or similar to this)

(click to show/hide)

EDIT::
To, again, further explain, I would expect the result to be the above because we are lighting in a 2D world, meaning the side of the block facing us could have any depth, in a 2D world that wouldn't be measure. For the light to shine on the side of the block facing the player we would have to assume the light is 3D, that is, it has enough depth to light the top of the block, and it is also positioned closer the the player, meaning it is on a different plane that the object it is shining light on.
Title: Re: Let There Be Light 2
Post by: Cmdu76 on September 29, 2016, 12:03:49 pm
lolz123 added this functionnality but as the project wasn't documented most people doesn't noticed it.

You can use :
shape->setRenderLightOver(true); // If you use my version
shape->_renderLightOverShape = true; // If you use lolz123 version's

Edit : I tested it, and the result wasn't what I expected, I'll take look...
Title: Re: Let There Be Light 2
Post by: R23MJ on September 29, 2016, 02:26:09 pm
I simulated the effect I wanted simply by setting the objects color to the light systems ambient color. Works unless you use alpha.
Title: Re: Let There Be Light 2
Post by: Ezhoikam on October 02, 2016, 02:08:42 pm
Is it possible to use it with the isometric tiled maps?
Title: Re: Let There Be Light 2
Post by: Cmdu76 on October 02, 2016, 03:28:48 pm
@R23MJ

I hadn't the time to really look at it...
But you can try something like that :
sf::RectangleShape shape;
shape.setSize({ 200.f, 50.f });
shape.setPosition({ 500.f, 300.f });
shape.setFillColor(lightSystem.getAmbientColor());
lightSystem.createLightShape(shape);
And then draw your shape

@Ezhoikam

Isometric usually divide y-axis length by 2, but I suggest you to try. The effect might be good depending on the render you want.
Title: Re: Let There Be Light 2
Post by: smguyk on October 29, 2016, 08:36:46 pm
Cmdu76 I'm trying to use your version but I'm getting these errors:

(click to show/hide)

What do I have to do? :/

I also tried the original version but I can't compile that one either because make_unique and other c++14 stuff isn't supported on my compiler

edit: yeah it was due to old files it's fixed now thank you!
Title: Re: Let There Be Light 2
Post by: Cleroth on October 29, 2016, 08:38:19 pm
Why are you using VS2012?
Title: Re: Let There Be Light 2
Post by: Guido_Ion on October 30, 2016, 01:02:05 am
Cmdu76 I'm trying to use your version but I'm getting these errors:

(click to show/hide)

What do I have to do? :/

I also tried the original version but I can't compile that one either because make_unique and other c++14 stuff isn't supported on my compiler

Maybe you should rebuild the entire solution, VS might not have recognized that you changed some files.
Title: Re: Let There Be Light 2
Post by: Guido_Ion on January 21, 2017, 08:50:14 pm
Hey, I'm having trouble getting this effect: I need occluders to cast shadows over other occluders like this:

(http://i63.tinypic.com/msbtvp.png)

I need the box on the bottom to be affected by the box on the top (meaning: be in the dark), like the player is.
In (1) player and grey box are visible and on (2) only the player is in the dark while the grey box isn't affected by the shadow of the big box.
Any idea on how to achieve this?
Title: Re: Let There Be Light 2
Post by: DarkRoku12 on January 22, 2017, 03:31:19 am
Hey, I'm having trouble getting this effect: I need occluders to cast shadows over other occluders like this:

(http://i63.tinypic.com/msbtvp.png)

I need the box on the bottom to be affected by the box on the top (meaning: be in the dark), like the player is.
In (1) player and grey box are visible and on (2) only the player is in the dark while the grey box isn't affected by the shadow of the big box.
Any idea on how to achieve this?

I was messing with this severals months ago, i couldn't reach a reliable way to solve this issue, but you can try the method "renderLightOverShape"
Title: Re: Let There Be Light 2
Post by: Ungod on January 28, 2017, 05:22:28 pm
I use ltbl2 in my game "Last of the Ambaras" now :)  Just wanted to share some impressions. I refactored the framework to support my own quad-tree and modified the interface. I didnt see ltbl2 in a top-down-game before, so I guess some of you might be interested in how it could look.

(https://media.giphy.com/media/l0ExiU81D6ucRQqNa/source.gif)
Title: Re: Let There Be Light 2
Post by: eXpl0it3r on January 28, 2017, 05:55:27 pm
Looks nice! Do you have your changes to LTBL2 online somewhere?
Title: Re: Let There Be Light 2
Post by: Ungod on January 28, 2017, 06:43:57 pm
Uploaded it here: https://github.com/Ung0d/light_ungod/tree/master

However, its fully integrated in my engine (uses my quad-tree, depends on my signal system to emit signals when a light of an entity is changed, depends on my logger ect...) so this is not intended to compile in any way. I dont want to make my whole engine open source, hope you understand :)

I merged the things together I liked most of the different reimplementations of LTBL2 posted in this thread and added the stuff I usually have in systems in my engine (component-support, signals ect). I biggest changes I made are:

1) I introduced LightAffectors. Thats basically a std::function-wrapper that refers to a specific PointLight. The affector code is called every frame. Maybe its note noticeable in the gif, but you can realize light-flickering and other neat stuff this way. See LightSystem::update and LightAffector class

2) In (I think) all other versions of ltbl, a Light and a LightCollider were rendered (and all heavy calculations were computed) even if their bounding boxes did not collide and thus the light was not affected by the collider at all. I changed that behavior. Now the LightSystem checks for collision of the bounding boxes (which is cheap in compare) and light-colliders that do not collide with a light are ignored. See LightSystem::renderLight
Title: Re: Let There Be Light 2
Post by: Alia5 on March 16, 2017, 12:30:07 am
I currently work on a "small" game framework using SFML and LTBL2.

Starting out with the version of  Cmdu76, I modified it a bit further.
In addition to normal maps, I implemented specular maps, the ability for occluders to cast shadows on other occluders and also added a little pseudo-bloom shader.
The pseudo bloom isn't embedded in LTBL2 (yet?) but sits in a wrapper class of mine.

(http://i.imgur.com/v1UTHB4.gif) (http://sharex.flatspot.pictures/sfml/2017-03-16_0005.mp4)
Click the gif for a higher quality window
Title: Re: Let There Be Light 2
Post by: Cmdu76 on March 16, 2017, 10:48:18 am
Nice ! I'm glad it helped you !

Do the modifications you made are open source somewhere ?
Title: Re: Let There Be Light 2
Post by: Alia5 on March 16, 2017, 12:06:40 pm
Sure! There (https://github.com/Alia5/FSE) you go. :)

It's not a separate LTBL2 repo, though, as I have it merged into my framework.

Edit:
It's worth noting that I didn't implement normal/specular maps for directional lights yet.
Also, I changed LTBLs sprites to require a separate call for drawing the regular texture, normals and specular, which kinda defeats the point a bit, but makes it overall more flexible.
Title: Re: Let There Be Light 2
Post by: DJuego on April 08, 2018, 10:04:28 pm
Any update about this? It is a pity that there is no a lighting extension for SFML alive and happy. :-|

DJuego
Title: Re: Let There Be Light 2
Post by: JSpirit on April 24, 2018, 05:53:51 pm
Hey, it is possible to disable the shadow "system", and keep the image light effect and mostly the occluders effect ?
Title: Re: Let There Be Light 2
Post by: Alia5 on April 24, 2018, 06:23:13 pm
I guess you wouldn't need such a complex library for that.
Just draw your "lights" to some renderTexture, draw black shapes for your occluders, and finally blend that render texture additively ;)
Title: Re: Let There Be Light 2
Post by: Grundkurs on November 03, 2018, 08:14:35 pm
to sum it up:
let there be light (https://github.com/eXpl0it3r/LTBL)
let there be light 2 (https://github.com/222464/LTBL2)
let there be light 2 by Cmdu76 (https://github.com/Cmdu76/LTBL2)
let there be light 2 by Alia5 (https://github.com/Alia5/FSE/tree/master/LTBL2)

I did notice that Alia5 did further improve Cmdu76's version of LTBL2, for example ltbl::LightSystem::create now deletes existing objects (marked as TODO in Cmdu76 version), BaseLight in Utils.hpp got a virtual Destructor which is important to prevent object slicing when inherited objects are deleted and so forth...
It seems advisable to use Alia5's version of LTBL2.
Title: Re: Let There Be Light 2
Post by: DJuego on November 03, 2018, 09:15:07 pm
Thank you for the LTBL2 compilation, Grundkurs

Well. I wish so much that this project had a more updated and powerful successor ...

DJuego
Title: Re: Let There Be Light 2
Post by: Alias on November 05, 2018, 02:11:57 am
Hey while using Cmdu76's version of the library I am getting a segfault in the LightSystem::Update(sf::Vector2u const& size) function at mEmissionTempTexture.create(size.x, size.y); while running the example project (https://github.com/Cmdu76/LTBL2/blob/master/examples/main.cpp).

Here is the backtrace:

#0  0x00007ffff7b94ed4 in sf::RenderTarget::initialize (this=0x7fffffffd628) at /SFML/Graphics/RenderTarget.cpp:545
#1  0x00007ffff7b933d4 in sf::RenderTexture::create (this=0x7fffffffd628, width=800, height=600, settings=...) at SFML/Graphics/RenderTexture.cpp:92
#2  0x00007ffff7b93264 in sf::RenderTexture::create (this=0x7fffffffd628, width=800, height=600, depthBuffer=false) at SFML/Graphics/RenderTexture.cpp:54
#3  0x000000000041ac01 in ltbl::LightSystem::update (this=0x7fffffffd070, size=...) at LTBL/LightSystem.cpp:330
#4  0x0000000000418ff3 in ltbl::LightSystem::create (this=0x7fffffffd070, rootRegion=..., imageSize=...) at LTBL/LightSystem.cpp:44
#5  0x0000000000406e87 in main () at main.cpp:43

And here's some screenshots of the output:
(https://i.imgur.com/bqQFzxl.png)
(https://i.imgur.com/pwOQ7OW.png)

Anybody see what I'm doing wrong?
Title: Re: Let There Be Light 2
Post by: Grundkurs on November 05, 2018, 10:29:42 pm
@Alia5: i tried your LTBL2 implementation, however a minimal example already produced a strange result.
I cannot set the Origin of a LightPointEmission-Object to the center without the Light-Point getting "spliced".
I did use the common "pointLightTexture.png", which is round.

#include "LTBL2/LightSystem.hpp"
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
int main() {
    sf::RenderTexture normal_texture_;
    sf::RenderTexture specular_texture_;
    sf::RenderWindow window{sf::VideoMode{800,600}, "LightShow"};
    ltbl::LightSystem lightSystem{normal_texture_,specular_texture_,true};
    lightSystem.create({ -1000.f, -1000.f, 2000.f, 2000.f }, window.getSize());

    sf::Texture pointLightTexture;
    pointLightTexture.loadFromFile("../examples/pointLightTexture.png");
    pointLightTexture.setSmooth(true);

    auto* light = lightSystem.createLightPointEmission();
    light->setTexture(pointLightTexture);
    light->setOrigin(pointLightTexture.getSize().x / 2.f, pointLightTexture.getSize().y / 2.f);
    light->setScale(10.f,10.f);

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
        sf::Vector2f pos(sf::Mouse::getPosition(window));
        light->setPosition(pos);

        window.clear(sf::Color::White);
        lightSystem.render(window);
        window.display();
    }
    return 0;
}
 

This produces this Lightpoint:
(https://c1.staticflickr.com/5/4862/45013972764_2166a2feec.jpg)

The white dot marks the position of the mouse (the mouse cursor does not get captured when taking screenshots).
Title: Re: Let There Be Light 2
Post by: Alia5 on November 06, 2018, 11:54:26 am
@Grundkurs
I haven't worked on anything the last half a year or something, but I don't think my mods to LTBL2 work really well for a standalone implementation outside of FSE. (Hence it's not a fork but directly baked into the repo)

For reference you can look at:
https://github.com/Alia5/FSE/blob/master/FSE/Lights/FSELightWorld.cpp (https://github.com/Alia5/FSE/blob/master/FSE/Lights/FSELightWorld.cpp)

Edit: I might decouple them somewhat one day, but when and if that day ever comes remains to be seen
Title: Re: Let There Be Light 2
Post by: Glucio on February 12, 2019, 08:18:37 pm
I've been trying to fiddle with this for a bit.
So after a long and hair pulling process, I managed to generate a .lib (I think)

Now that my project builds yet again, I'm trying to add some lights but since there is no documentation, I'm having a rough time.

Would anyone be able to shine some light for me? (Sorry for the bad pun)  :-X

Any help would be appreciated!

Edit: spelling
Title: Re: Let There Be Light 2
Post by: Guido_Ion on July 25, 2019, 09:29:25 pm
Hi, I hope this is not dead  ??? I'm still using LTBL2 , it's great!

For performance issues I wanted to use 2 diferent ltbl::LightSystem(), one for static lights (render once, draw every frame) and another one for dynamic lights (render and draw every frame).

The issue I'm having is that when drawing both lightSystems everything is really dark, I guess the not lighted parts are being drawn twice, thus turning everything dark.

Is there a way to only draw the lights for each lightSystem and not the dark parts?  :o

Or maybe there is another way instead of using 2 light systems, I need to render only the lights that change and not the static ones, BUT I need to draw every light, every frame.
Title: Re: Let There Be Light 2
Post by: Hapax on July 29, 2019, 02:37:28 am
Is there a way to only draw the lights for each lightSystem and not the dark parts?  :o
You could try drawing the second one using an additive blend mode.
See BlendMode documentation (https://www.sfml-dev.org/documentation/2.5.1/structsf_1_1BlendMode.php).
Title: Re: Let There Be Light 2
Post by: Guido_Ion on July 29, 2019, 05:32:40 pm
Thanks for the answer, but that didn't work, it still draws the dark parts twice and the lights very strong, that's not the result I want.
Maybe I need to create other sprites (penumbraTexture.png, etc.) with the dark parts as transparent for the second lightsystem. I don't know how to do that but I'll mess around with GIMP and see what's the result.

If lolz or someone has another easy answer for using 2 light systems it would be great.
Title: Re: Let There Be Light 2
Post by: grzyboleusz on March 12, 2020, 02:51:20 pm
Hello, I've been using SFML for quite a while, but stumbled upon this gem of a library a few days ago.

I have successfully integrated Alia5's version of LTBL2 and I am VERY pleased with it but there's 1 thing missing for me to achive what I want:
I'd love to have a directional light source to interact with normal/specular maps - a way to lit the surface of every object drawn to normal map buffer from given angle, a kind of global light source.
I suspect it can be done after every other light source is drawn with slight modification of existing shaders, but currently it's beyond me. If I'll manage to do it I'll post it here, but feel free to be first if it's no biggie to you  :-*

Many thanks to everyone involved in this project and SFML itself.
Title: Re: Let There Be Light 2
Post by: grzyboleusz on March 17, 2020, 11:31:27 am
As I said, there it is:

Shader to add global directional lighting, every pixel is lit from given direction vector without cosidering the distance (slightly modified version of the one included in the library, I only use it to draw light with additive blending):

(click to show/hide)

Also, I needed a shader to correct rotated normal maps of the sprites so there it is:
(click to show/hide)

As you can see, it uses vertex color channels to represent rotation and flipping, so you dont have to set any uniforms while drawing - useful for collective VertexArrays
Red color - if lower than 1.0 (or 255 in sf::Color) flips the normal map horizontally
Green  color - if lower than 1.0 (or 255 in sf::Color) flips the normal map vertically
Blue color - is angle in radians divided by Tau (2 * Pi)
Simply use it to draw normal maps
Title: Re: Let There Be Light 2
Post by: Yuri on May 27, 2020, 03:09:11 pm
Hello

I have problem thats my light point emmision is only a half of circle and i dont know how to fix it :/
I use fallowing code with Alia5 LTBL2:

Code: [Select]
#include "ltbl/lighting/LightSystem.hpp"
#include <SFML/Graphics.hpp>
#include <iostream>


int main() {
    sf::RenderTexture normal_texture_;
    sf::RenderTexture specular_texture_;
    sf::RenderWindow window{sf::VideoMode{800,600}, "LightShow"};
    ltbl::LightSystem lightSystem{normal_texture_,specular_texture_,true};
    lightSystem.create({ -1000.f, -1000.f, 1000.f, 1000.f }, window.getSize());


    sf::Texture pointLightTexture;
    pointLightTexture.loadFromFile("resources/pointLightTexture.png");
    pointLightTexture.setSmooth(true);


    auto* light = lightSystem.createLightPointEmission();
    light->setTexture(pointLightTexture);
    light->setOrigin(pointLightTexture.getSize().x / 2.f, pointLightTexture.getSize().y / 2.f);
    light->setScale(10.f,10.f);


    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
        sf::Vector2f pos(sf::Mouse::getPosition(window));
        light->setPosition(pos);


        window.clear(sf::Color::White);
        lightSystem.render(window);
        window.display();
    }
    return 0;
}
any tips?

edit: dummy me
 ltbl::LightSystem lightSystem{normal_texture_,specular_texture_,FALSE};