HalfLifeAssetManager icon indicating copy to clipboard operation
HalfLifeAssetManager copied to clipboard

Model does not blend with ground color when opacity is less than 100%.

Open malortie opened this issue 3 years ago • 2 comments

Context

When 'Show Ground' is enabled and when the opacity of the model is less than 100%, the region occupied by the model appears to blend with the background color instead of blending with the ground color.

Tested with

Software: Half-Life Asset Manager
Version: 1.0.0
OS: Microsoft Windows 10 Home

Steps to reproduce

  1. Launch Half-Life Asset Manager
  2. Load a model e.g. scientist.mdl
  3. In 'Model Display', check 'Show Ground'
  4. Rotate the camera in a way the model covers a significant portion of the ground
  5. Set 'Opacity' to a low value e.g. 10%

Expected behavior: The rendered model color should blend with the ground color. Actual behavior: The rendered model color blends with the background color.

malortie avatar Feb 06 '21 18:02 malortie

It's probably happening because the ground is drawn after the model. I'll need to double check the order that everything is drawn in.

SamVanheer avatar Feb 06 '21 20:02 SamVanheer

This will need a fair amount of refactoring to turn every object in the scene into its own distinct thing that can be depth sorted for proper rendering.

SamVanheer avatar Mar 07 '21 13:03 SamVanheer

I've mostly eliminated this problem but it still happens when the camera is at certain angles. I suppose it can be eliminated at least in this case by checking which quad vertex is furthest from the camera and using that for depth sorting.

SamVanheer avatar Dec 25 '22 18:12 SamVanheer

Using the furthest vertex breaks transparency when viewed from under the ground.

SamVanheer avatar Dec 25 '22 19:12 SamVanheer

I've looked into this and it's more complicated to fix than i hoped for. The solution to this problem is to use an order-independent transparency implementation but that's an advanced technique that requires relatively new hardware and graphics API functionality.

See https://learnopengl.com/Guest-Articles/2020/OIT/Introduction and the second page found linked in the sidebar which notes:

The only caveat is we need to write our code in OpenGL ^4.0 to be able to use blending to multiple render targets (e.g. utilizing glBlendFunci).

I've tried switching to additive blending but that breaks the opacity setting and causes affected meshes to render with a glow like additive in-game does.

The system requirements would be raised too high to be acceptable right now so i can't fully fix this problem.

I did fix a bug that caused the render order to change depending on camera angles, so it behaves like it used to in HLMV.

SamVanheer avatar Mar 17 '24 18:03 SamVanheer

Given this isn't critical, I'll close the issue.

This can always be revisited later if there's ever a need for it.

malortie avatar Mar 20 '24 19:03 malortie