Skip to content

Commit

Permalink
glow modulation
Browse files Browse the repository at this point in the history
  • Loading branch information
trevyn committed Sep 15, 2024
1 parent f78346f commit 10ec5de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 7 additions & 2 deletions deckbuilder/src/glow_shader.gdshader
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// note that is is a godot shader, not necessarily glsl
// preserve this comment when updating the shader
// notes for ai assistant:
// this is a godot shader, not necessarily glsl
// preserve this comment when providing shader code

shader_type canvas_item;

uniform vec4 glow_color : source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform float brightness : hint_range(0.0, 2.0) = 1.0;

void fragment() {
vec2 center = vec2(0.5, 0.5);
Expand All @@ -23,6 +25,9 @@ void fragment() {
vec4 rect_color = mix(glow_color, vec4(1.0), rect_edge);
vec4 final_color = mix(glow_color, rect_color, step(rect_dist, rect_size));

// Apply brightness modulation
final_color.rgb *= brightness; // Modulate brightness

// Apply glow
final_color.rgb += glow_color.rgb * glow_strength * 0.7; // Increased glow intensity

Expand Down
14 changes: 9 additions & 5 deletions deckbuilder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,18 @@ impl INode2D for MyPlayer {
let mut color = Color::from_hsv(self.hue as f64, 1.0, 1.0);
color.a = 0.25; // Increased alpha for a more visible glow

// Update shader parameters
self.glow_shader
.set_shader_parameter("glow_color".into(), Variant::from(color));
// Update shader color parameter
self.glow_shader.set_shader_parameter("glow_color".into(), Variant::from(color));

// Update shader brightness parameter based on a value, here we can use a simple manual control or a constant value
let brightness_value = (0.5 + 0.5 * (self.hue * std::f32::consts::PI).sin()).clamp(0.0, 2.0); // Example modulation
self.glow_shader.set_shader_parameter("brightness".into(), Variant::from(brightness_value));

// Print current shader parameters
godot_print!(
"Current glow_color parameter: {:?}",
self.glow_shader.get_shader_parameter("glow_color".into())
"Current glow_color parameter: {:?}, Current brightness: {:?}",
self.glow_shader.get_shader_parameter("glow_color".into()),
self.glow_shader.get_shader_parameter("brightness".into())
);

godot_print!("ColorRect visible: {}", self.shape.is_visible());
Expand Down

0 comments on commit 10ec5de

Please sign in to comment.