So now basically I've created a new sprite via script and I need to assign a shader and manipulate it how can I do that please?
Thank you very much in advance again
This is what I have but it doesn't work
var mat = CanvasItemMaterial.new() const skew_shader = preload("res://shaders/shearing_shader.tres")
'----inside function
mat.set_shader(skew_shader) sprite_p.set_material(mat)
Maybe try using a ShaderMaterial (documentation) instead of a CanvasItemMaterial?
ShaderMaterial
CanvasItemMaterial
Yeah, IIRC CanvasItemMaterial is for the default builtin shader.
ok, I have no errors but it doesn't produce any result
@TwistedTwigleg said: Maybe try using a ShaderMaterial (documentation) instead of a CanvasItemMaterial?
I 've been trying even another way but nothing, It doesn't produce any result, no errors but even no result
What is your actual shader like?
@Megalomaniak said: What is your actual shader like?
it is about image manipulation. But it works , it doesn't when just called by this script
The result of the shader is supposed to be applied/written to an image via the script then? What node specifically is holding the image buffer? A viewport?
no it is an Area2D, so we have:
--Area2D ----AnimatedSprite
Hi I tried something like that and it works, the shader is assigned on sprite via script Hope that's help
script on Node2D
func _ready(): $Sprite.material = ShaderMaterial.new() $Sprite.material.shader = preload("res://test_shader.tres")
shader test
shader_type canvas_item; void fragment() { COLOR.rgb = vec3(5.0, 0.1, 0.2); }
shader_type canvas_item;
void fragment() { COLOR.rgb = vec3(5.0, 0.1, 0.2); }
@LeeWee said: Hi I tried something like that and it works, the shader is assigned on sprite via script Hope that's help script on Node2D func _ready(): $Sprite.material = ShaderMaterial.new() $Sprite.material.shader = preload("res://test_shader.tres") shader test shader_type canvas_item; void fragment() { COLOR.rgb = vec3(5.0, 0.1, 0.2); }
@LeeWee said: Hi I tried something like that and it works, the shader is assigned on sprite via script Hope that's help
Yes but as you have written I cant understand. basically I have this function in loop
func render_(): var sprite_ref = $AnimatedSprite HERE I NEED TO ATTACH A SHADER to this sprite