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

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

0 Members and 9 Guests are viewing this topic.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #315 on: April 27, 2014, 09:25:25 pm »
If anyone else has this problem a temporary solution that works well is to put a convex hull with
"m_renderLightOverHull = false;"
in the top left corner. That will solve the problem. It worked for me with a 6x6 sized square, but you can probably make it even smaller.

Theshooter7

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #316 on: May 03, 2014, 11:01:03 am »
Hi, I've been trying to get LTBL to work with my Tile-based 2D SFML game.

I made the necessary changes to 1.5.1 to get it to work with the latest SFML (changing to sf::Texture::bind() etc). I finally got it working except the shadows always come up in the wrong place. What gives?

I'm using the tmx (Tiled) map format for my levels, and constructing the hulls based on collision objects read in from the loader. I've checked the debug drawing and the hulls are all in their correct places and the light is where it should be but the shadows are simply drawing for things that don't exist.

Anyone encounter this issue and know how to fix it?

[EDIT] Ok so I figured out the issue, the Hull verticies are relative to 0, 0 so I had to basically take the hull box being read in by loader and subtract it's width/height from the vertex position to get the correct location for the hull's placement.

However I've found that the hulls are only relative to your viewport/window. For instance, I have a 1024 x 768 Tile map (of which tiles are 32x32 so that's 32x24 tiles). When I try to place the Hull using SetWorldCenter, it comes up with the wrong y coordinate whenever I just get the center location from the loader. But if I use the Window's height and subtract the Hull's y from it, then it is placed properly. So the question is: how would I handle this with varying map sizes since it seems the hulls are all relative to the window?
« Last Edit: May 03, 2014, 11:44:18 pm by Theshooter7 »

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #317 on: May 04, 2014, 07:45:55 pm »
So the question is: how would I handle this with varying map sizes since it seems the hulls are all relative to the window?
Not sure what you mean here. You just need to do
viewSize.y - worldposition.y
and the size of the map doesn't matter.

Theshooter7

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #318 on: May 05, 2014, 02:26:39 am »
So the question is: how would I handle this with varying map sizes since it seems the hulls are all relative to the window?
Not sure what you mean here. You just need to do
viewSize.y - worldposition.y
and the size of the map doesn't matter.
That's the exact bit of code I used to fix it. :P But there is one last problem: it seems like I have to match the size of the sf::View to the size of my window, otherwise I get problems:
How it looks with sf::View set to 0, 0, 800, 600 and Window at 1024x768:
http://i.imgur.com/ogkRiU5.png
How it should look (sf::View size and Window size are the same, in this picture it's 800x600)
http://i.imgur.com/61juo4M.png

I want to make the sf::View a fixed size so that the game world looks the same no matter what your resolution is. But the light system seems to dislike that or something. Any ideas?

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #319 on: May 05, 2014, 03:51:48 am »
Ok the fix for this (i just tried) is to create another view with the screen resolution instead of using the normal one and then use screenSize instead of viewSize for the
screenSize.y - worldposition.y
part like this:
sf::View lightView;
lightView.setSize(screenSize.x, screenSize.y);
lightView.setCenter(View1.getCenter().x, View1.getCenter().y);

screenSize.y - worldposition.y

ls.SetView(lightView);
« Last Edit: May 05, 2014, 04:02:57 am by Voroz »

Theshooter7

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #320 on: May 05, 2014, 04:09:45 am »
That works perfectly! Thank you so much. ;D

[EDIT] another small question if you happen to know anything about it, but the light system affects everything that is drawn (unless you draw it after calling RenderLights()/RenderLightTexture()). I wanted to be able to draw a backdrop (such as a sky) with it's own brightness/color settings that would ignore the light system. However, since the backdrop has to be drawn first and then everything over it, and finally the lights are rendered, the sky is affected as well (and usually takes on the light system's ambient color setting).

I don't know any way around this. I thought maybe two render textures might work if I composite them after all is said and done (with the lights being drawn on the non-backdrop render texture), but realized the light system uses raw OpenGL and doesn't interact with SFML's drawing calls, making this impossible.
« Last Edit: May 05, 2014, 04:24:55 am by Theshooter7 »

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #321 on: May 05, 2014, 04:50:27 am »
I don't know if this is what you're looking for but maybe move the lightview down a bit.
lightView.setCenter(View1.getCenter().x, View1.getCenter().y+300);

Edit: I realize this doesn't give you 2 different light systems but it's 5 am here so i can't experiment with that atm, but i assume you could just create one more lightsystem and name it something else, and instead of moving it down like i just did, you could move most of it up outside the screen and have only the 300 pixels inside.
« Last Edit: May 05, 2014, 04:57:00 am by Voroz »

Theshooter7

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #322 on: May 05, 2014, 04:59:26 am »
Edit: I realize this doesn't give you 2 different light systems but it's 5 am here so i can't experiment with that atm, but i assume you could just create one more lightsystem and name it something else, and instead of moving it down like i just did, you could move most of it up outside the screen and have only the 300 pixels inside.
Huh, that's actually a clever idea. I'll give it a try soon. Thanks for your help. :)

[EDIT] Creating a secondary light system gave me some control over the sky brightness, but it looks like it can only go as bright as the main light system's ambient color.

To explain further, I mean a sky or background like a texture that is stretched to fit the whole screen, with things drawn over it.
« Last Edit: May 05, 2014, 05:21:13 am by Theshooter7 »

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #323 on: May 05, 2014, 02:57:20 pm »
So you want two equally big lightsystems stacked on eachother? Well i'm no expert but it's very hard to get any help about this light system since the developer seems to have abandoned this project.

I have never tried this and don't know of the issues with it but ofourse the front layer can't become brighter than the back one if that's your issue. Maybe post some screenshots again of your new issue so i understand better, but i don't think i will be able to help you, especially if it requires changes of the lightsystem itself, since i don't have a big understanding of how this lightsystem works.

Theshooter7

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #324 on: May 05, 2014, 08:56:33 pm »
So you want two equally big lightsystems stacked on eachother? Well i'm no expert but it's very hard to get any help about this light system since the developer seems to have abandoned this project.

I have never tried this and don't know of the issues with it but ofourse the front layer can't become brighter than the back one if that's your issue. Maybe post some screenshots again of your new issue so i understand better, but i don't think i will be able to help you, especially if it requires changes of the lightsystem itself, since i don't have a big understanding of how this lightsystem works.
This is what I was aiming for (using photoshop since I can't get it to work for real)
http://i.imgur.com/1uFZAMf.png
(Note the contrast of the sky texture against how dark the tiles are)

I understand if this is outside of the scope of just a simple implementation detail. I do appreciate all your help so far and I can see that this is basically abandoned.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: SFML Light System - Let There Be Light
« Reply #325 on: May 05, 2014, 09:04:12 pm »
Not having used LTBL myself, but you could probably draw all your tiles [including the lighting] onto a render texture. Then draw that render texture on top of your sky background in the window.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #326 on: May 05, 2014, 09:20:25 pm »
If i understand correctly i think i would draw the background stuff first, then the background lightsystem and then foreground boxes etc and the lightsystem and set
m_renderLightOverHull = false;
if you want it like the image.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #327 on: May 05, 2014, 10:05:53 pm »
I have a problem myself btw. I'm trying to change the brightness of the shadows.

This does nothing to the black color which i have for shadows, but the lights works:
ls.m_ambientColor = sf::Color(50,50,50);
ls.m_useBloom = false;

If i change bloom to true then i can change the shadows color but then the lights wont work anymore.

edit: To be clear my game is completely black, i want to be able to make it less dark :).

edit2: Managed to make it work with bloom on now by setting intensity to over 1, but bloom doesn't work well at all so i need it off.
« Last Edit: May 05, 2014, 10:44:49 pm by Voroz »

Theshooter7

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #328 on: May 06, 2014, 01:05:23 am »
Not having used LTBL myself, but you could probably draw all your tiles [including the lighting] onto a render texture. Then draw that render texture on top of your sky background in the window.
I was going to do this but the problem is LTBL uses raw OpenGL, and thus bypasses any way to use the Render Textures with it. :(
If i understand correctly i think i would draw the background stuff first, then the background lightsystem and then foreground boxes etc and the lightsystem and set
m_renderLightOverHull = false;
if you want it like the image.
I've tried this, and the result is the same unfortunately. Although I have not provided a hull for the backdrop, so I'm not sure if I should experiment with that, and if so, where to start? Make the hull as big as the window? That doesn't seem right.
I have a problem myself btw. I'm trying to change the brightness of the shadows.

This does nothing to the black color which i have for shadows, but the lights works:
ls.m_ambientColor = sf::Color(50,50,50);
ls.m_useBloom = false;

If i change bloom to true then i can change the shadows color but then the lights wont work anymore.

edit: To be clear my game is completely black, i want to be able to make it less dark :).

edit2: Managed to make it work with bloom on now by setting intensity to over 1, but bloom doesn't work well at all so i need it off.
What if you used a different shadow fin image? Like, you take the existing one, modify it so the dark portion is lighter, and use that with your/a light system? I think that would in turn make the shadows themselves brighter and combined with ambient lighting will brighten things up overall.

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #329 on: May 06, 2014, 02:45:24 am »
I've tried this, and the result is the same unfortunately. Although I have not provided a hull for the backdrop, so I'm not sure if I should experiment with that, and if so, where to start? Make the hull as big as the window? That doesn't seem right.
I don't think creating a hull would help you with this problem.

If your objective is to have your playing area in the middle and the background around that, then perhaps if you create a strong emissive light size and shape of your playing area in the background lightsystem. I read that those are shapeable and if you can also set the sharpness so there is no smoothing then that should give you the correct level of darkness in the center of your game after you draw the front lightsystem over it all.

What if you used a different shadow fin image? Like, you take the existing one, modify it so the dark portion is lighter, and use that with your/a light system? I think that would in turn make the shadows themselves brighter and combined with ambient lighting will brighten things up overall.
I guess the shadow fin is for the shadow part only, i was unsure what to call the dark area, but basically i want everything brighter, not just the shadow. I see in your screenshots it's not entirely black.

Basically m_ambientColor doesn't work at all with bloom turned off for me.
« Last Edit: May 06, 2014, 03:22:45 am by Voroz »