-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Expose access to 3D color buffer through ViewportTexture #90811
base: master
Are you sure you want to change the base?
Conversation
This allows users to keep their textures in linear color space and use the pre-tonemapped version
Should the checkbox "Disable 3D" be merged into the viewport mode enum as well? I assume there's no benefit to using 3D mode + Disable 3D checkbox in combination, for example. Or hide the property / show a configuration warning in such a case. |
That's a good question. We also have a In part because of how this would interact with
|
|
||
void Viewport::set_use_xr(bool p_use_xr) { | ||
ERR_MAIN_THREAD_GUARD; | ||
set_viewport_mode(p_use_xr ? VIEWPORT_MODE_XR : VIEWPORT_MODE_2D_AND_3D); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one change you need to do here is that if p_use_xr = false
, and viewport_mode != VIEWPORT_MODE_XR
, that you skip this. There is a high risk here that viewport_mode
is set to the required mode, but set_use_xr
is still called afterwards (loading properties for instance), and we end up unsetting the mode we want.
@@ -4752,7 +4776,8 @@ void Viewport::_bind_methods() { | |||
ClassDB::bind_method(D_METHOD("get_vrs_texture"), &Viewport::get_vrs_texture); | |||
|
|||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled"); | |||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_xr"), "set_use_xr", "is_using_xr"); | |||
//ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_xr"), "set_use_xr", "is_using_xr"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to keep use_xr
as a property but marked as deprecated for a few versions. We're going to be dealing with a lot of toolkits that need to work both with current and with older versions of Godot that use this property to enable XR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with just leaving it exposed for backwards compatibility. I commented it out just for testing, I will uncomment it before removing this PR from draft (if we decide to move forward with these changes)
@@ -1078,7 +1082,11 @@ RID RendererViewport::viewport_get_texture(RID p_viewport) const { | |||
const Viewport *viewport = viewport_owner.get_or_null(p_viewport); | |||
ERR_FAIL_NULL_V(viewport, RID()); | |||
|
|||
return RSG::texture_storage->render_target_get_texture(viewport->render_target); | |||
if (viewport->viewport_mode == RS::VIEWPORT_MODE_2D_AND_3D || viewport->render_buffers.is_null()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm guessing this should return our render target also when viewport_mode == RS::VIEWPORT_MODE_XR && view_count = 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to ask you about that. I have no idea what the expected return value should be when using the XR mode.
From this comment it sounds like:
- If view_count is 1 return the render_target
- if view_count is greater then one then return something else?
@@ -265,7 +265,7 @@ void RendererViewport::_draw_viewport(Viewport *p_viewport) { | |||
|
|||
/* Camera should always be BEFORE any other 3D */ | |||
|
|||
bool can_draw_2d = !p_viewport->disable_2d && p_viewport->view_count == 1; // Stereo rendering does not support 2D, no depth data | |||
bool can_draw_2d = !p_viewport->disable_2d && p_viewport->view_count == 1 && p_viewport->viewport_mode == RS::VIEWPORT_MODE_2D_AND_3D; // Stereo rendering does not support 2D, no depth data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be true if viewport_mode == VIEWPORT_MODE_XR && view_count == 1
You probably want to change this to:
bool can_draw_2d = !p_viewport->disable_2d && ((p_viewport->view_count == 1 && p_viewport->viewport_mode == RS::VIEWPORT_MODE_XR) || p_viewport->viewport_mode == RS::VIEWPORT_MODE_2D_AND_3D);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though this may not be future proof, right now we only allow stereo rendering for XR, but hopefully in the future we'll allow stereo rendering outside of an XR viewport as well, so maybe
bool can_draw_2d = !p_viewport->disable_2d && p_viewport->view_count == 1 && (p_viewport->viewport_mode == RS::VIEWPORT_MODE_XR || p_viewport->viewport_mode == RS::VIEWPORT_MODE_2D_AND_3D);
is safer..
The point is that stereo rendering is what disables 2d, not the fact that it is an XR viewport.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. So maybe we can just do p_viewport->viewport_mode != RS::VIEWPORT_MODE_3D
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is part of the reason I am wary about this PR. We already have logic to disable 2D when "disable_2d" is set and when using XR with a greater than 1 view count. So it doesn't seem all that beneficial to add a new setting which controls the same thing.
Proper fix for: #54122
Supersedes: #61667 and #70970
This PR does a few things:
Open Questions
Alternative approach
Building on question 3 above, we could change this PR to instead expose a similar set of options in the ViewportTexture itself: "2D and 3D", 3D, Depth, Normal-Roughness. Then users can use the ViewportTexture with whatever buffer they want.
In the Viewport API, we already have options to disable 2D if we want. So we could leave the questions of disabling 2D/3D in the Viewport and the question of what texture to expose to the ViewportTexture. To me, exposing these through ViewportTexture seems a bit cleaner and it doesn't carry implications for what rendering/processing is done. Further, users could also access multiple buffers from the same Viewport which I think is very important.
Example
In the below scene, the mesh has a red emission with a strength of 10. As expected, when dividing by 10 in "2D and 3D" mode, the color ends up quite dark as the color range is clipped to 0-1. When using the "3D" mode, the color is not clipped, so dividing by 10 restores it to the expected color
"2D and 3D" mode (same as current master)
New "3D" mode