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

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

0 Members and 5 Guests are viewing this topic.

fatum

  • Newbie
  • *
  • Posts: 47
    • MSN Messenger - bowsers7@hotmail.com
    • AOL Instant Messenger - therealblah569
    • View Profile
    • http://boards.psynetfm.com
Re: SFML Light System - Let There Be Light
« Reply #225 on: June 13, 2013, 06:33:35 am »
Currently I'm trying to use LTBL in my project like this:

Code: [Select]
private:
ltbl::LightSystem *ls;
ltbl::Light_Point *testLight;

Code: [Select]
World::World(sf::RenderWindow &rwin)
{
ls = new ltbl::LightSystem(AABB(Vec2f(0.0f, 0.0f), Vec2f(static_cast<float>(screenWidth), static_cast<float>(screenHeight))), &rwin, "res/images/lightFin.png", "res/shaders/lightAttenuationShader.frag");

testLight = new ltbl::Light_Point();
testLight->SetCenter(Vec2f(400.0f, 400.0f));
testLight->SetRadius(500.05f);
testLight->m_size = 30.f;
testLight->m_spreadAngle = 2.f * static_cast<float>(M_PI);
testLight->m_softSpreadAngle = 0.f;
testLight->CalculateAABB();

ls->AddLight(testLight);
}

void World::draw(sf::RenderWindow &rwin)
{
rwin.setView(vw_main);
//Drawing logic (background, player, etc)
ls->RenderLights();
ls->RenderLightTexture();
}

However, there haven't been any changes to my scene after adding all of the necessary functions.  How could I further troubleshoot this?  Thanks for any help!

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #226 on: July 03, 2013, 07:54:33 pm »
Hi, guys. I have to edit blend functions in LTBL to made more realistic darkness.  I had problems with white spot so I changed two lines in RenderLightTexture. In Game



Function

Quote
void LightSystem::RenderLightTexture()
   {
      Vec2f viewSize(m_viewAABB.GetDims());

      // Translate by negative camera coordinates. glLoadIdentity will not work, probably
      // because SFML stores view transformations in the projection matrix
      glTranslatef(m_viewAABB.GetLowerBound().x, m_viewAABB.GetLowerBound().y, 0.0f);

      m_compositionTexture.getTexture().bind(&m_compositionTexture.getTexture());

      // Set up color function to multiply the existing color with the render texture color
      //glBlendFunc(GL_DST_ALPHA, GL_ZERO); // Seperate allows you to set color and alpha functions seperately
        glBlendFunc(GL_DST_COLOR, 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();

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

         //glBlendFunc(GL_ONE, GL_ONE);
            glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
         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();
      }

      // Reset blend function
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

      m_pWin->resetGLStates();
   }

I hope I help someone.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML Light System - Let There Be Light
« Reply #227 on: July 03, 2013, 08:42:04 pm »

That looks nice! Do you have some more specifics? :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #228 on: July 03, 2013, 10:06:44 pm »
More specifics about project? It's screen from my game "Zombienation". I write the game for WSoC Contest. It will be 2d top down shooter like old Dead Frontier, but it will be single player game. All graphics are placeholders. More screenshoots here -> http://warsztat.gd/projects/Zombienation

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #229 on: July 05, 2013, 03:47:08 pm »
Another modification that I made is load shader from memory. QT 5 doesn't allow to load id from file (don"t know why)

jamesl22

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #230 on: August 08, 2013, 10:56:47 am »
Hi,

I am trying to implement LTBL into my game engine but I am struggling. I cannot get lights to render in the scene. Here is my code:

Engine::LightSystem::LightSystem(sf::RenderWindow &Window)
{
    ls = new ltbl::LightSystem(AABB(Vec2f(0.0f, 0.0f), Vec2f(16384.0f, 16384.0f)), &Window, "data/lightFin.png", "data/shaders/lightAttenuationShader.frag");

    Light = new ltbl::Light_Point();
    Light->m_center = Vec2f(200.0f, 1000.0f);
    Light->m_radius = 64.0f;
    Light->m_size = 30.0f;
    Light->m_intensity = 1.0f;
    Light->m_spreadAngle = 2.0f * 3.14159f;
    Light->m_softSpreadAngle = 0.0f;
    Light->CalculateAABB();
    ls->AddLight(Light);
}

void Engine::LightSystem::RenderLights(sf::View &View)
{
    ls->SetView(View);
    // Calculate the lights
    ls->RenderLights();
    // Draw the lights
    ls->RenderLightTexture();
}
 

I have attached an image of the problem. You will notice that LTBL is rendering the dark texture over the top.

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #231 on: August 11, 2013, 12:38:01 pm »
Set light intensity to 2.f. for better effects you could modify two lines in blending mode .

Nutomic

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #232 on: September 04, 2013, 11:34:27 pm »
I tried to integrate the ltbl version from https://github.com/hovatterz/light into my project, but I'm unable to really get it working.

No matter what I do, the area where shadows are is always the same size, and always in the same position (see attachment).

Does anyone know what I have to do to resize/move this area?

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #233 on: September 05, 2013, 05:59:01 pm »
I think your code look like that
app.draw(smth);
lightSystem.renderLights();
lightSystem.renderLightTexture();
but it have to look like this
app.setView(view);
app.draw(smth);
app.setView(app.getDefaultView());
lightSystem.setView(app.getdefaultView());
lightSystem.renderLights();
lightSystem.renderLightTexture();

Nutomic

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #234 on: September 05, 2013, 11:29:17 pm »
I think your code look like that
app.draw(smth);
lightSystem.renderLights();
lightSystem.renderLightTexture();
but it have to look like this
app.setView(view);
app.draw(smth);
app.setView(app.getDefaultView());
lightSystem.setView(app.getdefaultView());
lightSystem.renderLights();
lightSystem.renderLightTexture();

That's exactly how my current code looks (I basically copied the example into my project), but doing this only makes the light texture that is shown completely black (the previous code shows light correctly).

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #235 on: September 05, 2013, 11:53:49 pm »
Show me your code.

Nutomic

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #236 on: September 06, 2013, 03:29:58 pm »
Initialization:
        ltbl::LightSystem mLightSystem(qdt::AABB(Vec2f(0, 0), Vec2f(800, 600)), &mWindow);
        // Create a light
        ltbl::Light* mLight = new ltbl::Light();
        mLight->center = Vec2f(200.0f, 200.0f);
        mLight->radius = 500.0f;
        mLight->size = 30.0f;
        mLight->softSpreadAngle = 0.0f;
        mLight->CalculateAABB();

        mLightSystem.AddLight(mLight);

        // Create a hull by loading it from a file
        ltbl::ConvexHull* testHull = new ltbl::ConvexHull();

        testHull->LoadShape("data/testShape.txt");

        // Pre-calculate certain aspects
        testHull->CalculateNormals();
        testHull->GenerateAABB();

        testHull->SetWorldCenter(Vec2f(0, 0));

        mLightSystem.AddConvexHull(testHull);

        // Create a hull by loading it from a file
        ltbl::ConvexHull* testHull2 = new ltbl::ConvexHull();

        testHull2->LoadShape("data/testShape.txt");

        // Pre-calculate certain aspects
        testHull2->CalculateNormals();
        testHull2->GenerateAABB();

        testHull2->SetWorldCenter(Vec2f(300.0f, 300.0f));

        mLightSystem.AddConvexHull(testHull2);

Rendering:
        mWindow.clear();

        mWorldView.setCenter(mPlayer->getPosition());

        // Render world and dynamic stuff.
        mWindow.setView(mWorldView);
        mWindow.draw(mWorld);

        // Update light
        mLight->center.x = mPlayer->getPosition().x;
        mLight->center.y = mPlayer->getPosition().y;
        mLight->UpdateTreeStatus();

        mWindow.setView(mWindow.getDefaultView());
        mLightSystem.view = mWindow.getDefaultView();
         mLightSystem.RenderLights();
        mLightSystem.RenderLightTexture();

        // Render GUI.
        mWindow.drawGUI();
        mWindow.draw(mCrosshair);

        mWindow.display();

As I said, I just took the example and copied it in there.

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #237 on: September 06, 2013, 10:02:28 pm »
I saw different sample.

Quote
mLightSystem.view = mWindow.getDefaultView();
to
Quote
mLightSystem.setView(mWindow.getDefaultView());

should solve problem You hardly set up view. setView function make some more than setting up view

Quote
   void LightSystem::SetView(const sf::View &view)
   {
      sf::Vector2f viewSize(view.getSize());
      m_viewAABB.SetDims(Vec2f(viewSize.x, viewSize.y));
      sf::Vector2f viewCenter(view.getCenter());

      // Flipped
      m_viewAABB.SetCenter(Vec2f(viewCenter.x, viewCenter.y));
   }

Nutomic

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #238 on: September 06, 2013, 11:55:56 pm »
The thing is, the github version does not have setView, only a public member view.

I would try the version in the op, but gcc doesn't like the absolute include paths.

So I guess I'll try and reach the dev of this version and see if he can help.

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #239 on: September 07, 2013, 04:38:05 pm »
Ah I see now. You're using older version. http://sourceforge.net/projects/letthebelight/ here you have 1.5.1 that I'm using in Zombination

 

anything