Skip to content

Add per-viewport pre_draw and post_draw signals #1807

@Astrono2

Description

@Astrono2

Describe the project you are working on:
I'm working on a portal add-on.

Describe the problem or limitation you are having in your project:
I'm rendering the portals with viewports and extra cameras. My current problem is that each camera's view through a portal is obstructed by the portal itself (I've disabled back face culling for two-sided portals). It would be easy to solve this problem using layers and cull masks, but that would require anyone using my add-on to have a free layer for each portal, which scales poorly when adding more portals, and it makes the add-on clunkier to use.
The implementation I (as many others) am basing mine on (Sebastian Lague's) hides the portal plane before rendering the view form the camera and then shows it again, which he can do because he's rendering manually, which currently isn't possible in Godot.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Adding per-viewport pre_draw and post_draw signals wouldn't be as intrusive or big of a change as adding manual rendering, but it would still allow developers to hide and show objects before and after rendering a certain viewport.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
The already existing frame_pre_draw and frame_post_draw signals, get emitted at the beggining and end of the VisualServerRaster::draw and RenderingServerRaster::draw methods in 3.2 and master respectively. My proposal is to add two signals (pre_draw and post_draw) to the Viewport class and emit them at the beginning and end of VisualServerViewport::_draw_viewport and/or RenderingServerViewport::_draw_viewport methods (again, 3.2 and master respectively).
I haven't checked any signal related code in the source, and was worried that emitting two different signals at the beginning and end of a method wouldn't work. But since that's how frame_pre_draw and frame_post_draw work, it seems like it's that easy, if people are interested I can make the pull request.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
As far as I know, no. For my project I'm gonna try to make a hacky workaround, since I want it to work without using a custom build. But I'm still thinking about how to do it, I'm open to suggestions. Maybe I'll just try to achieve the same result with a different approach, but I figure these two signals would be pretty useful for other projects anyway.

Is there a reason why this should be core and not an add-on in the asset library?:
I don't know if it can be done with an add-on at all. I'm going to try, but even if it works, it's not going to be pretty. Implementing this in core is the easier alternative.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions