Skip to content

Commit

Permalink
gfx: make shaders compatible with GLSL 1.20
Browse files Browse the repository at this point in the history
Related to #327 and #685.
  • Loading branch information
vvs- authored Apr 30, 2023
1 parent 1fdc545 commit 0312c1b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- added the ability to unbind the sidestep left and sidestep right keys (#766)
- added a cheat to explode Lara like in TR2 and TR3 (#793)
- fixed sounds stopping instead of pausing if game sounds in inventory are disabled (#717)
- changed shaders to use GLSL 1.20 which should fix most issues with OpenGL 2.1 (#327, #685)

## [2.14](https://github.com/rr-/Tomb1Main/compare/2.13.2...2.14) - 2023-04-05
- added Spanish localization to the config tool
Expand Down
9 changes: 3 additions & 6 deletions bin/shaders/2d.fsh
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#version 130
#extension GL_ARB_explicit_attrib_location: enable
#version 120

in vec2 vertTexCoords;

layout(location = 0) out vec4 fragColor;
varying vec2 vertTexCoords;

uniform sampler2D tex0;

void main(void) {
fragColor = texture(tex0, vertTexCoords);
gl_FragColor = texture2D(tex0, vertTexCoords);
}
4 changes: 2 additions & 2 deletions bin/shaders/2d.vsh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#version 130
#version 120
#extension GL_ARB_explicit_attrib_location: enable

layout(location = 0) in vec2 inPosition;

out vec2 vertTexCoords;
varying vec2 vertTexCoords;

void main(void) {
vertTexCoords = inPosition;
Expand Down
19 changes: 9 additions & 10 deletions bin/shaders/3d.fsh
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
#version 130
#extension GL_ARB_explicit_attrib_location: enable
#version 120
#extension GL_EXT_gpu_shader4: enable

in vec4 vertColor;
in vec3 vertTexCoords;

layout(location = 0) out vec4 fragColor;
varying vec4 vertColor;
varying vec3 vertTexCoords;

uniform sampler2D tex0;
uniform bool texturingEnabled;
uniform bool smoothingEnabled;

void main(void) {
fragColor = vertColor;
gl_FragColor = vertColor;

if (texturingEnabled) {
#ifdef GL_EXT_gpu_shader4
if (smoothingEnabled) {
// do not use smoothing for chroma key
ivec2 size = textureSize2D(tex0, 0);
int tx = int((vertTexCoords.x / vertTexCoords.z) * size.x) % size.x;
int ty = int((vertTexCoords.y / vertTexCoords.z) * size.y) % size.y;
vec4 texel = texelFetch(tex0, ivec2(tx, ty), 0);
vec4 texel = texelFetch2D(tex0, ivec2(tx, ty), 0);
if (texel.a == 0.0) {
discard;
}
}
#endif

vec4 texColor = texture(tex0, vertTexCoords.xy / vertTexCoords.z);
vec4 texColor = texture2D(tex0, vertTexCoords.xy / vertTexCoords.z);
if (texColor.a == 0.0) {
discard;
}

fragColor = vec4(fragColor.rgb * texColor.rgb, texColor.a);
gl_FragColor = vec4(gl_FragColor.rgb * texColor.rgb, texColor.a);
}
}
6 changes: 3 additions & 3 deletions bin/shaders/3d.vsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 130
#version 120
#extension GL_ARB_explicit_attrib_location: enable

layout(location = 0) in vec3 inPosition;
Expand All @@ -8,8 +8,8 @@ layout(location = 2) in vec4 inColor;
uniform mat4 matProjection;
uniform mat4 matModelView;

out vec4 vertColor;
out vec3 vertTexCoords;
varying vec4 vertColor;
varying vec3 vertTexCoords;

void main(void) {
gl_Position = matProjection * matModelView * vec4(inPosition, 1);
Expand Down

0 comments on commit 0312c1b

Please sign in to comment.