Circular shadowcaster

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Is a circular loading screen with code ready to use. No Animation.
  • Currently, the shadowcaster object only supports rectangular objects. Here's a way to make circular objects cast realistic-looking shadows, by generating a ring of rectangular shadowcasters around the edge of the circle.

    You can do something similar by putting a single narrow box in the middle of the circle: - but it's not accurate if the light source is close or the object is large, both of which I need at the moment.

  • Slick!

  • Nice

  • Nice effect.

    I don't quite get how it works. Is there a possibility to adapt this effect into non-circular shapes?

  • The Physics behaviour has 'elipse' collision mask, shadow casting is pretty much collision check (you keep casting rays and paint those that collide with the shadowcaster object).

    I'm sure Shadowcaster behavior can be adapted to use custom masks.

  • Broo: This creates 36 square objects, sizes them proportional to the parent object, and puts them in a ring right next to the edge, on the inside of the object. Like... making a crude circle out of boxes, and using that to cast the shadow. (Sorry, I made them invisible - change the attribute 'invisible on start' and you should get an idea.)

    Making a crude ellipse out of boxes is possible, I'm sure of it. I suppose you'd just need more, smaller box objects to prevent them from being seen, proportional to how elongated the ellipse is. But you'd also need different maths to actually get the boxes in the right elliptical shape. At the moment I'm just moving the boxes towards angles in every direction, proportional to the size of the circle. For an ellipse, I think trigonometry might be involved. I guess they were right and I should've paid attention in maths class.

    (I hear the shadowcaster object is planned to support non-rectangular shapes eventually, like Mipey says. But I'm not sure what the priority is; probably after 1.0.)

  • I figured after seeing your post, I'd challenge myself to see if I could do it and learn some maths in the process. I gained some trig knowledge and a headache to boot! You math geniuses will probably be shocked at the way I went about it so go easy on a math noob!

    Anyway my initial test with an ellipse didn't work so I'll look into that tomorrow. The shadow is a distortion map btw.

    There are some obvious visual issues but I think you could probably tweak it or I may do tomorrow if I get the time.

  • A shadow without the shadowcaster behaviour? Ingenious.

    I don't understand your maths yet, but I'm reading up on it!

  • I'm afraid to click on anything in this thread, for fear that my head will explode... again.


  • sold: hahah yeah I'm the same as you but seriously.. and I know it's been said many many many times but if I can do it, anyone can. I didn't properly understand sin / cos / tan / asin / acos / atan until I set about this. I knew sin / cos obviously to create circles etc but I didn't understand them. The only thing I remember being told was SOH CAH TOA and that certainly came in handy.

    mort: New version coming soon. Tidying it up and trying to put it into functions so you can just CreateShadowCircle(x,y,radius) and DrawShadowCircle(x,y) and create as many circles as you like. I'm not sure about ellipses just yet. I think that'll need some extra figuring out But before all that I need to fix the shadow so it clips at the edges of the display and doesn't leave a huge gap when the lightsource is too close.

  • Okay here's a tidier version. I've put the drawing into a function so all you need to do is place your own circles in the layout editor, loop through each circle and call the function as in the example. I've left the create function in there (but disabled) in case you want to create circles at runtime. Just pass the 3 params - x,y,radius.

    Still haven't fixed the things I said I would because my brain is in meltdown today.. I think I overdosed on math last night! Anyway, it's getting there I think and it's workable for now.

  • Looking good! Containers and functions make that really easy to use.

    I'll definitely be switching to your distort map method - with 5 circles, the box ring method drops to ~45 FPS, while yours is running 260.

    I wonder if this is how Ashley implemented the shadowcaster behaviour, using something similar to distort maps? I have a rough idea of how we could make box shadows (like in the behaviour) this way. Not that that there would be much point, as behaviours are inherently more efficient, but it's an interesting thought.

  • Yeah I tried your demo earlier and noticed it was a lower FPS. I think the shadowcaster behaviour sends scanlines out in all directions and works from there? That's the only thing I can think of..

    The good thing about distort maps is you could assign a texture to the shadow itself. You could have gradient shadows where the opacity falls off as it gets further away from the circle for example. I'm sure there are other uses for a textured shadow... hmmm

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here's a fixed version. In the older versions one side was inaccurate. I had my triangles wrong when working it out and used atan instead of asin It works now! Still need to fix the clipping..

  • At this rate, you're going to be one of the forum math people!

    (I'm still working out how you did this - haven't had much time lately, but I think I'm getting the idea.)

    By the way, I'm trying to work out if objects are shadowed in the game I'm making (for a situation where a swarm of small objects have to hide from light). I was using instant-hit bullets or LOS objects to detect whether they're shadowed, but there should be a way to adapt this method to work it out, right? I might try it sometime this week.

    (Unfortunately, 'Object is overlapping shadow' doesn't work - I guess distorted objects don't count for collision purposes!)

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