Jump to content


Photo
- - - - -

Grid Based Lighting


  • Please log in to reply
22 replies to this topic

#1 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 21 June 2009 - 05:44 PM

  • Title: Grid Based Lighting
  • Description: a solution to add grid based dynamic lighting with soft shadows to any game
  • GM Version: GM7
  • Registered: Yes
  • File Type: .gmk
  • File Size: 0.02mb
  • File Link: Posted Image
  • Screenshots: Screenshot 1 Screenshot 2
Additional Info
I have been working on this for a couple days and it is an edit from my previous grid based lighting script (see signature) but has expanded to include dynamic soft shadows but has dropped some other features. You are still free to use my other one if the soft shadows aren't for you. This example does run fairly slow but some settings can be adjusted to accommodate. If anyone would like me to explain to them how this works just feel free to ask and I'll try my best. I know there are also some bugs in it that could be fixed and I am working on that at the moment. For credit there are none needed but please PM me if you complete a game using the engine as I would like to see how it turns out. Other than that enjoy!
  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#2 joffysloffy

joffysloffy

    GMC Member

  • GMC Member
  • 21 posts

Posted 21 June 2009 - 07:46 PM

Very nice system. But I don't think anyone is going to use this, because your fps is like 1...
  • 0

#3 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 21 June 2009 - 07:48 PM

Yeah it's pretty slow. It the fastest I think I can make it without to much unrealism. Also if you have a 32 by 32 grid it runs well. And I only got 1 when I set it to 4 or something I get around 20 at the stock settings. I do have a pretty nice computer though. :)
  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#4 serenity4ever

serenity4ever

    GMC Member

  • New Member
  • 513 posts

Posted 21 June 2009 - 07:57 PM

It is a pretty cool concept however the
grid = 4
for(i=0; i<room_width/grid; i+=1)
{
	for(j=0; j<room_height/grid; j+=1)
	{
	   if !collision_point(i*grid,j*grid,obj_block,0,0)
	   {
			instance_create(i*grid,j*grid,obj_grid_square)
	   }
	}
}
could do with some work as it causes it to run insanely slow however if grid is set to 16 it runs ok just doesn't look so good

could not a list of all those objects run quicker (I haven't tried anything yet)

Edited by serenity4ever, 21 June 2009 - 07:59 PM.

  • 0
They are coming - A 2d top down Call of duty WAW zombie mode game - WIP
----------------------------------------
Wash: This landing is gonna get pretty interesting.
Capt. Malcolm Reynolds: Define "interesting".
Wash : Oh God, oh God, we're all going to die?

#5 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 21 June 2009 - 08:02 PM

Not really, that is only in the create event to place all of the grid objects where there aren't any walls, it doesn't run every step nor does it effect the engine. If I wanted to I could place them in the room editor but I'm too lazy so I made that to do it for me.
  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#6 serenity4ever

serenity4ever

    GMC Member

  • New Member
  • 513 posts

Posted 21 June 2009 - 09:48 PM

Yeah after looking into it a bit more I realized I was barking up the wrong tree there its the draw event of obj_grid_square
  • 0
They are coming - A 2d top down Call of duty WAW zombie mode game - WIP
----------------------------------------
Wash: This landing is gonna get pretty interesting.
Capt. Malcolm Reynolds: Define "interesting".
Wash : Oh God, oh God, we're all going to die?

#7 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 21 June 2009 - 09:50 PM

Yeah cause I have to check a bunch of collision lines. I think it's the most efficient way of doing it but I can't be sure.
  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#8 TheSnidr

TheSnidr

    Heavy metal viking dentist

  • GMC Elder
  • 3345 posts
  • Version:GM:Studio

Posted 21 June 2009 - 10:14 PM

Doing this with objects is not going to work. I got 1 fps...

Why not make something similar to the shadow script you made for my fake 3d engine?
  • 0

#9 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 21 June 2009 - 11:09 PM

Because it doesn't work with grids properly. What kind of computers do you have anyway, I get 20 with 16 by 16 grid and 16 light diameter.

Edit: I am working on an update that removes the grid square object completely. This should help the framerate a bit.

Edit Edit: I did the way without objects but the fps went down about 5.

Edited by wiiowner, 22 June 2009 - 01:17 AM.

  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#10 serenity4ever

serenity4ever

    GMC Member

  • New Member
  • 513 posts

Posted 22 June 2009 - 06:59 AM

16x16 grid and 16 diameter gave me 15 fps with a 2.1 quad core Phenom, 3 gig ram, 512 g-ram on a 8600gt and not sure if it matters but 64bit vista
  • 0
They are coming - A 2d top down Call of duty WAW zombie mode game - WIP
----------------------------------------
Wash: This landing is gonna get pretty interesting.
Capt. Malcolm Reynolds: Define "interesting".
Wash : Oh God, oh God, we're all going to die?

#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 22 June 2009 - 08:59 AM

An interesting concept, though you can improve the speed by rethinking it a little

[removed]

Still too slow to be usable though;

Edited by xot, 22 June 2009 - 12:04 PM.
Sorry, in the Tutorials and Examples forum you're not allowed to post new examples or derivative works in the topics of others. Contact the topic starter privately. If they wish, they can post it.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#12 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 22 June 2009 - 12:56 PM

Did you understand how I did it icuurd? I think it's the most efficient way to do it without it being too unrealistic. I think Host-a is down at the moment.

Edited by wiiowner, 22 June 2009 - 12:59 PM.

  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#13 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 22 June 2009 - 01:14 PM

Did you understand how I did it icuurd? I think it's the most efficient way to do it without it being too unrealistic. I think Host-a is down at the moment.


The link was removed by mod... you can get it from my host-a net/my user name.


Yes I understand your method.

Like my link showed, you can limit the damage by exiting early, like if your light max casting distance is 100, and the shadow block is further, just exit;

Edited by icuurd12b42, 22 June 2009 - 01:22 PM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#14 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 22 June 2009 - 07:20 PM

Yes but that leaves an ugly draw distance.

Edit: Nevermind found your example, I'm not quite sure I understand your code but I tried to do something similar by adding darkness to the pre-exsiting value depending on how far away it is. I didn't turn out well because it made the blending look bad.

Edited by wiiowner, 22 June 2009 - 07:26 PM.

  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#15 serenity4ever

serenity4ever

    GMC Member

  • New Member
  • 513 posts

Posted 22 June 2009 - 08:50 PM

rather than using all the instances in the room wouldn't a 2-d array or ds_grid be quicker in theory?
  • 0
They are coming - A 2d top down Call of duty WAW zombie mode game - WIP
----------------------------------------
Wash: This landing is gonna get pretty interesting.
Capt. Malcolm Reynolds: Define "interesting".
Wash : Oh God, oh God, we're all going to die?

#16 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 22 June 2009 - 08:54 PM

An array doesn't really help. I did it without object and it run a bit slower for some strange reason.
  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#17 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 22 June 2009 - 11:12 PM

Yes but that leaves an ugly draw distance.

Edit: Nevermind found your example, I'm not quite sure I understand your code but I tried to do something similar by adding darkness to the pre-exsiting value depending on how far away it is. I didn't turn out well because it made the blending look bad.

Yep. No matter was you do, this method will never be pixel perfect.

The circular limit does help... You could have a sprite with a hole punched in it the size of the light range... Then you have much fewer instances covering only the radius of the hole; following it.

rather than using all the instances in the room wouldn't a 2-d array or ds_grid be quicker in theory?

Not really, since GML is interpreted...

An array doesn't really help. I did it without object and it run a bit slower for some strange reason.


...looping through an array is actaully slower than letting GM loop internally and trigger the events.

Leaving the the draw event alone, using a sprite and image_alpha instead of drawing a rectangle also improves performance
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#18 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 23 June 2009 - 12:24 AM

The reason mine looked bad is because it would turn normally blended tiles into pure black and only blended some. Which resulted in almost none being virtually transparent. Also what you said about the sprites versus drawing rectangles doesn't make sense. In my game of life program I tried both methods and got a couple more frames through drawing rectangles.
  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#19 Virus2_0

Virus2_0

    Penguin Programmer

  • New Member
  • 476 posts

Posted 01 July 2009 - 06:03 AM

there are faster ways of doing this. its faster to check every 5 degrees or so and find the nearest object on a line in that direction and then draw a polygon around using all the points.

Edit: I got my method working.... 30fps with a gradient on a <750MHz computer...no lagg issues there... im still waiting for my tut 2 b approved so i can update it....

Edited by Virus2_0, 01 July 2009 - 06:58 AM.

  • 0

galex - NoD Member -TDS flashlights, Fast - Draw Regular Polygons
Recursive (adj.): see [i]recursive.
Programmer (n): An organism that turns caffeine into code.
FIGHT FOR GM FOR LINUX! PLEASE ADD THIS IF YOU WANT THE DEVELOPERS TO COMPILE A LINUX VERSION!


#20 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 01 July 2009 - 04:11 PM

I'm not sure I quite understand your method but from what I do understand it's not grid based. Some code or a gmk would be nice.
  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics


#21 Virus2_0

Virus2_0

    Penguin Programmer

  • New Member
  • 476 posts

Posted 01 July 2009 - 04:53 PM

i submitted a tut... but it hasn't been approved yet... if it isn't in another few hours im gunna send a pm and see if its inthe works and make sure i didn't hit like [cancel] instead of [Post]. I modified it and i can get 30fps on a 9 1/2 year old computer...
  • 0

galex - NoD Member -TDS flashlights, Fast - Draw Regular Polygons
Recursive (adj.): see [i]recursive.
Programmer (n): An organism that turns caffeine into code.
FIGHT FOR GM FOR LINUX! PLEASE ADD THIS IF YOU WANT THE DEVELOPERS TO COMPILE A LINUX VERSION!


#22 general sirhc

general sirhc

    Dream Big, Act Small

  • GMC Member
  • 1667 posts
  • Version:GM:Studio

Posted 01 July 2009 - 04:57 PM

I am sure you are well aware that there is lighting engines out there that make this look like a square when the wheel was invented (That was meant to make what I said seem like less of an insults sorry.)

Anyway I like your idea but you've just gotta find a faster way of doing it

http://host-a.net/ge.....xample v5.gmk

Check out the simple but effective lighting engine I made a while back (And no mine is still no where near as good as the good ones) but its the same deal as where you seem to be coming from so hopefully you can learn how I did it and use what I did to make yours better

No credit needed what so ever but I would love it if you release your next version pm me and I'll check it out.

Best of luck =)
  • 0

qs8ZFMQ.png?1


#23 wiiowner

wiiowner

    Absolute Zero Team

  • New Member
  • 685 posts

Posted 01 July 2009 - 05:19 PM

You guys are missing the point here. It's supposed to be grid based and have soft shadows. I hope not to sound offensive but yours had neither of those features. I do have a different approach I'd like to try but it involves edge finding and stuff. I may test it out though.
  • 0
Completed Projects: Eco-Chrome || Conway's Game of Life - Update that triples framerate!
Scripts: Grid Based Lighting (With Dynamic Soft Shadows) || Mud Physics