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

Author Topic: SFML Light System - Let There Be Light  (Read 258021 times)

0 Members and 1 Guest are viewing this topic.

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #120 on: May 04, 2012, 01:34:15 am »
Lasers would be pretty simple, but would be completely separate from the rest of the light system. But, I can add it if you like. I was thinking more about mirrors for point light sources, those would  be a lot harder to do :)
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #121 on: May 04, 2012, 05:01:37 am »
Quote from: lolz123
I am not sure why you would want mirrors in a 2D game...
I'm making a puzzle game based on lights. That is why I need a mirror, and colored lights and transparency and such. Without them, the puzzles would be slightly boring.

Quote from: lolz123
...but a planar mirror should be possible, if you render a second light representing the image of the light source in the mirror, and then invert the shadow masking for the mirror.
This is exactly what I have in mind. The interesting part kicks in when some mirrors are facing at each other, or are in an angle next to each other, so light bounces off them multiple times. Ahh.. thinking is sometimes just plain tiring. :D

Quote from: lolz123
Curved mirrors would be pretty difficult...
Whoa, man, these kind of ideas give me a heart attack :D Yes, they would be, at least with a vector-based engine. And I don't even dare to think about refractions... with curved surfaces...

Thanks for the answers, and keep up the good work :)

DJuego

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #122 on: May 19, 2012, 01:02:01 pm »
Just keeping the sentiment alive.  ;D

DJuego

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: SFML Light System - Let There Be Light
« Reply #123 on: May 26, 2012, 04:11:35 pm »
Argh!

Just finished my University work and was about to start again working on my hobby game and noticed the new SFML update that fixes a big error.

I downloaded it and noticed the all the directories and installation method has changed..

can anyone explain how to install this?

before it was just drag into your project which was easy...

I have tried to include LTBL/ but to no avail :(
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #124 on: May 26, 2012, 08:26:08 pm »
Just link to the "Source" folder, and include the headers like so: #include <LTBL/.../...>
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: SFML Light System - Let There Be Light
« Reply #125 on: May 27, 2012, 05:02:47 am »
Hey mate!

Yeah that worked -,- haha thanks..

I noticed you haven't included your source to the demo program anymore so its hard to run tests :( and the code in your PDF readme does not have the fixed naming conventions and is throwing errors at really strange stuff like

Code: [Select]

ltbl::Light* testLight = new ltbl::Light();


Saying 'object of abstract class not allowed'

also - did you fix the problem where a light wouldn't actually 'light' up the texture, but just put a fake overlay on top - so if the ambient light was (0,0,0) there would be no light anywhere even if there was a light where i was standing? as I wanted to do a game with 0 ambient light and where lights would actually 'light' up an area - this actually worked in your first few versions but broke recently :(

Cheers Lolz - great work.
« Last Edit: May 27, 2012, 05:04:50 am by 1337matty »
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #126 on: May 27, 2012, 01:13:58 pm »
I didn't update the example program in the manual properly yet (sorry about that  :P), instead of Light it is now Light_Point which inherits from Light.

For the texture lighting problem, I am not quite sure how you are getting that. You must render the light texture at the very end of a frame, or else the multiplicative blending won't work. It sounds like you are getting normal alpha blending instead of multiplicative blending somehow.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Roose Bolton of the Dreadfort

  • Full Member
  • ***
  • Posts: 113
  • Full-time Procrastinator, Part-time programmer.
    • View Profile
    • Personal Portfolio/Website/Blog
Re: SFML Light System - Let There Be Light
« Reply #127 on: May 28, 2012, 01:25:20 am »
It might have been something I was doing but I was definetly rendering the lights last - I want to test with this version now but still getting problems.

I have fixed up your example code to the new naming conversions as follows;

 

#include <LTBL\Light\LightSystem.h>
#include <LTBL\Light\Light_Point.h>

#include <assert.h>


#include <SFML/Graphics.hpp>

int main(int argc, char* args[])
{

        sf::VideoMode vidMode;
        vidMode.width = 800;
        vidMode.height = 600;
        vidMode.bitsPerPixel = 32;
       
        sf::RenderWindow win;
        win.create(vidMode, "Let there be Light - Demo");
        // ---------------------- Background Image ---------------------
        sf::Texture backgroundImage;
        backgroundImage.loadFromFile("data/background.png");

        // Tiling background
        backgroundImage.setRepeated(true);

        sf::Sprite backgroundSprite(backgroundImage);
        backgroundSprite.setTextureRect(sf::IntRect(0, 0, vidMode.width, vidMode.height));

        // --------------------- Light System Setup ---------------------
        ltbl::LightSystem ls(AABB(Vec2f(0.0f, 0.0f), Vec2f(static_cast<float>(vidMode.width), static_cast<float>(vidMode.height))), &win, "data/lightFin.png", "data/shaders/lightAttenuationShader.frag");
        // Create a light
        ls.m_ambientColor = sf::Color(10, 255, 10);

        ltbl::Light_Point* testLight = new ltbl::Light_Point();
        testLight->m_center = Vec2f(200.0f, 200.0f);
        testLight->m_radius = 500.0f;
        testLight->m_size = 30.0f;
        testLight->m_spreadAngle = 2.0f * static_cast<float>(3.14159265);
        testLight->m_softSpreadAngle = 0.0f;
        testLight->CalculateAABB();

        ls.AddLight(testLight);

        sf::Event eventStructure;

        bool quit = false;

        while(!quit)
        {
                while(win.pollEvent(eventStructure))
                if(eventStructure.type == sf::Event::Closed)
        {

        quit = true;
        break;

        }
        sf::Vector2i mousePos = sf::Mouse::getPosition(win);
        // Update light
        //testLight->SetCenter(Vec2f(static_cast<float>(mousePos.x), static_cast<float>(vidMode.height - mousePos.y)));

        win.clear();

        // Draw the background
        win.draw(backgroundSprite);

        // Calculate the lights
        ls.RenderLights();

        // Draw the lights
        ls.RenderLightTexture();

        win.display();
        }

        win.close();
}

 

but no lights draw at all, is it possible you can upload your test sample code to pastebin or something?

Cheers Lolz!!
« Last Edit: May 28, 2012, 10:15:07 am by Laurent »
Trying so very hard to finish at-least one project.

Watch out for the RAII police, they will get you.

www.bantersaurus-games.com

zackhovatter

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #128 on: May 28, 2012, 03:39:04 pm »
With the authors permission, I've created a git repository for this project and made a few changes.

https://github.com/hovatterz/light

- Uses Boost instead of C++0x
- Uses SMFL 2.0
- Uses CMake

Feel free to file issues or submit pull requests.

DJuego

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #129 on: May 28, 2012, 05:16:26 pm »
Thank you very much zackhovatter. I am anxious to be witness of any progress. :-D. I expect to take advantage of them medium-term.  ;D

DJuego

Sorry for My English

Cheers Lolz123!! Our Hero

DJuego

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #130 on: June 01, 2012, 06:31:34 pm »
OS: Windows 7 64bits 8GB RAM NVIDIA GeForce GT 220


zackhovatter... I tried your distribution

 - Visual Studio 2010
 - MinGW SJLJ GCC 4.6.2 - 32bits (official distribution)
 - CMake 2.88
 - SFML(Git) 2012-06-01 (Today)
 - Thor(Git)  2012-06-01 (Today) <- Unrelated.

In CMake I get the warning-for-developer:



and when i build:



It seems a problem with the SFML include path management. I have not knowledge about how CMake works internally.  :(. I am a ignorant.  :-[

DJuego.


Sorry for my English. :(

« Last Edit: June 01, 2012, 08:33:41 pm by DJuego »

Orobu

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #131 on: June 08, 2012, 07:20:21 pm »
I have a question regarding viewport scaling. I'm currently working on a game were you can switch resolution and the viewport is scaling accordingly.

I'm trying to get this working with Let there be light as well but so far I haven't been able to get it to scale correctly if the window and viewport resolution does not match. this is how my viewport looks when the internal reoslution is 1600x900 and the window is 1024x600. How would I go about to make it correctly scale to my viewport?


[attachment deleted by admin]

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #132 on: June 08, 2012, 09:47:47 pm »
At the moment, it assumes the viewport is the same as the screen resolution. I can change that in a future version, but for now, try this:

In the LightSystem::RenderLightTexture() function, there is the following code:

glBegin(GL_QUADS);
                        glTexCoord2i(0, 0); glVertex2f(0.0f, 0.0f);
                        glTexCoord2i(1, 0); glVertex2f(viewSize.x, 0.0f);
                        glTexCoord2i(1, 1); glVertex2f(viewSize.x, viewSize.y);
                        glTexCoord2i(0, 1); glVertex2f(0.0f, viewSize.y);
                glEnd();

                if(m_useBloom)
                {
                        m_bloomTexture.getTexture().bind();

                        glBlendFunc(GL_ONE, GL_ONE);

                        glBegin(GL_QUADS);
                                glTexCoord2i(0, 0); glVertex2f(0.0f, 0.0f);
                                glTexCoord2i(1, 0); glVertex2f(viewSize.x, 0.0f);
                                glTexCoord2i(1, 1); glVertex2f(viewSize.x, viewSize.y);
                                glTexCoord2i(0, 1); glVertex2f(0.0f, viewSize.y);
                        glEnd();
                }

Change it to:

sf::Vector2u viewSizeui(m_pWin->getSize());

glBegin(GL_QUADS);
                        glTexCoord2i(0, 0); glVertex2f(0.0f, 0.0f);
                        glTexCoord2i(1, 0); glVertex2f(viewSizeui.x, 0.0f);
                        glTexCoord2i(1, 1); glVertex2f(viewSizeui.x, viewSizeui.y);
                        glTexCoord2i(0, 1); glVertex2f(0.0f, viewSizeui.y);
                glEnd();

                if(m_useBloom)
                {
                        m_bloomTexture.getTexture().bind();

                        glBlendFunc(GL_ONE, GL_ONE);

                        glBegin(GL_QUADS);
                                glTexCoord2i(0, 0); glVertex2f(0.0f, 0.0f);
                                glTexCoord2i(1, 0); glVertex2f(viewSizeui.x, 0.0f);
                                glTexCoord2i(1, 1); glVertex2f(viewSizeui.x, viewSizeui.y);
                                glTexCoord2i(0, 1); glVertex2f(0.0f, viewSizeui.y);
                        glEnd();
                }


I haven't tested it, but it should work.

Keep in mind that if you want to change internal resolution of the light system, you need to re-created it, since it relies on render textures.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Orobu

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #133 on: June 09, 2012, 12:59:36 am »
thanks for your quick reply!

I tried what you described and it is indeed stretched properly in the window. Only problem is that the lights are not properly scaled, meaning that if I create a light with a radius at 200 it will be the same size no matter the window resolution.

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #134 on: June 11, 2012, 12:27:06 am »
In LightSystem, where it says:

void LightSystem::CameraSetup()
{
        glLoadIdentity();
        glTranslatef(-m_viewAABB.m_lowerBound.x, -m_viewAABB.m_lowerBound.y, 0.0f);
}
 

Try changing it to:

void LightSystem::CameraSetup()
{
        glLoadIdentity();
        glScalef(m_viewAABB.GetDims().x / m_pWin->getSize().x, m_viewAABB.GetDims().y / m_pWin->getSize().y, 1.0f);
        glTranslatef(-m_viewAABB.m_lowerBound.x, -m_viewAABB.m_lowerBound.y, 0.0f);
}
 

Again, I didn't actually try it, but it should work. The next version of the light system will definitely have a scaling system  ;)
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

 

anything