HalfLifeAssetManager
HalfLifeAssetManager copied to clipboard
Model does not blend with ground color when opacity is less than 100%.
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
- Launch Half-Life Asset Manager
- Load a model e.g. scientist.mdl
- In 'Model Display', check 'Show Ground'
- Rotate the camera in a way the model covers a significant portion of the ground
- 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.
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.
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.
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.
Using the furthest vertex breaks transparency when viewed from under the ground.
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.
Given this isn't critical, I'll close the issue.
This can always be revisited later if there's ever a need for it.