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

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

0 Members and 1 Guest are viewing this topic.

Beernutts

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #150 on: August 03, 2012, 05:31:28 am »
Hi Lolz123,

Just wanted to let you know I had to modify v1.5 to get ti to run on my system properly.

I'm using Code::Blocks, Mingw 4.6 on Win7.  Here's the what happens:

After moving around a bit, I'm constantly calling Light_Point::SetCenter(), and eventually, in QuadTreeOccupant::TreeUpdate(), it calls m_pQuadTreeNode->Update(this);

However, it seems in QuadTreeNode::Update(), m_pQuadTree == NULL, so it crashes at the calls m_pQuadTree->m_outsideRoot.insert(pOc);

So, to fix this, I added this check in QuadTreeOccupant::TreeUpdate() (see past else)
        void QuadTreeOccupant::TreeUpdate()
        {
                if(m_pQuadTree == NULL)
                        return;

                if(m_pQuadTreeNode == NULL)
                {
                        // If fits in the root now, add it
                        QuadTreeNode* pRootNode = m_pQuadTree->m_pRootNode.get();

                        if(pRootNode->m_region.Contains(m_aabb))
                        {
                                // Remove from outside root and add to tree
                                m_pQuadTree->m_outsideRoot.erase(this);

                                pRootNode->Add(this);
                        }
                }
                else
                {
                    if (m_pQuadTreeNode->GetTree() == NULL)
                    {
                        m_pQuadTreeNode->m_pQuadTree = m_pQuadTree;
                    }
                    m_pQuadTreeNode->Update(this);
                }

        }
 

There's probably a more efficient way to do this, but it's what I did to get it working.

Thanks!

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #151 on: August 03, 2012, 12:24:41 pm »
Sorry for the late response!

@DJuego: You can modify the light system to act as fog of war, you just need to change the blending equation in LightSystem::Render() as well as the ambient color. I don't think I will make a general shader effects library. Writing things like blur shaders is not very hard, a quick google search will give you the code to do it.

@DevilWithin: I don't really understand what you want to do. The shadow calculation cannot be separated from rendering, if that is what you mean. You cannot have rendering occur without CPU driven logic in between, since you need to switch FBO's all the time which makes it hard to render batches of polygons.

@Beernutts: It is probably unrelated, but I found a big bug in the QuadTreeNode::Remove() function. It can actually infinitely loop, since I forgot to advance the parent node pointer  :P. To fix it, change QuadTreeNode::Remove() to:

void QuadTreeNode::Remove(QuadTreeOccupant* pOc)
        {
                assert(!m_pOccupants.empty());

                // Remove from node
                m_pOccupants.erase(pOc);

                // Propogate upwards, merging if there are enough occupants in the node
                QuadTreeNode* pNode = this;

                while(pNode != NULL)
                {
                        pNode->m_numOccupantsBelow--;

                        if(pNode->m_numOccupantsBelow >= minNumOccupants)
                        {
                                pNode->Merge();

                                break;
                        }

                        pNode = pNode->m_pParent;
                }
        }
 

I also uploaded a new version with this fix in it (1.5.1).

The fix you implemented will just hide any quad tree reshaping issues, so it is only a temporary solution.

I am working on a new 2D light system that uses more modern OpenGL (no more glBegin/glEnd stuff) and is completely independent from SFML (OpenGL/GLEW only). So you can also use it with GLUT, SDL, or whatever you prefer. It will use deferred shading for normal mapping. I may still update this one as well though.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Beernutts

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #152 on: August 03, 2012, 01:57:58 pm »
Hi Lolz123,

Thanks for the relpy:
Quote
The fix you implemented will just hide any quad tree reshaping issues, so it is only a temporary solution.

Well, that's not good.  Any idea why, in QuadTreeNode::Update(), m_pQuadTree is NULL, which causes a crash (much worse that hiding quadtree reshaping issues :)

Either way, I'll keep an eye out for your new library.  I'm not dependent on the SFML parts of the code, so I should be fine using the new one.

Thanks!

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Re: SFML Light System - Let There Be Light
« Reply #153 on: August 03, 2012, 01:58:26 pm »
I am working on a new 2D light system that uses more modern OpenGL (no more glBegin/glEnd stuff) and is completely independent from SFML (OpenGL/GLEW only). So you can also use it with GLUT, SDL, or whatever you prefer. It will use deferred shading for normal mapping. I may still update this one as well though.

I wanted to do the same for my future games. I would love to contribute, but my experience in OpenGL is quite inexistent. You could host it at Github :P There are lots of us coding there.

Ruckamongus

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #154 on: August 03, 2012, 07:17:10 pm »
Hello everybody, I'm having some issues getting this to work. I thought maybe I wasn't setting up the world or the shapes properly so I compiled the example code. I made absolutely no modifications to it at all, and it compiles and runs, but this is what I see:

http://postimage.org/image/hh9kokr75/


This is the case with 1.5 and 1.5.1. I'm using GCC 4.7 and the latest SFML source. Any help would really be appreciated. :)

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #155 on: August 03, 2012, 07:56:04 pm »
Oh, I accidentally set the transparency of the hull in the example to 0. Remove the line that does that, and it should work. I'll update the example.

Transparency doesn't quite work yet, the shadow fins don't blend properly.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #156 on: August 04, 2012, 12:44:17 am »
Okay, the new lighting system idea sounds perfect!

Can you leave a little room for extending? I would want GL ES rendering as well, even if i have to implement it :)

Verra

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #157 on: August 19, 2012, 11:32:32 pm »
so first off pretty great library dude, i'm going to be doing a lot of stuff with it and modifying it.  :) second I did have a lot of trouble with your 1.5.1 release in EclipseCDT - MinGW - gcc 4.7 a lot of errors were being thrown. So my friend and I took about 7 hours to fix it all :( so now it works pretty well with everything I've got. I'm going to be building an archive file of it soon so you don't have to stick the source in to your project.

Now for the fun part this is the test project I was using. It combines box2d and the ltbl library similar to how you used it in your gore factor remake. I had a few questions about optimization. I've noticed that it has some issues with objects on the same plane, it likes to render shadows on top of things it shouldn't I don't know if it's just because it doesn't take into account other blocks when it renders each one, but is there a way to stop shadows from going through other blocks. Second how would I turn down the intensity of the shadow I noticed in your gore factor game that the shadows were very soft and not quite as hard as the ones in 1.5.1 how would I replicate that. And lastly :) what's the easiest way to optimize ltbl with box2d so that when you render the shadow it actually keeps up with the physics shape. I've noticed that when I throw a box instead of just being slow to render things the box2d will render faster than the shadow does even though they happen sequentially before I display them on the screen. i.e the shadow will be in a previous position of the box.

Just to show what is happening in my test project here are some screen shots.



posva

  • Full Member
  • ***
  • Posts: 118
  • Feed me pls
    • View Profile
    • Posva Dev Blog
Re: SFML Light System - Let There Be Light
« Reply #158 on: August 21, 2012, 01:33:43 pm »
Is there anyway to get this working without C++11 ? I'm trying to use boost to replace unordered_set but unique_ptr does not exists and I was wondering if an auto_ptr would be enough. Anyway it would be great to have this also working for non C++11 compilers. I also noticed some errors at compilation like determining a class a friend of himself.
Thanks, keep up the good work!

Edit: I tried what I said and I managed to correctly launch the example you provide. But I still don't know if an auto_ptr is enough for you or not. I can upload what I modified if you want. I really like your light and being able to use it would be great! :D

Edit: There are a lot of warning I'm trying to correct, also not used variables like m_render in convexhull and not initialized variables on constructors. Not initialized variables may give unexpected behaviours

Edit: I found this portion of code weird:
void Light_Point::RenderLightSolidPortion()
    {
        float renderIntensity = m_intensity;

        // Clamp the render intensity
        if(renderIntensity > 1.0f)
            renderIntensity = 1.0f;

        assert(renderIntensity >= 0.0f);

        float r = m_color.r * m_intensity;
        float g = m_color.g * m_intensity;
        float b = m_color.b * m_intensity;

        glBegin(GL_TRIANGLE_FAN);

        glVertex2f(m_center.x, m_center.y);
     
        // Set the edge color for rest of shape
        int numSubdivisions = static_cast<int>(m_spreadAngle / m_lightSubdivisionSize);
        float startAngle = m_directionAngle - m_spreadAngle / 2.0f;
     
        for(int currentSubDivision = 0; currentSubDivision <= numSubdivisions; currentSubDivision++)
        {
            float angle = startAngle + currentSubDivision * m_lightSubdivisionSize;
            glVertex2f(m_radius * cosf(angle) + m_center.x, m_radius * sinf(angle) + m_center.y);  
        }

        glEnd();
    }

You don't use the color created, also why calculating renderIntensity and then use m_itensity? Is that what you meant to write? :
...
Color3f(m_color.r * renderIntensity, m_color.g * renderIntensity, m_color.b * renderIntensity).GL_Set();
glBegin(....
« Last Edit: August 21, 2012, 02:47:25 pm by posva »

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #159 on: August 22, 2012, 03:39:27 am »
@Verrazano

Quote
it likes to render shadows on top of things it shouldn't
At the moment, there are only 2 settings for how the shadows are drawn over the hulls. One with hull self-shadowing and one without. There is not yet a setting to leave hulls completely unaffected by shadows. I am working on a more generalized OpenGL 2D lighting system, I'll include this feature in there  ;).

Quote
Second how would I turn down the intensity of the shadow I noticed in your gore factor game that the shadows were very soft and not quite as hard as the ones in 1.5.1 how would I replicate that
The intensity of the shadow cannot be adjusted at the moment.  That would require hull transparency, but that isn't really the effect you want in your case anyways. Actually, hull transparency is available in the library, but it doesn't quite work with the soft portion of the shadows yet.

In Gore Factor, I just raised the ambient light level.

Quote
what's the easiest way to optimize ltbl with box2d so that when you render the shadow it actually keeps up with the physics shape
The easiest way to make LTBL work with Box2D is to construct a hull from the transformed points of a b2PolygonShape, and update this hull whenever the shape's body is active. The problem you are having with the shadow being a frame behind is caused by rendering the lights before the physics are performed in a frame.

@posva

Quote
But I still don't know if an auto_ptr is enough for you or not
You can use auto_ptr instead of unique_ptr. I didn't put any unique_ptrs into STL containers, so it doesn't matter (auto_ptr cannot be copied).

Quote
I also noticed some errors at compilation like determining a class a friend of himself
I google'd this, it only seems to happen with gcc. But, it seems like you can just leave it out with gcc, since the class is implicitly a friend of itself.

Quote
I found this portion of code weird
The color thing is indeed a mistake, thanks for finding this! I didn't notice it, since the color values end up being clamped to a [0, 1] range anyways when rendering. So, you can just remove everything up until the glBegin statement, it doesn't do anything.

Quote
There are a lot of warning I'm trying to correct, also not used variables like m_render in convexhull and not initialized variables on constructors. Not initialized variables may give unexpected behaviours
m_render is indeed not used, thanks for finding this. However, you don't need to initialize variables in a constructor if that constructor value is never used for anything. They are set later on, so there shouldn't be any unexpected behavior.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

DJuego

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #160 on: September 24, 2012, 04:57:55 pm »
Quote from: lolz123
I am working on a more generalized OpenGL 2D lighting system

Any update about this, Lolz? You have us in total suspense.  ;D

DJuego



danikaze

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #161 on: December 02, 2012, 01:25:42 am »
Sorry for asking this but...
how it's installed?

I tried to include <LightSystem.h> as the manual says but I get lots of errors (like inexistent Vec2f class).

I'm using codeblocks and I added the LTBL directory to the Build Options -> Search Directories -> Compiler.

Am I doing something wrong? :S

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #162 on: December 03, 2012, 01:55:51 am »
Unfortunately, I am not very familiar with Code::Blocks. Try adding it under Build Options -> Search Directories -> Linker.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

Predator106

  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #163 on: December 03, 2012, 01:56:51 am »
are there any plans/progress on that opengl lighting system? i'd really, really like something like that.

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #164 on: December 03, 2012, 02:39:32 am »
It is still being developed, slowly, as a side project. I can speed up the development though if you are interested in using it :). I uploaded the project to Github, so you can view progress there.

https://github.com/222464/GLLight2D
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

 

anything