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
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.
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)
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 :(
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
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.
@@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.
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
Very inspirational. These tutorials give me something to focus on and I end up learning so much from implementing them.
Glad you like them!
Didn't expect the math, but it's great math! Good work!
just want to say thank you! Very useful and pleasant to watch
Glad it was helpful!
this was really helpful, thanks!
This looks very nice! Worth giving a try tonight.
thanks!! exactly what I was looking for :)
Saludos desde Uruguay, me encantaría más tutoriales 🇺🇾✌️
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
Hopefully it's not because of my thick French accent :D
@@dreamedawayrpg lol no I just don't understand any of the technical jargon!
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.
Cool! But I have a question. How to draw a sector?
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)
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 :(
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)
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
Oh, I see! I'll check the video, because that's what I should have done as well.
Nice! Is there a way to make the lights in different sizes?
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.
thanks
gonna see if I can replicate this in 3D somehow
Wow.
Nice! Is there a way to make the lights work if the camera is static and doesn't follow player?
Yes, because it will work with or without camera.
@@dreamedawayrpg are there any changes needed to make because when i try with static camera the light move slower than the player
@@Hungg-ry6ih No I don't think so. Did you check my previous tutorial where I explain how the project is set up?
@@dreamedawayrpg same thing also happen to me, my lights are moving slower than the player
Thanks for the video.
Why not use the light nodes from the Godot instead of the shader?
It's just a very different effect.
How to cast shadow?
What is the advantage of doing it this way as opposed to using the Godot lighting system?
It's a very different look, much more stylized and retro than using Godot's lighting system.
@@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.
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
french accent ?
Haha, yes!