Can 2D casted shadows behave as "sun" casted shadows?

zadigzadig Posts: 28Member
Hi again :).

Considering a 2D top-view game, using oblique projection to be more precise (think of oldschool RPGs for instance), I'd like buildings in a given scenario to cast shadows all in the same angle, as if the light origin was very, veeeery far - just like the sun is far from us.
Using light2d and light occluder2D I was unsuccessful trying to achieve the desired effect, unless placing the light2d very far, far enough to feel wrong :neutral:
Is it possible to achieve this "directional 2D light" effect?
Thanks in advance!


Tags :


  • razvanc-rrazvanc-r Posts: 84Member
    OK, so what you're talking about is isometric projection if I'm not mistaking. Godot as far as I know can do it yes, I think there are a couple of examples that you can download from the godot demo repository. About the shadow you might feel that this is hack but if I were you (and you find this in many games, even 3D through baking), I'd make the shadow myself, as part of the art. You don't need light for what you want to achieve.

    I can think of two ways on how to cast shadow on characters. Either make a transparent png as the shadow and have the characters render behind it or use an area2d with the shape of the shadow and trigger change in color or whatever effect you want on characters that get in contact with this area2d things.

    Good luck!
  • zadigzadig Posts: 28Member
    edited August 2016
    Thanks for answering, Razvanc
    Actually it's not isometric projection, I was referring to games like SNES rpgs (Final Fantasy III for instance) and not isometric titles like Fallout or Diablo. My mistake for not expressing myself with examples.
    I am currently doing exactly as you suggested, using shadows as part of the artwork. However it would be easier to do otherwise, a projected shadow, with occluders (considering that I could project all the shadows at the same angle as said in OP) could allow me to easily give the player a notion of what's time of the day in a given scene (a 45 degrees shadow indicating sunrise, opposed to a -45 degrees indicating sunset, for instance). Of course some area effects would be used together to affect the environment "light" (in this case emulated just changing the contrast / brightness of the artwork a little).

    Just illustrating a little (forgive-me for the "crudeness" of the images :blush:  ) here's what I can do with Light2D and oclluders (not the desired "sun casted shadows" effect):

    And here's the effect I'd like to achieve:

    Once again thank you for your time :).

  • razvanc-rrazvanc-r Posts: 84Member
    Well... I don't see any other way of doing it other than either include it in the art or as you mentioned with a very distant light...
  • zadigzadig Posts: 28Member
    By going under the hood and playing with the cpp code it shouldn't be hard to create such a behavior just by modifying a little the existing raycast algorithms of the Light2D. I just don't want to recreate the wheel, maybe someone else has done it or has an idea of how to do it with the existing tools and maybe some gdscript "guru-ing"
  • KioriKiori Posts: 246Member
    edited August 2016 Answer ✓
    Essentially, in most any engine, unless there are built-in types that already do this: This is a job for Shader-Man!




    Now as a disclaimer i haven't fully read the above links, but it doesnt matter, they are trying to implement the same thing you are.
    You can go online and search for  2d penumbra shader, for instance, should give you some results.
    Shaders control your presentation, in essence, they -can- behave like a dynamic layer of paint atop your original texture/art, among other things.(hence the shade part)
    This is how games with great graphics, including the effect you're looking for, were made with "limited" engines like game maker.

    Now what you have to do is sit down, read lots, understand it, experiment, research, port any number of such implementations to Godot's GLSL and be happy. There are lots of pre-made shader implementations online.
    Also, hopefully share it with the community later on, so other ppl have a shortcut, and don't have to do all the work you did.

    Most good looking effects will not be a simple plug and play, unless one of the devs already did the heavy lifting for you. Sorry I can't give you a more direct solution but I'm ultra busy atm.
    OH and btw, check out the forum's shader section. Researching shaders is always good!

    Best of luck!
  • zadigzadig Posts: 28Member
    Thanks, Kiori :).
    My small team has a inhouse engine for another project in which we deal with shaders quite a bit :). It is indeed fascinating and I'm always amazing me with other people's creative uses for shaders. I really wanted to know if there was an object like "Sun light 2D" or a way for the Light2D to behave as said, just to avoid scripting shaders if it invest some time.
    Thank you all, guys!
Sign In or Register to comment.