Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add a CompositorEffect to a Compositor #89030

Closed
thompsop1sou opened this issue Mar 1, 2024 · 12 comments · Fixed by #95347
Closed

Can't add a CompositorEffect to a Compositor #89030

thompsop1sou opened this issue Mar 1, 2024 · 12 comments · Fixed by #95347

Comments

@thompsop1sou
Copy link

thompsop1sou commented Mar 1, 2024

Tested versions

v4.3.dev4.official [df78c06]

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 #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

@JekSun97
Copy link

JekSun97 commented Mar 1, 2024

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

@scgm0
Copy link
Contributor

scgm0 commented Mar 1, 2024

@thompsop1sou
Copy link
Author

thompsop1sou commented Mar 1, 2024

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.

@scgm0
Copy link
Contributor

scgm0 commented Mar 1, 2024

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.

@thompsop1sou
Copy link
Author

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?

@scgm0
Copy link
Contributor

scgm0 commented Mar 1, 2024

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.

@AThousandShips
Copy link
Member

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

@AThousandShips AThousandShips added this to the 4.3 milestone Mar 1, 2024
@clayjohn
Copy link
Member

clayjohn commented Mar 2, 2024

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

@BastiaanOlij
Copy link
Contributor

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

@ArceusMaxis
Copy link
Contributor

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!

@scgm0
Copy link
Contributor

scgm0 commented Mar 12, 2024

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

@jamesdimick

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants