image filter and shader
Asked Answered
K

4

0

The image loses the filter once a shader is applied Is there a way to fix it ? Ive tried multiple thing adding a view port... a sprite with a view port texture...

and the result is always the same i cant add the filter on top of the image after the shader is drawn ? also there doesnt seem to be an option to add multiple shaders ?

FILTER ON

FILTER OFF

Kinny answered 15/3, 2022 at 16:29 Comment(0)
C
0

also there doesnt seem to be an option to add multiple shaders ?

Godot doesn't support multipass shaders yet, so you have to use multiple Sprite nodes overlaid on top of each other.

Chapbook answered 15/3, 2022 at 18:8 Comment(0)
K
0

@Calinou said:

also there doesnt seem to be an option to add multiple shaders ?

Godot doesn't support multipass shaders yet, so you have to use multiple Sprite nodes overlaid on top of each other.

thanks for the reply, Using "multiple Sprite nodes behind the main sprite, with a diferent color in order to give an outline effect" its the same thing the shader is doing in code ?

Could the shader be added in code in a node2D ? Ive tried doing although maybe important thing are missing like draw_texture rotation degrees ?

extends Node2D

var sprite1 = preload('res://sprites/spr_BaseTESTE.png');
var sprite2 = preload('res://sprites/PlayerAllAnimsFinal.png');

func _draw():
	draw_texture(sprite1, Vector2(position.x, position.y));
	draw_texture(sprite2, Vector2(position.x, position.y));

anyway i manage to get it working with a better version of the shader this way it seems to draw the line correctly around the filter image...

! ! shader_type canvas_item; !
! uniform float width : hint_range(0.0, 10.0); ! uniform vec4 outline_color : hint_color; !
! void fragment() ! { ! vec2 size = vec2(width) / vec2(textureSize(TEXTURE, 0)); ! vec4 sprite_color = texture(TEXTURE, UV); !
! float alpha = sprite_color.a; ! alpha += texture(TEXTURE, UV + vec2(0.0, -size.y)).a; ! alpha += texture(TEXTURE, UV + vec2(size.x, -size.y)).a; ! alpha += texture(TEXTURE, UV + vec2(size.x, 0.0)).a; ! alpha += texture(TEXTURE, UV + vec2(size.x, size.y)).a; ! alpha += texture(TEXTURE, UV + vec2(0.0, size.y)).a; ! alpha += texture(TEXTURE, UV + vec2(-size.x, size.y)).a; ! alpha += texture(TEXTURE, UV + vec2(-size.x, 0.0)).a; ! alpha += texture(TEXTURE, UV + vec2(-size.x, -size.y)).a; !
! vec3 final_color = mix(outline_color.rgb, sprite_color.rgb, sprite_color.a); ! COLOR = vec4(final_color, clamp(alpha, 0.0, 1.0)); ! } ! !

But combining muitiple sprites with an outLine shader seems a confusing process... Once the sprites are in a viewPort they will lose the filter... The only way to get filter back is use a sprite with a view port texture anywere in the tree...

maybe there is a simpler solution to make this entire process.. ?

Kinny answered 15/3, 2022 at 18:57 Comment(0)
C
0

the problem is filter option is not avaible to choose in viewPort

You can remove the filter flag from the ViewportTexture at run-time using a script:

$Path/To/SpriteNode.texture.flags &= ~Texture.FLAG_FILTER

This must be done from a script, as changes to texture flags within the editor are not persisted to disk.

Chapbook answered 15/3, 2022 at 20:2 Comment(0)
K
0

@Calinou said:

the problem is filter option is not avaible to choose in viewPort

You can remove the filter flag from the ViewportTexture at run-time using a script:

$Path/To/SpriteNode.texture.flags &= ~Texture.FLAG_FILTER

This must be done from a script, as changes to texture flags within the editor are not persisted to disk.

I was trying to add the filter to the viewport, withOut having to create a sprite viewPort texture... It seems to much extra confusion... I was trying to make this...

but instead of using scaleX and scaleY to deform the image, i would use the sekelton bones to deform the polygon... but i dont know why

Kinny answered 15/3, 2022 at 20:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.