godot icon indicating copy to clipboard operation
godot copied to clipboard

Can't add a `CompositorEffect` to a `Compositor`

Open thompsop1sou opened this issue 1 year ago • 12 comments

Tested versions

v4.3.dev4.official [df78c0636]

System information

Godot v4.3.dev4 - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3050 Ti Laptop GPU (NVIDIA; 31.0.15.3734) - AMD Ryzen 7 5800H with Radeon Graphics (16 Threads)

Issue description

I have been following https://github.com/godotengine/godot/pull/80214 and saw that it was recently closed. Hoping to try it out, I downloaded 4.3 dev4. However, I can't seem to add a CompositorEffect to the Compositor. I've tried using both the editor and GDScript, but neither works. Maybe there's something I'm missing on how this is supposed to work?

Using the Editor

First, in the editor, when attempting to add a new CompositorEffect to the compositor_effects array, it will only allow me to load one already created (can't create a new one).

image

So I tried to create one from the file system dock using "New Resource...", but CompositorEffect doesn't show up in the list of available resources.

image

Using GDScript

Finally, I tried to do it from GDScript. I created a new Compositor resource and added a script to it. Then I put it in my main scene. Although I was able to create a new CompositorEffect from script, I wasn't able to add it to the compositor_effects array.

extends Compositor

func _init() -> void:
	print(compositor_effects)
	# Trying to add a CompositorEffect via code
	var compositor_effect := CompositorEffect.new()
	print(compositor_effect)
	# This doesn't work
	compositor_effects.append(compositor_effect)
	print(compositor_effects)
	# This also doesn't work (even though the array currently has a null value in the first element)
	compositor_effects[0] = compositor_effect
	print(compositor_effects)

Steps to reproduce

  1. From the file system dock, create a new Compositor resource.
  2. In the new Compositor resource, add an empty element to the compositor_effects array.
  3. Add the following script to the new Compositor resource:
extends Compositor

func _init() -> void:
	print(compositor_effects)
	# Trying to add a CompositorEffect via code
	var compositor_effect := CompositorEffect.new()
	print(compositor_effect)
	# This doesn't work
	compositor_effects.append(compositor_effect)
	print(compositor_effects)
	# This also doesn't work (even though the array currently has a null value in the first element)
	compositor_effects[0] = compositor_effect
	print(compositor_effects)
  1. Create a new 3D scene.
  2. Add a WorldEnvironment node to the scene.
  3. In the WorldEnvironment node, add the Compositor that was created above.

Minimal reproduction project (MRP)

compositor-test.zip

thompsop1sou avatar Mar 01 '24 03:03 thompsop1sou

I can confirm that the same thing is happening to me...

JekSun97 avatar Mar 01 '24 04:03 JekSun97

Try @tool with class_name. 图片 Demo: https://github.com/godotengine/godot-demo-projects/pull/942 https://github.com/BastiaanOlij/RERadialSunRays

scgm0 avatar Mar 01 '24 08:03 scgm0

Try @tool with class_name.

The problem is that I can't even create a CompositorEffect resource, let alone add a script to it. I wrote a script for a Compositor because I thought that might allow me to work around the editor and create and add a CompositorEffect from code.


I was finally able to add a CompositorEffect to the compositor_effects array by setting the entire array directly using assignment. The updated script:

extends Compositor

func _init() -> void:
	print(compositor_effects)
	# Trying to add a CompositorEffect via code
	var compositor_effect := CompositorEffect.new()
	print(compositor_effect)
	# This doesn't work
	compositor_effects.append(compositor_effect)
	print(compositor_effects)
	# This also doesn't work (even though the array currently has a null value in the first element)
	compositor_effects[0] = compositor_effect
	print(compositor_effects)
	# This DOES seem to work (but not showing up in editor)
	compositor_effects = [compositor_effect]
	print(compositor_effects)

The above script prints the following out when the project is run:

[<Object#null>]
<CompositorEffect#-9223372009642130200>
[<Object#null>]
[<Object#null>]
[<CompositorEffect#-9223372009642130200>]

So for now, it seems like this might be a possible workaround through code. But I'm assuming it should still be possible to create a CompositorEffect from the editor.

thompsop1sou avatar Mar 01 '24 09:03 thompsop1sou

Try @tool with class_name.

The problem is that I can't even create a CompositorEffect resource, let alone add a script to it. I wrote a script for a Compositor because I thought that might allow me to work around the editor and create and add a CompositorEffect from code.

I was finally able to add a CompositorEffect to the compositor_effects array by setting the entire array directly using assignment. The updated script:

extends Compositor

func _init() -> void:
	print(compositor_effects)
	# Trying to add a CompositorEffect via code
	var compositor_effect := CompositorEffect.new()
	print(compositor_effect)
	# This doesn't work
	compositor_effects.append(compositor_effect)
	print(compositor_effects)
	# This also doesn't work (even though the array currently has a null value in the first element)
	compositor_effects[0] = compositor_effect
	print(compositor_effects)
	# This DOES seem to work (but not showing up in editor)
	compositor_effects = [compositor_effect]
	print(compositor_effects)

The above script prints the following out when the project is run:

[<Object#null>]
<CompositorEffect#-9223372009642130200>
[<Object#null>]
[<Object#null>]
[<CompositorEffect#-9223372009642130200>]

So for now, it seems like this might be a possible workaround through code. But I'm assuming it should still be possible to create a CompositorEffect from the editor.

You need to inherit CompositorEffect and write your own CompositorEffect, then use the CompositorEffect that you wrote. 图片

You can refer to the demo link I gave before to see how to write a custom CompositorEffect.

scgm0 avatar Mar 01 '24 09:03 scgm0

You need to inherit CompositorEffect and write your own CompositorEffect, then use the CompositorEffect that you wrote. 图片

Ah, thank you. That does work.

However, seems like you should be able to create a built-in CompositorEffect from the editor without first having to extend it with your own script. Or is that just how this feature works?

thompsop1sou avatar Mar 01 '24 10:03 thompsop1sou

You need to inherit CompositorEffect and write your own CompositorEffect, then use the CompositorEffect that you wrote. 图片

Ah, thank you. That does work.

However, seems like you should be able to create a built-in CompositorEffect from the editor without first having to extend it with your own script. Or is that just how this feature works?

I think it should be like this. You must use a custom CompositorEffect, which itself has no effect, and there is currently no built-in CompositorEffect with effects.

scgm0 avatar Mar 01 '24 10:03 scgm0

A small note on the docs clarifying this has to be extended would help I think

AThousandShips avatar Mar 01 '24 10:03 AThousandShips

You need to inherit CompositorEffect and write your own CompositorEffect, then use the CompositorEffect that you wrote. 图片

Ah, thank you. That does work.

However, seems like you should be able to create a built-in CompositorEffect from the editor without first having to extend it with your own script. Or is that just how this feature works?

I think it should be possible to have a button that creates a "new" CompositorEffect which is just a GDScript file that extends CompositorEffect. It would also be nice to have a similar shortcut in the "new resource" dialogue.

It is understandable why creating CompositorEffects is the way it is right now. But I think the workflow can definitely be improved.

We also need to prepare a detailed doc on creating and using CompositorEffects

clayjohn avatar Mar 02 '24 02:03 clayjohn

However, seems like you should be able to create a built-in CompositorEffect from the editor without first having to extend it with your own script. Or is that just how this feature works?

Indeed, that is how it works. The CompositorEffect class just forms the base giving you entry points where you implement the logic for an effect. In order to write that logic you'll need an implementation, hence needing to extent in GDScript or create a GDExtension for it.

I hope to get time to do some documentation for this soon, I do have a substantial demo project here: https://github.com/BastiaanOlij/RERadialSunRays And while its a long watch, I go over the demo project in detail here: https://www.youtube.com/watch?v=insa9VY0ruA

BastiaanOlij avatar Mar 03 '24 22:03 BastiaanOlij

Hey guys, I would like to contribute regarding this! Is a quick glance of how to create and use a derived/extended CompositorEffect be enough for this? I'm really new to FOSS contribution, can you lemme know if we have any structure or rules to follow before getting started on contributing?

Thanks a lot in advance!

ArceusMaxis avatar Mar 12 '24 17:03 ArceusMaxis

Hey guys, I would like to contribute regarding this! Is a quick glance of how to create and use a derived/extended CompositorEffect be enough for this? I'm really new to FOSS contribution, can you lemme know if we have any structure or rules to follow before getting started on contributing?

Thanks a lot in advance!

https://docs.godotengine.org/en/latest/contributing/ways_to_contribute.html

scgm0 avatar Mar 12 '24 17:03 scgm0

~~Is this known not to currently work with C#? I did basically a direct translation to C# from https://github.com/BastiaanOlij/RERadialSunRays and I can't get it to work. I even tried manually adding sections to the scene file to reference it, but then I get the error "Failed to set a resource of the type 'CompositorEffect' because this EditorResourcePicker only accepts 'CompositorEffect' and its derivatives".~~

EDIT: Turns out it does work. You need to use the [GlobalClass] attribute in C#. -- Thanks @raulsntos

jamesdimick avatar Apr 25 '24 02:04 jamesdimick