Godot Version
4.4.stable
Question
How can I make that a texture reacts to turn white having the shape with a little glow like in old CS:GO
4.4.stable
How can I make that a texture reacts to turn white having the shape with a little glow like in old CS:GO
@export var material: Material
@onready var mesh = $MeshInstance3D
func _on_mouse_entered() -> void:
mesh.material_overlay = material
func _on_mouse_exited() -> void:
mesh.material_overlay = null
Thank you! But I need the gd-shader
If you have a texture that’s got a white shape with a black shadow and alpha, if you modulate that with some color the black will stay black and the white will take on whatever color you modulate with.
If you make the shadow dark grey instead of black, it’ll take on some of the modulation color.
This is probably the best tutorial on outline shaders that exists for Godot 4. The X-Rays part will get you what you’re looking for I believe, but follow the whole thing. You may have to re-import your models after changing your model’s normals in blender to get outlines to work properly.
I’ll check it, thank you!
I was going to recommend using a theme, as a StyleBoxTexture would allow for adding a shadow.
but what you want is an animation that goes from a colored gun to full white? over a period of time?
in that case you need a custom shader, but not one that is removed but one that is always assigned.
then create a different scene with a different texture for each gun, or you can create a single texture with all the guns and UV shift to change them.
in godot 4.4 they introduced instancing for 2D. I haven’t tested it yet, but they allow you to change uniforms of a shader for each object assigned to a material.
alternatively you can just change the uniform for the whole material.
code would look similar to @dragonforge-dev example, but do something different:
this is an example from my game:
func overheat(amount : float = 0.0) -> void:
(heat.material as ShaderMaterial).set_shader_parameter("blur", amount)
shader_type canvas_item;
uniform sampler2D tex : source_color, filter_linear_mipmap;
uniform float speed : hint_range(0.0, 8.0) = 1.0;
uniform float blur : hint_range(0, 4.0) = 0.0;
void fragment() {
vec4 col = textureLod(tex, UV, sin(TIME * speed) * blur);
COLOR = col;
}
let me try writing some code, you will have to type it again in editor to fix any errors with the autocomplete:
extends TextureRect
var current_value : float = 0.0
func _on_mouse_entered() -> void:
var tween : Tween = create_tween()
tween.tween_method(change_uniform, current_value, 1.0, 0.4)
func _on_mouse_exited() -> void:
var tween : Tween = create_tween()
tween.tween_method(change_uniform, current_value, 0.0, 0.4)#you might need a second function that does exactly the same but with a different name, if there is a glitch
func change_uniform(_val : float) -> void:
current_value = _val
(material as ShaderMaterial).set_shader_parameter("shine", _val)
shader_type canvas_item;
uniform sampler2D tex : source_color, filter_linear_mipmap;
uniform float shine : hint_range(0, 1.0) = 0.0;
uniform vec4 shine_color : source_color;
void fragment() {
vec4 col = mix(texture(tex, UV), shine_color, shine);
COLOR = col;
}
you could also use a texture for the second state of the gun indicator instead of a color:
shader_type canvas_item;
uniform sampler2D tex : source_color, filter_linear;
uniform float shine : hint_range(0, 1.0) = 0.0;
uniform sampler2D shine_color : source_color, filter_linear;
void fragment() {
vec4 col = mix(texture(tex, UV), texture(shine_color, UV), shine);
COLOR = col;
}