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

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

0 Members and 2 Guests are viewing this topic.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #75 on: March 26, 2012, 03:23:14 am »
I can't believe this lighting solution was made without considering the situation where the render area is not the screen.. It simply does not work : (

Hey, lolz, can you fix this?

Since you rely on fixed dimensions for the quad tree, we should be able to place the quad tree anywhere like a drawable..

I would create a lighting system for example in (400,400) with size (1000,1000). I would put lights somewhere within (400-1400, 400-1400) so they are within the quad tree and render optimally.

Then, what should happen when I try to render is that the lighting texture is rendered exactly to fit the region I chose before.. This is not happening at all, Help? Thanks :)

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 #76 on: March 26, 2012, 05:12:59 am »
Also having this problem, it was meant to be an addition made during this release with the 'SetView' function, however, it seems not to work. The only area that is lit is the area in the original view, if I scroll the view down, anything in the new area is not lit and ambient light does not effect it either.

TLDR; Lighting does not work on areas not in original viewport; SetView does not work.

If anyone can find a fix for this I will love them forever;

Thanks,

Matthew
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 #77 on: March 26, 2012, 11:18:11 pm »
Oh, I see what you mean. Wow, I can't believe I missed that, sorry about that. A fix is under way!

@DevilWithin you can set the quad tree root region in the light system constructor. The AABB you pass it is the root region AABB.
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 #78 on: March 27, 2012, 12:45:51 am »
In the sample you pass the AABB as (0,0) (screenWidth, screenHeight)..

I have different quads around the world, with arbitrary size and position, i want each of them to display a tilemap and a lighting system on top with a light on its center for testing.

That doesn't work at all, tell me please how it would be done, both in AABB and view. Thanks :)

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #79 on: March 27, 2012, 02:44:02 am »
Alright, version 1.3.3 is up, I hope the views work properly now.
I also added some new features. The fins are now smoother, and there is a parameter in ConvexHull that allows you to specify if you want the light to render over the hull or not, so that objects under the convex hulls are visible. The demo has this setting enabled, so you can see it in action there.

@DevilWithin The darkness of the light system stretches indefinitely, in the new working version (not limited to the quad tree region). Changing the quad tree region only changes performance, nothing else. You mentioned multiple quads with light systems in each, are you trying to draw multiple, separate light systems at once? If so, I can add support for that, it is not a big change.

@jmcmorris Sorry, I missed you post! The game the light system originally came from, Gore Factor, also uses a tile map. Instead of generating hulls for every tile, I made it stretch the hull across multiple tiles, so there are less hulls in total (faster). The easy way of doing this is to make it attempt to stretch a hull horizontally or vertically as long as a there are consecutive tiles. If the map is modified, you would simply have to regenerate the hulls for the rows or columns (depending on your setup) of the map that contain modified tiles.
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

jmcmorris

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #80 on: March 27, 2012, 02:49:43 am »
Thanks for fixing this so quickly. I'll test this out later this evening. Also thanks for responding to my question. I was thinking of doing something like that. I had actually done a similar thing with box2d and it's chain shape for my tile map in the past.

Once I get something worth showing, I'll post what I am using your lighting system for. :)

Thanks again!

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #81 on: March 27, 2012, 03:13:44 am »
You mentioned multiple quads with light systems in each, are you trying to draw multiple, separate light systems at once? If so, I can add support for that, it is not a big change.

That is exactly what i am doing :) If everything is properly encapsulated, that should work automatic, if it works for one case, it should work for all..

I want to have rectangles, with any proportions, which act as boundaries for the light system quad tree. Lights may go out of the rectangle, but will not lose the normal proportions, whatever the rectangle is.. This is because i have arbitrary sized streaming regions. They are pretty big, so i need to make a clear separation, and fast enabling/disabling of a region.

Plus, I don't get it about the views, what is written in the manual. The view should be synced in lighting and in world... This is exactly what i dont want, why would the light follow the view as some kind of ui? that doesn't make sense to me, if the world view moves, it simply sees another part of the lighting system, what if i have my regions with different systems, all in screen at once with a large zoom out?
« Last Edit: March 27, 2012, 03:24:32 am by DevilWithin »

DJuego

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #82 on: March 28, 2012, 07:13:30 pm »
It seems fantastic!   :o Thank you lolz123!

However I prefer to wait to build it with the new SFML naming convention. ??? I am anxious!  :P

DJuego

jmcmorris

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #83 on: March 29, 2012, 11:47:27 am »
It is going much better, but I have found two bugs regarding the convex hulls.

First is that the shadow fins will show up sometimes when they shouldn't. This can be seen with a rectangle convex hull. To reproduce this change the testShape.txt file to this...
Code: [Select]
-25 -50
-25 50
25 50
25 -50

And here is a screenshot of it - http://grab.by/czYM (that is suppose to be a box hull)

The other bug deals with the same setup. Regardless if you set ConvexHull::renderLightOverHull to true or false it still fills in the hull with the ambient light. It does work with the initial testShape.txt but not this modified one.

EDIT:

I have a question about hulls. How difficult would it be to make a hull transparency? An example would be if a hull is 50% transparency then it only blocks 50% of the light. Right now it is all or nothing.

I could see this adding a decent amount of complexity though. Since this would mean that a light source could be broken down not only by distance but also how many objects it has passed through.
« Last Edit: March 30, 2012, 05:50:36 am by jmcmorris »

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #84 on: March 30, 2012, 10:19:40 pm »
What you have encountered is not a bug, you just specified the vertices in the wrong order. They have to be specified in a counter-clockwise order, or else the normals (and therefore the shadow boundaries) will not generate properly.

I'll see what I can do to get some hull transparency rendering going  ;)

EDIT: Please note that LTBL coordinates do not have the Y axis flipped like in SFML
« Last Edit: March 30, 2012, 10:25:03 pm by lolz123 »
Have you heard about the new Cray super computer?  It’s so fast, it executes an infinite loop in 6 seconds.

jmcmorris

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #85 on: March 30, 2012, 10:31:16 pm »
That's not counter-clockwise? It starts at the top left, goes to bottom left, then bottom right and then bottom top. What is counter-clockwise according to ltbl? I'll play with it once I get home.

I think hull transparency could be useful in several scenarios. The one I was planning on using it for is having the ambient light be nearly pitch black and then have the character cast a light shadow so that way it doesn't obscure the player's vision.

EDIT:

Ah, I see. so I actually want something like this... right?
Code: [Select]
-25 50
-25 -50
25 -50
25 50
« Last Edit: March 31, 2012, 12:35:01 am by jmcmorris »

lolz123

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #86 on: March 31, 2012, 12:45:20 am »
Those coordinates will work fine. I am working on the hull transparency, shouldn't be a big modification. All it needs to do is render the shadows a bit lighter.
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 #87 on: March 31, 2012, 01:35:14 am »
EDIT: Please note that LTBL coordinates do not have the Y axis flipped like in SFML

Can you elaborate a little on that? Im a little confused here. So you say there is already a way to do what i need?

jmcmorris

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #88 on: March 31, 2012, 02:11:48 am »
@DevilWithin What he means by that is that the y coordinates starts at the bottom of the screen instead of the top. Which is why you need to do something along the lines of...
Code: [Select]
light.SetCenter(ltbl::Vec2(position.x, window.Height() - position.y))
I didn't realize that this is the case for the vectors as well - I should have though. :)

A side note, I'm actually thinking of modifying the ltbl code a little to make it so that it will automatically flip it for me because having to do that all of the time is not too friendly.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #89 on: March 31, 2012, 02:34:54 am »
That is something kinda important to have missed, I will try around with that, hoping it solves my issues :)