From a3943b722be6777e673557b1cd06f444bbfadd2b Mon Sep 17 00:00:00 2001 From: Digvijaysinh Gohil Date: Thu, 22 Feb 2024 16:29:08 +0530 Subject: [PATCH] #4 resolved --- README.md | 4 +--- addons/ShaderLib/UV/FlipbookUV.gd | 20 ++++++-------------- addons/ShaderLib/UV/FlipbookUV.gdshaderinc | 6 ++++-- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f4793f7..6b56f82 100644 --- a/README.md +++ b/README.md @@ -294,7 +294,7 @@ Default value for uv input will be vec2(0, 0) for shader modes PARTICLES,

Flipbook node

Creates a flipbook, or texture sheet animation, of the UVs supplied to input UV. The amount of tiles on the sheet are defined by the values of the inputs rows and columns. -This node can be used to create a texture animation functionality, commonly used for particle effects and sprites.

This node is only available in shader modes SPATIAL and CANVAS ITEM. +This node can be used to create a texture animation functionality, commonly used for particle effects and sprites. Animation frames will go from top left to bottom right.

This node is only available in shader modes SPATIAL and CANVAS ITEM.
**Inputs** @@ -303,8 +303,6 @@ This node can be used to create a texture animation functionality, commonly used |uv|vec2|UV|Input UV value| |rows|int|none|Amount of horizontal tiles in texture sheet| |columns|int|none|Amount of vertical tiles in texture sheet| -|start frame|int|none|Start tile index texture sheet| -|end frame|int|none|End tile index texture sheet| |anim speed|float|none|Animation speed| **Outputs** diff --git a/addons/ShaderLib/UV/FlipbookUV.gd b/addons/ShaderLib/UV/FlipbookUV.gd index 357eccc..ee41c0d 100644 --- a/addons/ShaderLib/UV/FlipbookUV.gd +++ b/addons/ShaderLib/UV/FlipbookUV.gd @@ -4,9 +4,7 @@ class_name VisualShaderNodeUVFlipbook extends VisualShaderNodeCustom func _init() -> void: set_input_port_default_value(1, 1) set_input_port_default_value(2, 1) - set_input_port_default_value(3, 0) - set_input_port_default_value(4, 0) - set_input_port_default_value(5, 0.1) + set_input_port_default_value(3, 0.1) set_output_port_for_preview(0) @@ -23,7 +21,7 @@ func _get_return_icon_type() -> VisualShaderNode.PortType: return PORT_TYPE_VECTOR_2D func _get_input_port_count() -> int: - return 6 + return 4 func _get_input_port_name(port: int) -> String: match port: @@ -34,10 +32,6 @@ func _get_input_port_name(port: int) -> String: 2: return "columns" 3: - return "start frame" - 4: - return "end frame" - 5: return "anim speed" return "" @@ -45,9 +39,9 @@ func _get_input_port_type(port: int) -> VisualShaderNode.PortType: match port: 0: return PORT_TYPE_VECTOR_2D - 1, 2, 3, 4: + 1, 2: return PORT_TYPE_SCALAR_INT - 5: + 3: return PORT_TYPE_SCALAR return PORT_TYPE_SCALAR @@ -85,8 +79,6 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad var rows: String = input_vars[1] var columns: String = input_vars[2] - var start_frame: String = input_vars[3] - var end_frame: String = input_vars[4] - var anim_speed: String = input_vars[5] + var anim_speed: String = input_vars[3] - return output_vars[0] + " = flipbook_uv(%s, %s, %s, %s, %s, %s);" % [uv, rows, columns, start_frame, end_frame, anim_speed] + return output_vars[0] + " = flipbook_uv(%s, %s, %s, %s);" % [uv, rows, columns, anim_speed] diff --git a/addons/ShaderLib/UV/FlipbookUV.gdshaderinc b/addons/ShaderLib/UV/FlipbookUV.gdshaderinc index 7a62c5c..b323eb7 100644 --- a/addons/ShaderLib/UV/FlipbookUV.gdshaderinc +++ b/addons/ShaderLib/UV/FlipbookUV.gdshaderinc @@ -1,4 +1,6 @@ -vec2 flipbook_uv(vec2 uv, int rows, int columns, int start_frame, int end_frame, float anim_speed){ +vec2 flipbook_uv(vec2 uv, int rows, int columns, float anim_speed){ + int start_frame = 1; + int end_frame = rows * columns; start_frame += int(fract(TIME * anim_speed) * float(end_frame)); float _frame = float(clamp(start_frame, 0, end_frame)); vec2 _off_per_frame = vec2((1.0 / float(columns)), (1.0 / float(rows))); @@ -7,7 +9,7 @@ vec2 flipbook_uv(vec2 uv, int rows, int columns, int start_frame, int end_frame, _current_sprite.x += _frame * _off_per_frame.x; float _row_index; float _mod = modf(_frame / float(columns), _row_index); - _current_sprite.y -= _row_index * _off_per_frame.y; + _current_sprite.y -= 1.0 - (_row_index * _off_per_frame.y); _current_sprite.x -= _row_index * float(columns) * _off_per_frame.x; vec2 _sprite_uv = (_sprite_size + _current_sprite); return _sprite_uv;