-
-
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
Add access to the viewport's G-buffers (and depth). #38926
base: 3.x
Are you sure you want to change the base?
Conversation
…e to Viewport. With this addition, the G buffers in viewports, and the depth buffer, are now accesible textures that can be used in shaders.
Regarding CI - it failed on clang format and/or documentation, if I am reading it correctly. |
Yeah, the error it's giving is kinda confusing, this is my first time using the Clang. I can't tell what exactly is not right with the formatting in the code parts it's highlighting. :/ |
@SIsilicon This is probably due to trailing whitespace. Make sure you don't have trailing whitespace in your local copy. PS: If you want to stage all changes in a repository but ignore whitespace changes, add the following alias to Git by editing the [alias]
addnw = !sh -c 'git diff -U0 -w --no-color "$@" | git apply --cached --ignore-whitespace --unidiff-zero -' Then use |
Sorry for the commits. I have no idea how to do the check locally myself. |
Ok, thanks for pointing all that out @clayjohn . I guess I was a little messy with my code. 😅 |
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.
Looking good so far!
As you'll see from my comments, I am concerned about the constant memory/performance impact this PR would have. However, I think any performance issues can be addressed with a slight API change.
Right now the extra textures are created regardless of whether the user is using mrts, and then if mrts are used the blits take place automatically, even if the textures are not read. Even if a user does not use mrts, they can force mrts in order to copy the textures. The problem there is that they are then forced to calculate mrts even if there scene doesn't benefit from them.
I suggest instead exposing a boolean expose_textures
, the textures would only be exposed when expose_textures
is true. Further, you would only expose the textures that would be used (so mrts will only be exposed when mrts are used). Your block in render_scene
would become (in psuedo-code):
if (expose_textures) {
//blit color
//blit depth
if (use_mrts) {
//blit mrts
}
}
Note: this is just my view of a better API, making the requested changes doesn't guarantee that this will be merged. The final decision is up to reduz and not me.
Technically, color is already exposed, and depth already had its own texture, so they wouldn't need to be explicitly exposed. This would make more sense for the gbuffers however, as as you said before, their textures may not always be accessed. So how about this?
Again, thanks for the feedback. I'll make the necessary changes tomorrow. 🙂 |
Yea, that sounds good. I think lots of people are familiar with the term "g buffers". The important thing is making sure that this change is zero cost for people who won't use it. |
Now the buffers will only be created when `expose_gbuffer` is enabled in a Viewport. Plus texture swizzling on the depth buffer will no longer attempt to happen in WebGL.
Don't mean to add noise, just wondering if there is anything still blocking this? I need this for a feature and it looks like it just keeps getting pushed back |
This feature needs to be reimplemented on the As said above, SIsilicon does not have access to a GPU that runs Vulkan. This means they can't look into implementing this in Even if merging this PR for |
I understand, thanks for clarifying the situation! |
Actually my GPU doesn't support vulkan either, so it was support in the 3.x series I was hoping for 🙂 but it wouldn't be merged if a viable implementation existed for 4.0 too? Any way one can throw money at this and maybe someone else will take a look at vulkan? Does the Godot project use bounty source or equivalent? |
This PR would most likely be merged in
Godot does not use a bounty system, and there are no plans to add one. |
71cb8d3
to
c58391c
Compare
@SIsilicon This is really amazing work. Small remarks:
Also: Would there be a way to access the buffers directly in a screen shader, without having to create ViewportTexture uniforms? |
Just mentioning that this PR would make effects such as https://godotengine.org/qa/123831/how-to-do-outline-and-overlay-of-3d-meshes possible (or significantly easier and more performant) |
hello!! any updates on this? (for godot 4 specifically) |
This PR needs a reimplementation from scratch for Godot 4, but SIsilicon no longer seems to be available to do this. Also, a reimplementation would need significant design changes to follow what's being done in #80214. |
i see, thank you!! |
With this addition, the G buffers in viewports, and the depth buffer, are now accessible textures that can be used in shaders.
Using the new
buffer_mode
property inViewportTexture
, the following buffers are now accessible, including the defaultColor
buffer.It is now possible to do various mid-processing effects, such as this.
There is also an
expose_gbuffer
variable inViewport
that enables access to the G-buffers, with some exceptions.Bugsquad edit: This closes godotengine/godot-proposals#798.