-
Notifications
You must be signed in to change notification settings - Fork 8
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
In-Game: Add support for accessing a surface's depth buffer #3708
Comments
I second this! +1 I would like to suggest that it is possible to get the depth information in the form of a surface, something like surface_get_zbuffer or surface_get_depth_buffer This will be particularly useful for a lot of things besides the ones mentioned, like creating lighting systems where the lights have depth, fog effects, color grading in specific areas, etc. |
Talking about depth buffer, there are cases where I want to draw on some extra surface, but keep my main buffer for it when drawing. So, I want to be able to share/copy-paste depth buffer around between different surfaces. Edit: I did deal with it in GMS1 by using Multiple Render Targets shader btw. But it's Windows-only. |
It'd be nice to be able to copy a surface to another along with its depth buffer. Not sure if it's possible to interpolate from surface to surface but copying to a larger buffer while retaining depth buffer info would be ideal. |
While at it, can we have a stencil buffer as well? Is useful for more tricky stuff where you need both z-buffer and some way to mask by already drawn pixels. |
Yep, having access to the stencil buffer would be awesome! |
If we're going to have this, then it'd be nice to have an optional argument for the standard code used to draw Sprites that sets the depth, rather than using the Instance Depth. |
That is not quite related to this issue. What you want is also already possible with function |
Implemented and merged for the 2024.6 release. ChangesDepth buffer functions
Stencil functions
Depth and stencil clearing functions
Buffer functions
Test projectFollowing is a project for testing whether all functions are working correctly: DepthStencilTest.zip. Since most of the tests are visual, I'm also attaching screenshots of what the results are supposed to look like:
Showcase project
|
Verified working as expected in Beta IDE v2024.600.0.562 Runtime v2024.600.0.580. Will move to Verified swim lane once docs are done. |
…get_tex_mip_enable page YoYoGames/GameMaker-Bugs#3708
YoYoGames/GameMaker-Bugs#3708 * Tiny typo fix on depth variable page
YoYoGames/GameMaker-Bugs#3708 * Finished draw_clear_depth function page
…tion page YoYoGames/GameMaker-Bugs#3708 * Finished draw_clear_depth function page
YoYoGames/GameMaker-Bugs#3708 * Added variables for default z-function, depth & stencil equation (+masks) and stencil operation constant
YoYoGames/GameMaker-Bugs#3708 * Added variables for default z-function, depth & stencil equation (+masks) and stencil operation constant
…le function name YoYoGames/GameMaker-Bugs#3708 * Changed page title to British English spelling and replaced occurrences
…page YoYoGames/GameMaker-Bugs#3708 * Listed new functions under reference * Added new section "Depth and Stencil buffer"
…nction page YoYoGames/GameMaker-Bugs#3708 * Rewrote short function description & added paragraph on depth buffer * Moved notes under "Usage Notes" section * Added optional parameter "depth"
…tencil_* function pages YoYoGames/GameMaker-Bugs#3708
…ce_get_depth_disable YoYoGames/GameMaker-Bugs#3708 * Updated surface_depth_disable page to include depth and stencil buffer * Minor changes to surface_get_depth_disable
…ce_get_depth_disable YoYoGames/GameMaker-Bugs#3708 * Moved zfunc table to snippet and linked it on the pages
…ce_get_depth_disable YoYoGames/GameMaker-Bugs#3708 * Listed gpu_get_stencil_* & gpu_set_stencil_* functions on GPU Control page
YoYoGames/GameMaker-Bugs#3708 * Added main page: The Depth and Stencil Buffer (including screenshots) * Added code snippet with linear depth conversion * Added RH variables for default settings, inserted on function pages
YoYoGames/GameMaker-Bugs#3708 * Documented the contents of the gpu_get_state/gpu_set_state DS Map * Some items left to add
YoYoGames/GameMaker-Bugs#3708 * Documented surface_get_texture_depth, including a full copy-paste code example * Tiny fix on The Depth And Stencil Buffer overview page
…t_state/gpu_set_state DS map YoYoGames/GameMaker-Bugs#3708 * Listed all keys and values on the gpu_set_state() page * Added RH variable for GPU State DS Map * Visual update of gpu_set_texrepeat() page
Added the depth & stencil buffer documentation to a new page under the "Drawing" section: "The Depth and Stencil Buffer". Updated existing function pages and added reference pages for all new functions, some of them including complete code examples. Various updates and improvements to related pages. Also documented the contents of the DS map used by |
…get_tex_mip_enable page YoYoGames/GameMaker-Bugs#3708 (cherry picked from commit 3a14db1)
…verview page YoYoGames/GameMaker-Bugs#3708 (cherry picked from commit 18c4e66)
Description
Create functions that would allow developers to gain access to the internal depth buffer texture of surfaces so that it could be referenced in deferred shaders. This would allow the already existing depth information to be used in a plethora of standard shader effects, such as screen space ambient occlusion (SSAO), screen space reflections (SSR), depth of field (DOF), shadow mapping, and several others.
Benefit
Currently in GMS2, the only way to effectively create these types of effects is to either use forward rendering and do all the processing on the pixels upfront (which isn't ideal in many situations), or use multiple channels in a custom surface to store the data again, wasting draw calls and GPU time just so the depth information can be accessed. This is a cumbersome, inefficient, non standard approach could be completely rectified by simply allowing access to the built in depth buffer that surfaces have.
This kind of change would probably also require the ability to change surface data types and precision, otherwise specific depth buffer surface functions would be needed.
Justification
I recommend expanding the surface structure to accommodate these changes as this will allow myself and other GMS2 developers unparalleled access to a plethora of common graphics techniques and not have to use hacky, confusing, and difficult work around methods to achieve them.
Other very popular game engines already have this functionality and GMS2 is sorely lacking.
Thank you for your time.
The text was updated successfully, but these errors were encountered: