LostArtefacts / TR1X

Open source re-implementation of Tomb Raider 1 (1996), along with additional enhancements and bugfixes
https://lostartefacts.dev/
GNU General Public License v3.0
468 stars 32 forks source link

Adding shaders for playing also with OpenGL 2.1. #685

Open carlo-bramini opened 1 year ago

carlo-bramini commented 1 year ago

I was wondering what you think about adding some extra shaders programs for running the engine also with OpenGL 2.1. I tested the engine with a Raspberry PI computer board and at the beginning it didn't work because because it just supports programs up to version 1.20 while the ones in the current development branch run from version 1.30. However, I have been able to add extra support also for previous version of OpenGL, to be used if support for OpenGL 3.0 is missing. After that, testing with the above computer module gave an excellent result.

Into the bin/shaders directory there are these files:

2d.fsh 2d.vsh 3d.fsh 3d.vsh

I have seen that 2d.vsh and 3d.vsh can be set to version 1.20 safely because they don't use any specific command from version 1.30 and newer. Instead, 2d.fsh and 3d.fsh required some extra work. Actually, after downgrading to version 1.20, I replaced command texture with texture2D into both scripts. I had also to remove support smoothingEnabled from 3d.fsh because I don't know how it could be replaced at this time. Probably, there is a better way to handle it. However, it was enough for making the engine working.

Perhaps, it may be worth to evaluate the chance to fall down to use a program able to run on a previous version of the GL library, if the preferred support for OpenGL 3.0 is rejected.

Gerwin2k commented 1 year ago

I looked into this earlier, and came to these conclusions: 1) The shader files have a syntax error. They use v330 syntax, but identify as v130. Most windows GPU drivers work regardless, some don't. 2) Proper fallback from GLSL v330 to v130 cannot be achieved solely by changing the external shader files. Because the v130 absence of "layout(location = something)" must be handled in the source code with glBindAttribLocation.

See also issue #327 See also issue #644

vvs- commented 1 year ago

Because the v130 absence of "layout(location = something)" must be handled in the source code with glBindAttribLocation.

I don't think so. They are properly handled by OGL extension which I have even on OGL 2.1 hardware (Intel).

@carlo-bramini

I had also to remove support smoothingEnabled from 3d.fsh because I don't know how it could be replaced at this time. Probably, there is a better way to handle it.

You can conditionally compile corresponding part, i.e.#ifdef GL_EXT_gpu_shader4.

Gerwin2k commented 1 year ago

From what I understand now, when older openGL hardware is used with drivers updated with the ARB_explicit_attrib_location feature, it can parse the layout syntax. In that way, it is not strictly GLSL-version specific.

reference: https://stackoverflow.com/questions/7668599/glsl-equivalent-of-layout-location-1-in-version-130