Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

Relief mapping is not applied on alpha mask / depth computation

Open illwieckz opened this issue 5 years ago • 16 comments

Relief mapping is not applied on depth computation, hence alpha-tested textures using depth write (like grids) displays a bit of void. It's possible to workaround this by disabling the depth computation on those textures, but it would be better to fix the bug.

illwieckz avatar Apr 25 '20 23:04 illwieckz

Maybe the proper implementation is to render the heightmap (basically blend the alphaterrain heightmaps) somewhere in memory in a way it can be reused multiple time (basically on depth map and on diffuse/lightmap stage).

illwieckz avatar Aug 21 '20 23:08 illwieckz

Another proposed solution (and easier to implement at first) would be to just redo the relief computation on the depth mask as well…

illwieckz avatar Feb 09 '21 00:02 illwieckz

To illustrate the problem, the white garbage is filling the space between the displaced diffuse and the non-displaced depth mask:

broken relief alpha mask

illwieckz avatar Feb 09 '21 01:02 illwieckz

Another proposed solution (and easier to implement at first) would be to just redo the relief computation on the depth mask as well…

Checking the alpha channel in lightMapping_fp would probably be faster. Some extra texture reads, but no extra divergence introduced in depth shader then. It would also avoid writing depth in it, which would otherwise disable early-z optimisations.

VReaperV avatar Sep 27 '24 09:09 VReaperV

Instead of disabling relief mapping, we should disable the depth shader for the affected shader. Depth shaders are not essential to render correctly: see #1412.

slipher avatar Nov 04 '24 06:11 slipher

@slipher the screenshot in the comment above was taken in test-pbr map from https://github.com/UnvanquishedAssets/UnvanquishedTestAssets/releases/tag/v2.1

illwieckz avatar Nov 04 '24 07:11 illwieckz

I'd prefer a proper fix here rather than disabling things.

VReaperV avatar Nov 04 '24 07:11 VReaperV

A proper fix is likely slower: what I understand is that it would require to compute relief mapping in the depth shader…

illwieckz avatar Nov 04 '24 07:11 illwieckz

I mean, if by disabling we mean disablign depth.

If we mean disabling relief mapping, we better not do that yes.

illwieckz avatar Nov 04 '24 07:11 illwieckz

Since relief mapping is known to be very expensive, maybe skipping the depth pass could actually be optimal in any case? For an sufficiently expensive shader, the cost of running it twice would outweigh the savings of using less memory bandwidth.

slipher avatar Nov 04 '24 07:11 slipher

Since relief mapping is known to be very expensive, maybe skipping the depth pass could actually be optimal in any case?

I do believe it, yes.

illwieckz avatar Nov 04 '24 07:11 illwieckz

A proper fix is likely slower: what I understand is that it would require to compute relief mapping in the depth shader…

I believe we can just use alpha mask with relief mapping instead.

VReaperV avatar Nov 04 '24 07:11 VReaperV

My concern with skipping depth here is that it might lead to incorrect results, since it would probably break any effects that rely on depth. It might not be noticeable if it's only done on surfaces that look like swiss cheese, though.

VReaperV avatar Nov 04 '24 07:11 VReaperV

If we skip depth, what would happen if there are more than one texture like this in the line of sight?

illwieckz avatar Nov 04 '24 08:11 illwieckz

If we skip depth, what would happen if there are more than one texture like this in the line of sight?

It probably wouldn't look worse than if there was only one of them in line of sight, but performance would suffer as relief mapping is quite heavy.

VReaperV avatar Nov 04 '24 08:11 VReaperV

I tried the approach with alpha-testing in relief shader, but it creates too much of a slowdown.

VReaperV avatar Feb 20 '25 13:02 VReaperV