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

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

0 Members and 3 Guests are viewing this topic.

Daffern

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #240 on: September 08, 2013, 01:03:37 am »
Hi, i've been trying to implement this into my game, but i have a problem with it. Has anyone gotten a bug looking like the one in this picture?

I changed the shader.bind() to sf::Shader::bind(shader) and texture.bind() to sf::Texture::bind(texture) as someone posted, but i cant figure this bug out. Help is very much appreciated!

Edit: the below ground he is standing on is not a convexHull, but the one above it is. The light is shining through the left part of it and there is a shading part on the right part of the screen which should not be there.
« Last Edit: September 08, 2013, 01:05:53 am by Daffern »

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #241 on: September 08, 2013, 12:34:53 pm »
Take screen shot of this without lighting and with lighting in debug mode.

Daffern

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #242 on: September 08, 2013, 01:24:16 pm »
These are all in debug mode, the last one without any lighting. I noticed that if i the light gets really close to the hull, it seems to render correctly.

Daffern

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #243 on: September 08, 2013, 03:38:44 pm »
My bad, my bad! The size of my light was set way too high which caused the light to overlap the hull  :P. Thank you very much for the reply anyway!

ThreeDumps

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #244 on: September 09, 2013, 09:50:31 pm »
Well... Author probably don't read this topic anymore but I need help so I will risk

in example code from author side everything goes ok but when I change
testLight->m_radius = 600.0f;
to
testLight->m_radius = 20.0f;
(i need little spot light)
I got "Access violation reading location" when mouse moved outside of render window. Visual shows me xhash code on line 1003 so probably something goes wrong in QuadTree in std::unordered_set.



Daffern

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #245 on: September 09, 2013, 10:24:47 pm »
Yes, i had this problem too. You can fix it by setting the AABB to larger than your screen size(i put mine to 20000x20000) in this code

lightSystem(AABB(Vec2f(-10000.0f, -10000.0f), Vec2f(20000,20000)), &rw, "data/shaders/lightFin.png", "data/shaders/lightAttenuationShader.frag")

ThreeDumps

  • Newbie
  • *
  • Posts: 34
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #246 on: September 09, 2013, 10:30:46 pm »
It wouldn't be overkill for app? I guess that AABB is render area?

Daffern

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #247 on: September 09, 2013, 11:44:02 pm »
AABB is the quadtree limits, and im pretty sure the quadtree works well :)

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #248 on: September 10, 2013, 12:25:06 am »
Better option to avoid access violation is set AABB to 0,0,0,0. And I think QuadTree is broken.

Daffern

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #249 on: September 11, 2013, 12:19:30 am »
I don't know if there is a fix for this, but is there any way to make the shadow fill where it's supposed to fill below the ground rectangle?

Nutomic

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #250 on: September 11, 2013, 07:37:20 pm »
I finally got it working, but even after playing around with Light::m_color and LightSystem::m_ambientColor, colors aren't like I want them:

At the position of the light, anything below it is drawn with a white overlay instead of a transparent one.
Also, I want pitch black if there is no light, instead of gray.

Example pic (single point light at player position):
http://i.imgur.com/oEzrgh1.png
        mLight->m_radius = 250.0f;
        mLight->m_size = 50.0f;
        mLight->m_softSpreadAngle = 0.0f;
        mLight->m_spreadAngle = 2.0f * M_PI;
        mLight->m_intensity = 1.5f;
        mLight->m_bleed = 0;

Edit: Or, can you give some example settings that you used which give good, realistic results?
« Last Edit: September 11, 2013, 07:44:08 pm by Nutomic »

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #251 on: September 11, 2013, 08:05:53 pm »
Edit: Or, can you give some example settings that you used which give good, realistic results?
http://warsztat.gd/screens/2522b9f8e41887617078274713c0d4c2.png
like that?

I don't know if there is a fix for this, but is there any way to make the shadow fill where it's supposed to fill below the ground rectangle?

Make black texture ? What do you want at all?

Nutomic

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #252 on: September 11, 2013, 08:48:42 pm »
Edit: Or, can you give some example settings that you used which give good, realistic results?
http://warsztat.gd/screens/2522b9f8e41887617078274713c0d4c2.png
like that?

Minus the halo (which is probably m_bleed?), this would be perfect!

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #253 on: September 11, 2013, 08:55:18 pm »
Yep it's with m_bleed. Here you are.
        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 modified blend modes. Minus of this is broken penumbra if you would change transparency.

Nutomic

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #254 on: September 11, 2013, 10:23:49 pm »
This is perfect, thanks  :D

Another question, why does it sometimes take a few seconds (or more) until fins are loaded on a light? (There are no errors or warnings, and the file path is given correctly).

Edit: Maybe it has to do with me starting outside of a Quadtree (or maybe I am just interpreting DebugDraw wrong).
« Last Edit: September 11, 2013, 10:30:13 pm by Nutomic »