[CAPX] Yet another shadow caster

0 favourites
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • Thanks for responding Sorry about the delay, I wasn't alerted to your response.

    Please find below the version I have been working on:

    https://dl.dropboxusercontent.com/u/50465867/Construct/LightTest.capx

    This setup allows objects with textures on to be hidden, but this is based on an additional falloff being added and used as an effective mask. This issue I can forsee with this, is if you were to move it up to a solid object, although the light wouldn't go through, and would cast a shadow, the objects on the other side would still be visible.

    Also, as CanvasMain is constantly being turned solid black, It prevents me from having a background. Shadows won't appear on objects on a higher layer.

    I saw this version (linked below), which only uses 1 canvas, and allows a background, without the need for transparency, etc, however it doesn't work well with multiple light sources.

    https://dl.dropboxusercontent.com/u/50465867/Construct/LightTest02.capx

    With yours, I like the way the colour bleeds into each other forming different colours, but can't really see why 2 canvas' are required. I've tried altering bits and pieces, but it seems to be an easy thing to break.

    However, I have disabled the falloff visibility toggle every tick, as I don't see any difference. I've also added a distance indicator so that shadows aren't drawn on objects that are too far away from lights.

    Still, my attempts at combining the two methods have been met with failure. Any ideas?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh, and additionally, although I really like the mixed colours, I have a bad feeling that they wash away the texture below them :(

    My sprite is made up on 2 solid colours, but with the light on top, both show up as a single solid.

  • Amazing R0J0hound :) very good and fast implementation, why is there no native plugin for this? :) and canvas plugin too! You rock, I thought it wasn't even possible to do do such things in C2.

  • Hi, I had a quick look at the capx. I also tinkered abit with making objects visible but my implementation of my idea wasn't working right. As to multiple canvas' it's for the additive blending of the lights. Each light casts shadows on its own canvas and then it's additively drawn to the main canvas for blending. I got away with just two canvas' since I can just keep reusing the 2nd canvas for each light. The composition will have to be reworked to incorporate transparency so you can allow textures underneath to show through.

    Here's a rough idea how it could be done.

    I think it's "destination out" that acts as an erase.

    1 draw shadows to canvas c1

    2 fill canvas c2 with the light color

    3 give c1 the destination out blend and paste it to c2.

    C2 will then have the lit areas colored and the shadow areas transparent.

    4 paste the falloff sprite to that too and then paste it with an additive blend to canvas c3

    Do that go each light.

    5 you can then get the shadows again with steps like 2 and 3. The shadows should be now on canvas c4.

    The only 2 canvas that should be drawn are c3 for the light and c4 for the shadows.

    You could then fiddle with the light canvas opacity to adjust the blend.

    There may be some issues with the idea since I haven't tested it.

  • R0J0hound will try your last post :D if I fail I will ask you to post a little sample file :)

  • So this method uses 4 canvas', but only 2 of them are drawn? This should mean it's using about the same resources as before, right? I'm wondering if I've tweaked your design a little too much for me to make this work. I may have to start again too.

  • xDGameStudios Had any luck? Have you tried out my version posted earlier?

  • For my project I need flash light and (normal) lamp light, and I need the rest of the screen to be completly dark!

    AnD4D

    I haven't tryed it yet... I looked at your samples the one you've made is very good and fast :) the other one is just toooooo slow.. 15fps :/

    I'll try it today, maybe tomorrow :)

  • AnD4D

    Have been trying to for 5 hours now.. with no luck.. think I'm missing something :/

  • xDGameStudios

    I wish we had this native. I also am looking for a flashlight and lamplight look. If I figure it out, I'll send you the capx. Can you do the same? :) Imagine if we're making the same game... <img src="smileys/smiley3.gif" border="0" align="middle" />

    I manage to break the project more than I can make it work. I am starting to wonder if my brain is good enough for this... :(

  • Wow, destination in really kills the frame rate!!!

  • Hi,

    I converted the example to use the Paster plugin instead of the Canvas plugin so it will be much faster with webgl.

    This is the result of much tinkering and unfortunately even I have a hard time to see what I did. Basically the lighting is done with transparency and then the color is a separate canvas below so I can have finer control of the blending.

    https://dl.dropboxusercontent.com/u/5426011/examples19/shadow_cast_paster.capx

    Here is a simplified version that just has one light.

    https://dl.dropboxusercontent.com/u/5426011/examples19/shadow_cast_paster_simple.capx

  • Wow, thanks R0J0hound,

    I had to alter the resolution slightly for the advanced version, as 320x240 gave unusual results, but this looks like it's exactly what I've been looking for!

    I can see what you meant earlier about concave objects. Interesting self shadow.

    I can't seem to get my head around the use of the RES variable, however. This version may be a lot faster, but I still found it a useful operation to have available. I tried to add in /RES to the parameters as in the old version, but I managed to break it all, so quickly CTRL-Z'd :)

    This is brilliant though! I'm quickly pulling it around to see what it can do, and how many strain it can take :)

    Thank you so much!

  • RES isn't used, I forgot to remove it. If you want to use it just change set resolution int the start of layout to 640/RES,480/RES. It isn't used elsewhere.

  • R0J0hound

    In my attempt to make it suitable to layouts of all sizes, I added in a feature that will destroy all of the pasters, and then re-create them (just to be tidy, and make sure they're in the same space). I then set their width and height to the size of the layout (so that they can be used everywhere), and finally, I set the resolution.

    However, I noticed that when I scaled the paster objects, the resolution looked like it had dropped. I tweaked the resolution, as you suggested, and that didn't have any effect. Finally, I separated the family into their individual parts, and altered the scale for each, and I ended up with a black screen.

    Please see the attached: https://dl.dropboxusercontent.com/u/50465867/Construct/NewLight.capx

    I've made it work with any layout size (with a few more things to add to help maintain a high frame rate) but notice how low the resolution is? It doesn't matter how much I seem to change the RES variable, it doesn't appear to help.

    It's a brilliant plugin, and thanks again. So close to getting it exactly how I want it. Any ideas how I can fix this resolution? The same technique worked fine for the older version.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)