Skip to content
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

Allow materials to read from a depth texture #2474

merged 2 commits into from
Apr 6, 2022


Copy link

@MoritzBrueckner MoritzBrueckner commented Apr 3, 2022

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.

Material UI


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 and lbuffer0 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 the l in lbuffer0 stand for?

Tested on:

  • Krom on Windows
  • html5
  • Hl/C on both OpenGL and D3D11 on Windows

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.

@MoritzBrueckner MoritzBrueckner added the Release Notes: Changes A pull request that is a feature change, not a fix. Used to generate release notes. label Apr 3, 2022
@luboslenco luboslenco merged commit 70bd264 into armory3d:master Apr 6, 2022
Copy link

Btw, what does the l in lbuffer0 stand for?

I believe it originally comes from the, standing for lightbuffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Release Notes: Changes A pull request that is a feature change, not a fix. Used to generate release notes.
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants