Allow materials to read from a depth texture #2474
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Requries armory3d/iron#160.
This PR implements what was discussed in #1817. Materials now can specify that they want to read from the depth buffer. In this case, meshes with those materials are drawn last and before they are drawn, the depth buffer is copied to a dedicated depth texture that can then be sampled from a shader uniform called
depthtex
.It works on deferred and forward (Depth prepass on/off), with shadows and transparency, SSR and mesh batching. The only limitation I know is that on forward RP this doesn't work when the compositor is turned off because then the
rp_render_to_texture
define is undefined andlbuffer0
does not exist. I'm not sure whether this define should only be set for the compositor (as it also creates some other render targets for example) or whether it can be enabled for this feature as well. In general it's difficult to see what rendertargets and defines are used for what purpose, so please let me know if I should change something. Btw, what does thel
inlbuffer0
stand for?Tested on:
The entire depth texture feature can be toggled on or off in the renderpath settings:
My next goal is to implement the possibility to allow defining samplers/texture units in custom materials via the UI (because they are defined in the mat data .json and not in the shader .json that the user can provide; also Khamake needs to know about the textures). Then it would be possible for example to create an underwater caustics volume together with the depth read feature.