Custom lighting system in Godot 4

Поділитися
Вставка
  • Опубліковано 15 жов 2024

КОМЕНТАРІ • 39

  • @johneicher6683
    @johneicher6683 3 місяці тому +7

    Very inspirational. These tutorials give me something to focus on and I end up learning so much from implementing them.

  • @150nitrodude
    @150nitrodude 2 місяці тому +1

    Didn't expect the math, but it's great math! Good work!

  • @slavakislov3675
    @slavakislov3675 3 місяці тому +2

    just want to say thank you! Very useful and pleasant to watch

  • @Rambi_PorkChop
    @Rambi_PorkChop 3 місяці тому +5

    this was really helpful, thanks!

  • @UltiemeHack
    @UltiemeHack 3 місяці тому +1

    This looks very nice! Worth giving a try tonight.

  • @donklii
    @donklii 3 місяці тому +1

    thanks!! exactly what I was looking for :)

  • @ŕíćéAvarice
    @ŕíćéAvarice 2 місяці тому +1

    Saludos desde Uruguay, me encantaría más tutoriales 🇺🇾✌️

  • @DeadIndGames
    @DeadIndGames 3 місяці тому +1

    Wow! Subscribing because I love what you're doing with Godot! And maybe with the hope that someday I'll understand even a single sentence of what you said! lol

    • @dreamedawayrpg
      @dreamedawayrpg  3 місяці тому

      Hopefully it's not because of my thick French accent :D

    • @DeadIndGames
      @DeadIndGames 3 місяці тому

      @@dreamedawayrpg lol no I just don't understand any of the technical jargon!

  • @marcusdias93
    @marcusdias93 2 місяці тому

    Very good tutorial and a wonderful result in game. I was wondering if i can achieve a similar result using a CanvasModulate ? I have made a day and night cycle with it, and i want to set some lights when it is night time.

  • @MR_PORRIDGE97
    @MR_PORRIDGE97 3 дні тому

    Cool! But I have a question. How to draw a sector?

  • @F776-b2s
    @F776-b2s 2 місяці тому

    Great tutorial. One problem I ran into was that depending on the size of the window the positions of the lights would get smaller and pushed to the top left corner. I found a workaround, but the pixel art effect was lost. I did not modify the shader code.
    class_name Lighting
    extends ColorRect
    var get_light_positions: Callable #Inject function from parent node
    var previous_viewport_size: Vector2
    func _ready() -> void:
    self.set_process(false)
    previous_viewport_size = get_viewport_rect().size # Window size on my project settings, (384, 216)
    func _process(_delta: float) -> void:
    var current_viewport_size: Vector2 = DisplayServer.window_get_size()
    var shader_material: ShaderMaterial = self.material
    # Check if the viewport size has changed
    if current_viewport_size != previous_viewport_size:
    # Scale the light parameters
    var scale_factor: float = current_viewport_size.x / previous_viewport_size.x
    shader_material.set_shader_parameter(&"light_radius", shader_material.get_shader_parameter(&"light_radius") * scale_factor)
    shader_material.set_shader_parameter(&"band_radius", shader_material.get_shader_parameter(&"band_radius") * scale_factor)
    previous_viewport_size = current_viewport_size
    var light_positions: Array = get_light_positions.call()
    var viewport_transform: Transform2D = get_viewport_transform()
    # Convert light positions to screen space
    var screen_space_positions: Array[Vector2] = []
    for light_pos: Vector2 in light_positions:
    screen_space_positions.append(viewport_transform.basis_xform(light_pos))
    # Update shader parameters
    (self.material as ShaderMaterial).set_shader_parameter("number_of_lights", screen_space_positions.size())
    (self.material as ShaderMaterial).set_shader_parameter("lights", screen_space_positions)

  • @jRsqILVOY
    @jRsqILVOY 2 місяці тому +1

    I wonder if it's possible to do this with a Compositor Effect now instead of a screen-wide fragment shader?
    Also if it's possible to remove the if statement in the shader, branching is bad :(

    • @dreamedawayrpg
      @dreamedawayrpg  2 місяці тому

      These days if statements in shaders are probably not as bad as you think, but yeah, you can probably get rid of them (I haven't tried though)

  • @WexDex99
    @WexDex99 2 місяці тому +1

    im probably missing something, but all i see is the lights on the corner of my camera not moving, or rather following the camera.
    EDIT : okay i found it.
    when you send shader params you need to do the "shader_param/" before the actual param, could be a godot version thingy? but loved the tutorial

    • @dreamedawayrpg
      @dreamedawayrpg  2 місяці тому

      Oh, I see! I'll check the video, because that's what I should have done as well.

  • @davifox94
    @davifox94 3 місяці тому +1

    Nice! Is there a way to make the lights in different sizes?

    • @dreamedawayrpg
      @dreamedawayrpg  3 місяці тому +1

      Yes! By attaching a script to each light source (Marker2D), you could export a radius and use that in the shader instead of a fixed one for all lights.
      This is actually what I do in Dreamed Away.

  • @HtetMyat79
    @HtetMyat79 3 місяці тому +2

    thanks

  • @soloshottie
    @soloshottie Місяць тому

    gonna see if I can replicate this in 3D somehow

  • @theflowtnt
    @theflowtnt 3 місяці тому +1

    Wow.

  • @Hungg-ry6ih
    @Hungg-ry6ih 3 місяці тому +1

    Nice! Is there a way to make the lights work if the camera is static and doesn't follow player?

    • @dreamedawayrpg
      @dreamedawayrpg  3 місяці тому

      Yes, because it will work with or without camera.

    • @Hungg-ry6ih
      @Hungg-ry6ih 3 місяці тому

      @@dreamedawayrpg are there any changes needed to make because when i try with static camera the light move slower than the player

    • @dreamedawayrpg
      @dreamedawayrpg  3 місяці тому

      @@Hungg-ry6ih No I don't think so. Did you check my previous tutorial where I explain how the project is set up?

    • @ariffirdaus5376
      @ariffirdaus5376 2 місяці тому

      @@dreamedawayrpg same thing also happen to me, my lights are moving slower than the player

  • @ShinSpiegel
    @ShinSpiegel 3 місяці тому +1

    Thanks for the video.
    Why not use the light nodes from the Godot instead of the shader?

  • @DexterFstone
    @DexterFstone 3 місяці тому +1

    How to cast shadow?

  • @WhoIsCraig
    @WhoIsCraig 3 місяці тому

    What is the advantage of doing it this way as opposed to using the Godot lighting system?

    • @dreamedawayrpg
      @dreamedawayrpg  3 місяці тому

      It's a very different look, much more stylized and retro than using Godot's lighting system.

    • @ninstars
      @ninstars Місяць тому +1

      @@dreamedawayrpg That effect you showed at the end of the video you can actually achieve that very easily using the built-in light system, all you need to do is to use a GradientTexture2D as the texture of a light point and set the interpolation to constant.

  • @ToastedGears
    @ToastedGears 2 місяці тому +1

    Hey, I don't know what I did differently my code seems to be the same as in the later part of your video, with band radius and the modulate func.
    But on the return modulated it gives me the error Expected Return with an expression of type void
    nvm my error was that i put in void before modulate

  • @FlambynoLeVrai
    @FlambynoLeVrai 3 місяці тому +1

    french accent ?