In need of Smart Shadows

Dream3r

90% Dreamer, 100% Dedicated
Veteran
Joined
Jun 13, 2013
Messages
530
Reaction score
376
First Language
English
Primarily Uses
I've attached a picture in the spoilers of a rough concept of what I'm shooting for shadow wise in my current project.  Below that I'll list some issues below I'm having with achieving this effect in engine.  Then hopefully we can find a way to make this work.  So let's get to it.

Shadows

I'm wanting shadows to look more like they do in real life and not just squares and circles that are typical for those new to map design.  (The game currently has a lot of amazing features and bad shadows just takes away from how good the rest of the game is)

Here's some issues though.

1)  Events, like the vegetation shown above, are not placed traditionally on square tiles.  Instead we have events which list thousands of spawns as such,

spawn_event_location(5, 5, 16, 5, 1000)

Basically what you're seeing here is, x location, y location, event ID to clone, map that event is on, ID # to give the new clone.  Meaning the example above is at 5x,5y and it's a tree.

So in order for shadows to be placed exactly in the right spot they need to spawn in a similar fashion, except instead of acting like an event that can be interacted with, they're just shadows.

2)  Shadows need to change direction/angle based on the time of the day.  The game goes through a day and night cycle and though I would prefer constantly moving shadows, that may not be possible.  However they need to at least cycle between morning, afternoon, dusk, and night versions.

3)  Shadows need to behave properly.  Meaning they shouldn't overlap events that wouldn't be affected by them  (For example in the pic above, the trees along the bottom shouldn't have shadows casted on them from trees above, because the shadow would be on the back of the tree, which the player can't see)

________________________________________________________________

Overall it's a lot to pull off but I need to find some way to do it.  Unfortunately this is less of a graphical issue at this point and more of a technical one so my knowledge on the subject is limited.  If some of you are absolute geniuses I do have some extra goals below but of course the focus should be on just solving the issues listed above.

    I) Base shadow tilt on a source of light (aka the sun) so that they tilt as the source of light moves throughout the day.

   II) Have other light sources (using Khas Awesome Lighting effects) effect shadows.  Such as lighting a campfire at night should create shadows on these spawned events.

Thanks everyone for your feedback and I hope we can figure out how to do this together!

-Dakota
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
21,853
Reaction score
11,062
First Language
English
Primarily Uses
RMVXA
One further refinement you might want to build in - shadows are rarely as crystal cut clear as you have shown in your spoiler image, so you need to build in an element of blur on the outline and branch detail, otherwise the shadows will look more like a cartoon than what I think you are aiming for.
 

Dream3r

90% Dreamer, 100% Dedicated
Veteran
Joined
Jun 13, 2013
Messages
530
Reaction score
376
First Language
English
Primarily Uses
Good point @ksjp17, I was rushing this a bit in photoshop just to get them on the thread.  I'll update the image in a sec with blur

EDIT: Added some blur now
 
Last edited by a moderator:

GrandmaDeb

Modern Exteriors Posted!
Veteran
Joined
Apr 25, 2012
Messages
4,467
Reaction score
2,895
Primarily Uses
Depending on how you propagate the shadow image, you can achieve many of your goals.


If you create your shadow producing objects as a seaparate layer in a parallax map, then you can:


1. create a new copied map of the objects which throw a shadow.


2. Select all areas with color and turn them black.


3. Create images of these objects distorted to the various angles you need. (black on top of black shouldn't be a problem)


4. Make each of the images 50% opacity


Unless I am missing something, this should give you the shadows you are looking for.


Display the shadows under the trees layer, obviously.


but I am not an image pro by any account. Or a parallaxing pro. Or a mapping pro. So get others to weigh in. =D


And you aren't generating those forests in-game, are you?
 
Last edited by a moderator:

Dream3r

90% Dreamer, 100% Dedicated
Veteran
Joined
Jun 13, 2013
Messages
530
Reaction score
376
First Language
English
Primarily Uses
And you aren't generating those forests in-game, are you?
Thaaaaaaat's actually where it becomes an issue.  Otherwise I'd do exactly what you said.  Since the forest are generated in engine so that every item can be interacted with (trees cut down, berries picked, etc) everything needs to be an event.  Currently we're going to have over 2,000 events so we have them generated instead of placed to keep lag to a minimum.

So that's why I have this post here, because I can't solve it graphically as you stated which is what I do best.
 

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,255
Reaction score
612
First Language
English
Primarily Uses
The biggest problem I see here is that these changing, un-overlapping dynamic shadows will take too much of a toll on the CPU. Other engines and games in general use the GPU specifically for drawing the graphics, but rpg maker has always used only the CPU (as far as I'm aware).At the moment, spawning your events only happens when you enter the map or in your case, when the game first loads. This is fine because it can take as long as it wants. If it needs to update positions of your events constantly via a parallel process, it'll become very laggy.

Of course you can keep the updating to only whatever is on screen or near the screen. If it lessens the lag enough, then the only issue is finding someone to make a script that draws these shadows all on a single plane to avoid the overlapping issue. I don't believe there's an easy (or hard) solution to this without scripting involved. I think Khas is probably the most experienced in this type of script considering his awesome light effects script. It'll still be difficult if the shadows aren't hard edged, and if you're planning on using lanterns or anything at night, you'll need to take that into account.

Honestly though, for an RM game you're better off having a stationary shadow just underneath the trees, part of the event. With that they can at least be a bit dynamic by changing positions during the day. Haven't brainstormed on how to do that yet though.
 

Dream3r

90% Dreamer, 100% Dedicated
Veteran
Joined
Jun 13, 2013
Messages
530
Reaction score
376
First Language
English
Primarily Uses
@seita, I figured Khas may have been the best to contact too since he's worked with it before and has some plans for an even more awesome light effect system for some point in the future but who knows if he'll be able to help right here and now...

As for your feedback, I hadn't considered the GPU vs CPU functions of RPGM.  Good point.  As is it takes about 10 seconds to load the game at the start and that would be horrible to have happen every time it shifts to a different point in the day.

So basically your suggestion is to make most of the shadow function work but ignore that it won't affect characters and such by casting a shadow over them?  That's...doable just not ideal.  Would make Val seem like she's glowing in the shadows pretty much.

Hmmm, I'll see if further ideas get suggested.  I do have one idea and that is spend the hundreds of hours it would take to hand craft each shadow so that they are laid down like a normal overlay layer but have the right portions cut out so that they don't overlap other objects....It's something I would really like to avoid doing.  already take about a week to get a few hundred plants placed and that doesn't require me cutting away at each one.
 

seita

Donn_M
Veteran
Joined
Feb 6, 2013
Messages
2,255
Reaction score
612
First Language
English
Primarily Uses
You'd also be screwed once one of those trees were cut down. There is another option I hadn't thought of, it's to use a variation of victors light effects script. As it works (unlike other light scripts) it makes a new black layer, and the lights subtract the black from that layer, including the players lantern, etc. In this case you would have another scripter reverse that function and make it so the layer is light, and the lights are darkness. So then you'd make a shadow (light) underneath the trees. You'd have to modify it so that the player lantern still works as intended, and adds light instead. Kind of hard to get your head wrapped around it. I believe you'd also have to make sure the light layer has a Z level underneath the trees, but not the player......

eh. maybe not such a good idea. just brainstorming I suppose.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
I might add that the shadows in your picture may as well overlap, because since we can still see what's underneath them they don't fully block all light.
 

Dream3r

90% Dreamer, 100% Dedicated
Veteran
Joined
Jun 13, 2013
Messages
530
Reaction score
376
First Language
English
Primarily Uses
You'd also be screwed once one of those trees were cut down. There is another option I hadn't thought of, it's to use a variation of victors light effects script. As it works (unlike other light scripts) it makes a new black layer, and the lights subtract the black from that layer, including the players lantern, etc. In this case you would have another scripter reverse that function and make it so the layer is light, and the lights are darkness. So then you'd make a shadow (light) underneath the trees. You'd have to modify it so that the player lantern still works as intended, and adds light instead. Kind of hard to get your head wrapped around it. I believe you'd also have to make sure the light layer has a Z level underneath the trees, but not the player......

eh. maybe not such a good idea. just brainstorming I suppose.
I think you're starting to get onto something...complicated as hell but something...and also I didn't think about the trees being cut down.  That totally ****s the overlay idea.

I might add that the shadows in your picture may as well overlap, because since we can still see what's underneath them they don't fully block all light.
Yeah someone pointed that out to me, so that line is now removed from the requirements
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
The "easiest" way to do this is to have each shadow as it's own sprite and set its zoom_y (to shorten shadows when the sun stands high) and angle depending on the current time of day. Let's be warned, though, that angling sprites is pretty cost-intensive and might cause serious lags if you were to so this every frame.
 

Dream3r

90% Dreamer, 100% Dedicated
Veteran
Joined
Jun 13, 2013
Messages
530
Reaction score
376
First Language
English
Primarily Uses
The "easiest" way to do this is to have each shadow as it's own sprite and set its zoom_y (to shorten shadows when the sun stands high) and angle depending on the current time of day. Let's be warned, though, that angling sprites is pretty cost-intensive and might cause serious lags if you were to so this every frame.
I think I get where you're going with this.  If this works without weird overlaps of events as mentioned before, a shadow being on top of something that should not have a shadow on it, then couldn't set these sprites to only change the zoom and shadow during certain points of the day, or at least space it out where it's not every frame and lag conducive then we should be good....in theory.

Being a gamedev, so many people think it's fun...it's not. Rewarding sure but fun...that's not the word for it
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,023
Reaction score
7,026
First Language
German
Primarily Uses
RMMV
Another point to consider: How fast would the shadows change?


I'm asking because there is a different way to handle this, but it would only work with slow changing.


You can use RGSS-code to create a bitmap picture - for example Tsukihime does this in her mapshot script.


So you can create a single overlay picture with the tree shadows, and then use one of the regular overlay scripts to change it as a shadow layer.


If I remember correctly, yami's script allows for changing of shadow layer pictures by game variables.


You would then have to call the function to make a new shadow overlay only when the time/shadow direction changes or when a player cuts down a tree.


However, the speed with which the picture is created would depend on how large the map is, and if you need it changed too often that wouldn't work.
 

Dream3r

90% Dreamer, 100% Dedicated
Veteran
Joined
Jun 13, 2013
Messages
530
Reaction score
376
First Language
English
Primarily Uses
Another point to consider: How fast would the shadows change?

I'm asking because there is a different way to handle this, but it would only work with slow changing.

You can use RGSS-code to create a bitmap picture - for example Tsukihime does this in her mapshot script.

So you can create a single overlay picture with the tree shadows, and then use one of the regular overlay scripts to change it as a shadow layer.

If I remember correctly, yami's script allows for changing of shadow layer pictures by game variables.

You would then have to call the function to make a new shadow overlay only when the time/shadow direction changes or when a player cuts down a tree.

However, the speed with which the picture is created would depend on how large the map is, and if you need it changed too often that wouldn't work.
I remember the mapshot script, and I am using yami's script to allow multiple shadow layers...I'll be honest I only understood half of your explanation.  What would make the individual tree shadows and such go away when cut down?  from what i can tell yemi's layer system would just pull from a series of images and it wouldn't be able to account for each individual tree (as from what I've done with it, it can only show one shadow layer at a time)

As for speed of shadow change, ideally it would change constantly throughout the day but since that is very hard to do with 2D and near impossible with RPGM as it is today, the shadows need to only change at set points throughout the day.  It isn't ideal but it will work.

Though when an object such as a tree is removed (or cut down in a tree's case, picked if it was a small plant) the removal of the shadow would need to be close to instant.  That being said to save money on animation the cutting of the tree is not shown.  It's just a fade to black, play sfx, cut back to fallen tree.  So if it needs to load something, it can be during this short time.

____________________________________________________

I just wanted to thank you all for the support so far.  I know I'm on the verge of creating something really good with RPGM (or games in general) despite my lack of programming knowledge.  I would have never made it this far without you guys and the community here so thank you for this.  This goes beyond the shadows today.  This thanks is for the last two years of helping me get to this point.  I'm not doing great in real life but at least the game and my dreams are getting somewhere.  So thank you.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
The basic idea is to create a bitmap at the time the map is loaded and whenever it changes (tree cut down, shadow angle changes, etc), fill it with the shadows of all trees and use it like an overlay (would need to fiddle a bit with the z-index to have it display below the trees but above the player, but that would need to be done anyway).

This way you only have to draw 1 sprite every frame at the expense of having to recreate it everytime something changes.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,023
Reaction score
7,026
First Language
German
Primarily Uses
RMMV
As lavra explained, the principle behind my idea would be to dynamically create the bitmap just before using it.


Basically you would have two shadow layer pictures, only one of them active - and when any change happens, the non-active picture would be rewritten to the current state (which takes some time) and after it's ready the script would switch to the new picture and the next change would overwrite the old one.


The key is the time needed to create that shadow picture dynamically. I never used the mapshot script, so I don't know how fast that bitmap creation is. But I do know that it takes longer the bigger the map is.


If it can be done in a few seconds for your maps, then you could easily create the shadows whenever you need a new one.


If that is too slow, then it won't work.


There are a few possibilities on how to speed that up (like only changing small sections when a tree is cut down), but it all depends on how your maps are structured so I can't give more advice
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
859
First Language
German
Primarily Uses
Funny idea, but would it be possible to realize multi-threading in RGSS? So you have a thread running in the background creating a new shadow bitmap that then gets fetched by the main thread when it's ready. On big maps there will still be a delay after a tree gets cut down (won't be that noticeable at time changes), but at least you won't experience freezes that way.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
30,023
Reaction score
7,026
First Language
German
Primarily Uses
RMMV
yes and no - you'll need to step in at the same point as evented parallel processes, but that basically takes care of the multi-threading (no, real multi-threading isn't possible due to the game being run on an interpreter, not a compiler)


But because it isn't using a different CPU, you'll have to split the shadow creation in a way that allows it to be run as such a parallel process - and that is not as easy as it sounds.
 

GrandmaDeb

Modern Exteriors Posted!
Veteran
Joined
Apr 25, 2012
Messages
4,467
Reaction score
2,895
Primarily Uses
Well, you guys are waaay outta my league on this one, but can the peanut gallery just step in with a very small thought?


If you choose to have much smaller shadows, (not so long and only extending in a limited circle around the tress/bushes) couldn't you just switch from one sprite to another and include the shadow in the sprite?


Then overlap would be minimized and you'd hit your main goals and maybe simplify your life.


My two bits.


Looks cool. Good Luck.


/me goes back to the peanut gallery
 
Last edited by a moderator:

Dream3r

90% Dreamer, 100% Dedicated
Veteran
Joined
Jun 13, 2013
Messages
530
Reaction score
376
First Language
English
Primarily Uses
If you choose to have much smaller shadows, (not so long and only extending in a limited circle around the tress/bushes) couldn't you just switch from one sprite to another and include the shadow in the sprite?

Then overlap would be minimized and you'd hit your main goals and maybe simplify your life.

/me goes back to the peanut gallery
I'm with you on that last statement.  I get maybe half of what they're saying...still trying to wrap my head around the other half....

@Andar and @Iavra...I'm going to see how I can implement the methods listed here.  I like the bitmap idea updating as needed but with the map being 250x250 tiles even if it works it would take a long time to do from what I can tell.  I'm going to speak with a friend who is helping me script wise and see what we can do.

Thanks everyone and I'll be back with an answer sometime soon hopefully.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

It's ironic, but one of the many hilarious things done with Shia's Just Do It speech was to make a hype song, and....I know what it is.....but I still get inspired by it! I'm like..."Yes I can!!"
That moment when you realize you lost time frankenstiening a sprite together, only to realize it already exited.
My first game is going to have the main character more or less create monsters as his party members.

Thanks to the plugin creators still producing content for MV, I might be able to give each of the monster members a personalized range of tactics during combat. I liked how the devs made it like that in FF6.
Stream will be live shortly! Tonight will be the PREMIERE of Killer 7 for the first half of the stream, and at half-stream, we will switch to a session of the Interactive Text Adventure! Feel free to drop by!
Watching the launch, I felt a sort of detached excitement. Usually I'd think something like this would be extremely exciting. I'm fascinated by space exploration and am a big Sci-Fi fan. I guess it's just current events.
What did everyone else think about it?

Forum statistics

Threads
97,970
Messages
948,196
Members
129,221
Latest member
GeorgePity
Top