-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add masking support (let one Actor mask others) #56
Comments
Hmm, doing more testing in my test project (added a SubViewport), and it seems related to the |
Actually, we just need to stop using our custom shader for Actors that are acting as masks (they aren't displayed anyhow, so we don't need our custom colour-tweaking behaviour). I got the basic version working now, still need to fine-tune it a bit, but at least it seems to work! Recording.2024-06-06.actor.masking.mp4 |
I've also discovered lots of problems with Actors as children will now always be parented under the "Animation" ( There were also lots of problems with transforms getting messed up when parenting and unparenting, especially when taking into account multi-level hierarchies. Now parenting/unparenting and masking/unmasking should all leave the parent and child with the same (global) transform. Note that the current transform commands (to move, rotate, scale, etc.) are all working locally (in the parent's space). This is good...but at some point we may want to add global versions of them. For example, when you are masking, you may want to transform the masked Actors globally. (both types of transform are useful to have -- @loopier made a comment that you can work around by unparenting, transforming and reparenting, but I find this a bit "heavy"...would be nicer to expose the global transform commands themselves!) Also, currently the |
One other thing I noticed (but didn't change)...the For example, suppose you have Actors drawn in this order: If you want any of those other changes, maybe open new issues for them, so I stop "contaminating" this issue about masking.... ;-) |
My example test code (various permutations of these lines of code, and more):
|
- masking uses the `clip_children` functionality, which had to be made to work in the context of our use of SubViewport and custom shaders. - masking uses reparenting, so masked Actors become children of the Actor acting as mask. - also fixed numerous issues with (un)parenting, transforms getting messed up, node ordering. Now, the global transform of an Actor should remain constant before and after any kind of reparenting or masking. - also fixed issues related to reordering, including /front, /behind, /top and /bottom commands, and also artibrary depth hierarchies of Actors.
I think masking should be an opaque operation. When performing, the less thinking the better, so encapsulating the parenting for
I think this wasn't actually that bad, because you can target the front or back of an object, without having to know it's actual position in the overall stack. So in your example, you could send |
- this can happen if you /parent or /mask A to B and then B to A, it would introduce a cycle and also would detach the entire hierarchy from the scene graph. Now, if such a cycle is detected, /parent and /mask commands will return an error. - related to #56
Fixed an issue @loopier found, where it was possible to crash or lose Actors by doing a "cross-reparenting" (A as child of B, and B as child of A). This could also happen with longer chains of ancestry, like A-B-C and trying to parent A under C. I fixed it by detecting the potential cycle in the hierarchy and return an error to the user. |
This is not directly related to masking, but I'll mention it here before I close this issue. In 5008021 I exposed
See the note on that commit -- there is also a built-in |
This seems like a simple thing, but is not as simple as it seems. In Godot 3, one could use Light2D masks to do something like this. In Godot 4, there is a feature called clip children that seems like it should be able to do it (also related: CanvasGroup, that similarly uses the backbuffer). I've been able to get clipping to work in a simple test project using
clip_children
, but when I try it in Animatron I seem to get unreliable results. Sometimes it doesn't work at all as I'd expect, other times it works but doesn't take into account alpha in the child nodes. I don't know if this is related to the fact that we're rendering into a SubViewport, maybe(?).Here's how I want it to work (it works in a simple test project with a parent "cog" mask and a child "heart" image):
Here's what sometimes happens in Animatron with the same setup (alpha of the child is not erased, instead we see black):
I thought this might be related to the fact that we're using a custom shader, but if I remove that and use the default shader I still get the same problem.
There is a long and frustratingly unresolved thread related to this in a Godot proposal/issue:
godotengine/godot-proposals#4282
The text was updated successfully, but these errors were encountered: