OpenSWE1R / openswe1r

An Open-Source port of the 1999 Game "Star Wars Episode 1: Racer"
https://openswe1r.github.io/
GNU General Public License v2.0
313 stars 26 forks source link

Implement alpha testing #99

Closed JayFoxRox closed 6 years ago

JayFoxRox commented 6 years ago

This implements alpha testing.

As OpenGL 3.3 Core does not have this feature anymore, we have to implement it in GLSL. I've only seen the game use the D3DCMP_NOTEQUAL mode, so it's hardcoded in the shader. The alpha-ref is also never set, so it's also the default (0x00) and hardcoded in the shader. Further modes and the alpha-ref will be implemented as they are encountered.

I assumed an alpha value of 0x00 = 0.0 and 1.0 = 0xFF; with proper rounding (so it's not biased towards 0x00 (floor) or 0xFF (ceil)) Threfore, the round() in the shader is necessary because the GLSL spec says "When constructors are used to convert any floating-point type to an integer type, the fractional part of the floating-point value is dropped." (floor). Actually, doing a floor() (or simply removing the round()) would make it more likely that pixels get discarded. This would make the following glitch disappear completly:

Screenshot after merging this PR (Click here to see how severe the issue is on master, without any alpha-testing)

For accuracy, I recreated the expected original behaviour (using round()). We should test how this behaves on original 90'ies hardware and consider changing it in our D3D implementation. For now, it is assumed that the pictured glitch is just a glitch in the PC version of the original game.

Closes #41