-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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 new Parallax2D node #87391
Add new Parallax2D node #87391
Conversation
456a0ae
to
add5855
Compare
I just started with a feature to add number of repeats. This is to address the issue some users face when zooming out on an infinite repeat background since it only draws twice per. The performance isn't bad. Even with 8 layers with 5 repeats (36 copies per item per layer), it still performs better than Before: 2024-01-20.13-56-18.mp4After: 2024-01-20.13-57-15.mp4 |
a7bd784
to
47aa23d
Compare
Also added a highly requested 2024-01-21.17-58-32.mp4 |
Dumb question from the peanut gallery: Would this branch work for parallax of Nodes which draw themselves using 'draw_polygon' commands and the like? Or just for textures? Thanks for unpacking. |
47aa23d
to
d09fe93
Compare
@AThousandShips Thanks for the quick review! A lot of stuff I overlooked while having a million tabs open. @tartley Absolutely! |
i can't wait for this to get merged! i actually need this a lot for my game, i'd be glad to know if there was a way i could use it right ahead. |
@enderprism You can go to the "Checks" tab and download one of the build artifacts. I'd wait for it to be merged before using it for anything serious, since it hasn't been approved yet. If you would be willing to try it out and tell me if there's any issues or things I've overlooked, it would help out a lot! |
Thanks! Amazing work 🎉 |
Hooray, we will see this in next dev version🥳 Thanks a lot! |
Saw this in the 4.3 dev 5 changelog and tried playing around with it a little bit. I was wondering if it's possible to preview the parallaxing in the editor in the same way ParallaxBackground allows you? (This is done by changing the scaling under "follow viewport" and enabling "preview canvas scale" in the editor) |
The Parallax2D does not work correctly with multiple cameras/viewports. In one viewport I can see the background move correctly when the camera moves, but on the other viewport where the camera does not move, the background still moves. |
See the instructions here |
@Araraura I tried this with @cody82 I'm currently finishing a blog post touching on some of these topics. Some of the same drawbacks to |
I experience broken behavior on 4.3 dev5 when using the old ParallaxBackground, I have tried to strip down my project to illustrate the issue. Also I have so far sound it hard to replicate this behavior using the new node, I will likely have more time to elaborate tomorrow, Thanks for your time! |
@filkata Your zip file is being flagged and won't let me download it. Not sure why. If you can fix it I'll take a look. Though I'm glad that the problem is with |
@markdibarry Still I think a regression in the behavior of ParallaxBackground is not ok. Please try this link instead: https://drive.google.com/file/d/1MSKnS9JGnw3KpCmLP5y3ZU3LpNYPdS2i/view?usp=sharing |
@filkata Please open a separate issue about this as it makes it much easier to track and troubleshoot. |
Opened #89563 |
Trying it out in 4.3dev5, works great from my initial testing. Also not sure if this is in scope of the node, but maybe a sort of "perspective mode" could be nice to have? Basically, multiply the offset by the scroll scale. So with lower scroll scale, the object slowly goes towards the center, which can create a "building from above" effect. For this the toggle above could be important as it would let you input a custom center point. This is relatively easy to make yourself (so I left some code below), but it could be nice to have as a built-in feature. Example and Codeextends Node2D
@export var scroll_scale: Vector2 = Vector2.ONE
@export var scroll_offset: Vector2 = Vector2.ZERO
@onready var original_position: Vector2 = global_position
@onready var camera: Camera2D = get_viewport().get_camera_2d()
func _process(delta):
global_position.x = lerp(camera.get_screen_center_position().x + scroll_offset.x, original_position.x, scroll_scale.x)
global_position.x = lerp(camera.get_screen_center_position().y + scroll_offset.y, original_position.y, scroll_scale.y) Also I found documentation bug, |
@ettiSurreal I appreciate the feedback! This initial PR is mainly focused on being able to replicate the behavior of |
Testing works great as well for me on 4.3dev5. I haven't had any issues.
I also want to add to this and ask if we can have an option to scale objects according to perspective scale as well? So we can have objects appear smaller as their distance is further away. And on top of that, an equivalent to "Preview Canvas Scale" but for this instead, since we can't really preview the parallax effect in editor like we could with ParallaxBackground. This is mainly so we can preview the background as a pseudo-3D space. I'm not sure how much work that is, but it'd be nice to have, and is one big feature I feel is missing in this one. |
@Braveo This is some great feedback as well. This is a closed PR, and it'd be a shame for your findings to be ignored, so it'd be great if you could create a proposal or issue! While I'm here, though, I've heard the technique you mentioned once or twice, but I haven't found any official documentation on this (just a few random comments from users on forums). I also tried replicating it using EDIT: I was able to get similar results by just putting the |
btw I managed to recreate more or less the same thing using Parallax2D (it's easy using |
It's probably too late. But this guy made a plugin to preview parallax in the editor. I don't know if it can be replicated in the new system. |
That'd be up to the developer of that plugin to adjust to, if it's even needed, but that wouldn't really change the decision or progress of this PR, you should probably talk to them about this instead |
I think this is the only "official" mention: https://godotengine.org/article/godot-32-will-get-pseudo-3d-support-2d-engine/ |
God damn genius! This will be awesome! |
Hey, just because it was asked, and I'm current working with Parallax in my project. It was a huge problem for me working with parallax and split screen. Reason being, because parallax inherits from canvas layer, it makes its contents to be dependant on the viewport. |
@FrederickKDP Thanks for the interest! This PR is closed, so it'd be best to open a discussion regarding this. Feel free to tag me, since I'm currently looking at good ways to accomplish split screen easily! In the meantime, please take a look at this proposal to make this easier. godotengine/godot-proposals#10014 |
This is a new node, intended as a replacement for the current
ParallaxBackground
andParallaxLayer
workflow. In contrast toParallaxBackground
,Parallax2D
inherits fromNode2D
, which provides a few benefits over the old workflow:CanvasGroup
CanvasLayer
The inspiration for this was a few pain points regarding the old workflow. There's still a lot to work on, as I'd like some community feedback and to add some more (reasonable) helpful features, but this is a good start with feature parity to the old system. I have a few ideas to fix some more issues, like handling zoom-out repeats, and some editor guides, but this is a nice beginning.
This should close quite a few old open issues:
Fixes: #22453, fixes: #30988, fixes: #39347, fixes: #42586, fixes: #67120, fixes: #77827
Possibly fixes: #63352, #71701, #82380, #87317
Also implements the following proposal:
Closes: godotengine/godot-proposals#8779,
Closes: godotengine/godot-proposals#8107,
Closes: godotengine/godot-proposals#7237
Obviously, this is too much of a breaking change to flat out remove the old workflow, but with this the
ParallaxBackground
andParallaxLayer
nodes can be deprecated for removal in a later version. In the meantime, I was able to retrofit the new changes for mirroring intoParallaxBackground
, so users who aren't ready for a change can still benefit from a speed up. Here is my cursory benchmarks:2500-2600 FPS:
ParallaxBackground
with 8ParallaxLayer
s while scrolling (master branch)4100-4200 FPS:
ParallaxBackground
with 8ParallaxLayer
s while scrolling (Parallax2D branch)4400-4500 FPS: 8
Parallax2D
s while scrolling4900-5000 FPS: Empty scene
2024-01-19.22-01-46.mp4
Here it is working in a
CanvasGroup
:2024-01-19.22-06-14.mp4
Also thanks to our neighborhood svg wizard @MewPurPur for the quick work on an alternative icon!
Any and all feedback is welcome!