1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-29 14:39:48 +00:00

Implement support for elapsed time in loaded shaders for layer effects

Simply add `uniform float PXO_time;` in the shader's uniforms, and replace all instances of `TIME` with `PXO_time`. This will make the shader animate per frame.
This commit is contained in:
Emmanouil Papadeas 2024-12-17 00:53:58 +02:00
parent fede8c3e49
commit 11ae7c007b
4 changed files with 15 additions and 2 deletions

View file

@ -24,6 +24,13 @@ func get_final_opacity(layer: BaseLayer) -> float:
return layer.opacity * opacity
func get_frame(project: Project) -> Frame:
for frame in project.frames:
if frame.cels.has(self):
return frame
return null
# Methods to Override:

View file

@ -234,8 +234,10 @@ func display_effects(cel: BaseCel, image_override: Image = null) -> Image:
for effect in effects:
if not effect.enabled or not is_instance_valid(effect.shader):
continue
var params := effect.params
params["PXO_time"] = cel.get_frame(project).position_in_seconds(project)
var shader_image_effect := ShaderImageEffect.new()
shader_image_effect.generate_image(image, effect.shader, effect.params, image_size)
shader_image_effect.generate_image(image, effect.shader, params, image_size)
# Inherit effects from the parents, if their blend mode is set to pass through
for ancestor in get_ancestors():
if ancestor.blend_mode != BlendModes.PASS_THROUGH:

View file

@ -62,6 +62,8 @@ static func create_ui_for_shader_uniforms(
var u_init := u_left_side[0].split(" ")
var u_type := u_init[1]
var u_name := u_init[2]
if u_name == "PXO_time":
continue
# Find custom data of the uniform, if any exists
# Right now it only checks if a uniform should have another type of node
# Such as integers having OptionButtons

View file

@ -177,8 +177,10 @@ func _apply_effect(layer: BaseLayer, effect: LayerEffect) -> void:
undo_data[cel_image.indices_image] = cel_image.indices_image.data
undo_data[cel_image] = cel_image.data
var image_size := cel_image.get_size()
var params := effect.params
params["PXO_time"] = frame.position_in_seconds(project)
var shader_image_effect := ShaderImageEffect.new()
shader_image_effect.generate_image(cel_image, effect.shader, effect.params, image_size)
shader_image_effect.generate_image(cel_image, effect.shader, params, image_size)
var tile_editing_mode := TileSetPanel.tile_editing_mode
if tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL: