Files @ r28566:ec28e66fe6ee
Branch filter:

Location: cpp/openttd-patchpack/source/src/table/opengl_shader.h

dependabot[bot] 49699333+dependabot[bot]@users.noreply.github.com
Upgrade: [CI] bump the actions group with 9 updates (#11881)

Bumps the actions group with 9 updates:

| Package | From | To |
| --- | --- | --- |
| [actions/checkout](https://github.com/actions/checkout) | `3` | `4` |
| [actions/cache](https://github.com/actions/cache) | `3` | `4` |
| [actions/github-script](https://github.com/actions/github-script) | `6` | `7` |
| [OpenTTD/actions](https://github.com/openttd/actions) | `2` | `5` |
| [github/codeql-action](https://github.com/github/codeql-action) | `2` | `3` |
| [actions/download-artifact](https://github.com/actions/download-artifact) | `3` | `4` |
| [actions/upload-artifact](https://github.com/actions/upload-artifact) | `3` | `4` |
| [tibdex/github-app-token](https://github.com/tibdex/github-app-token) | `1` | `2` |
| [peter-evans/repository-dispatch](https://github.com/peter-evans/repository-dispatch) | `2` | `3` |

Updates `actions/checkout` from 3 to 4
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

Updates `actions/cache` from 3 to 4
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v3...v4)

Updates `actions/github-script` from 6 to 7
- [Release notes](https://github.com/actions/github-script/releases)
- [Commits](https://github.com/actions/github-script/compare/v6...v7)

Updates `OpenTTD/actions` from 2 to 5
- [Release notes](https://github.com/openttd/actions/releases)
- [Commits](https://github.com/openttd/actions/compare/v2...v5)

Updates `github/codeql-action` from 2 to 3
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v2...v3)

Updates `actions/download-artifact` from 3 to 4
- [Release notes](https://github.com/actions/download-artifact/releases)
- [Commits](https://github.com/actions/download-artifact/compare/v3...v4)

Updates `actions/upload-artifact` from 3 to 4
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v3...v4)

Updates `tibdex/github-app-token` from 1 to 2
- [Release notes](https://github.com/tibdex/github-app-token/releases)
- [Commits](https://github.com/tibdex/github-app-token/compare/v1...v2)

Updates `peter-evans/repository-dispatch` from 2 to 3
- [Release notes](https://github.com/peter-evans/repository-dispatch/releases)
- [Commits](https://github.com/peter-evans/repository-dispatch/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
- dependency-name: actions/cache
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
- dependency-name: actions/github-script
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
- dependency-name: OpenTTD/actions
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
- dependency-name: github/codeql-action
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
- dependency-name: actions/download-artifact
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
- dependency-name: actions/upload-artifact
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
- dependency-name: tibdex/github-app-token
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
- dependency-name: peter-evans/repository-dispatch
dependency-type: direct:production
update-type: version-update:semver-major
dependency-group: actions
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file opengl_shader.h OpenGL shader programs. */

/** Vertex shader that positions a sprite on screen.. */
static const char *_vertex_shader_sprite[] = {
	"#version 110\n",
	"uniform vec4 sprite;",
	"uniform vec2 screen;",
	"attribute vec2 position, colour_uv;",
	"varying vec2 colour_tex_uv;",
	"void main() {",
	"  vec2 size = sprite.zw / screen.xy;",
	"  vec2 offset = ((2.0 * sprite.xy + sprite.zw) / screen.xy - 1.0) * vec2(1.0, -1.0);",
	"  colour_tex_uv = colour_uv;",
	"  gl_Position = vec4(position * size + offset, 0.0, 1.0);",
	"}",
};

/** GLSL 1.50 vertex shader that positions a sprite on screen. */
static const char *_vertex_shader_sprite_150[] = {
	"#version 150\n",
	"uniform vec4 sprite;",
	"uniform vec2 screen;",
	"in vec2 position, colour_uv;",
	"out vec2 colour_tex_uv;",
	"void main() {",
	"  vec2 size = sprite.zw / screen.xy;",
	"  vec2 offset = ((2.0 * sprite.xy + sprite.zw) / screen.xy - 1.0) * vec2(1.0, -1.0);",
	"  colour_tex_uv = colour_uv;",
	"  gl_Position = vec4(position * size + offset, 0.0, 1.0);",
	"}",
};

/** Fragment shader that reads the fragment colour from a 32bpp texture. */
static const char *_frag_shader_direct[] = {
	"#version 110\n",
	"uniform sampler2D colour_tex;",
	"varying vec2 colour_tex_uv;",
	"void main() {",
	"  gl_FragData[0] = texture2D(colour_tex, colour_tex_uv);",
	"}",
};

/** GLSL 1.50 fragment shader that reads the fragment colour from a 32bpp texture. */
static const char *_frag_shader_direct_150[] = {
	"#version 150\n",
	"uniform sampler2D colour_tex;",
	"in vec2 colour_tex_uv;",
	"out vec4 colour;",
	"void main() {",
	"  colour = texture(colour_tex, colour_tex_uv);",
	"}",
};

/** Fragment shader that performs a palette lookup to read the colour from an 8bpp texture. */
static const char *_frag_shader_palette[] = {
	"#version 110\n",
	"uniform sampler2D colour_tex;",
	"uniform sampler1D palette;",
	"varying vec2 colour_tex_uv;",
	"void main() {",
	"  float idx = texture2D(colour_tex, colour_tex_uv).r;",
	"  gl_FragData[0] = texture1D(palette, idx);",
	"}",
};

/** GLSL 1.50 fragment shader that performs a palette lookup to read the colour from an 8bpp texture. */
static const char *_frag_shader_palette_150[] = {
	"#version 150\n",
	"uniform sampler2D colour_tex;",
	"uniform sampler1D palette;",
	"in vec2 colour_tex_uv;",
	"out vec4 colour;",
	"void main() {",
	"  float idx = texture(colour_tex, colour_tex_uv).r;",
	"  colour = texture(palette, idx);",
	"}",
};


/** Fragment shader function for remap brightness modulation. */
static const char *_frag_shader_remap_func = \
	"float max3(vec3 v) {"
	"  return max(max(v.x, v.y), v.z);"
	"}"
	""
	"vec3 adj_brightness(vec3 colour, float brightness) {"
	"  vec3 adj = colour * (brightness > 0.0 ? brightness / 0.5 : 1.0);"
	"  vec3 ob_vec = clamp(adj - 1.0, 0.0, 1.0);"
	"  float ob = (ob_vec.r + ob_vec.g + ob_vec.b) / 2.0;"
	""
	"  return clamp(adj + ob * (1.0 - adj), 0.0, 1.0);"
	"}";

/** Fragment shader that performs a palette lookup to read the colour from an 8bpp texture. */
static const char *_frag_shader_rgb_mask_blend[] = {
	"#version 110\n",
	"#extension GL_ATI_shader_texture_lod: enable\n",
	"#extension GL_ARB_shader_texture_lod: enable\n",
	"uniform sampler2D colour_tex;",
	"uniform sampler1D palette;",
	"uniform sampler2D remap_tex;",
	"uniform bool rgb;",
	"uniform float zoom;",
	"varying vec2 colour_tex_uv;",
	"",
	_frag_shader_remap_func,
	"",
	"void main() {",
	"  float idx = texture2DLod(remap_tex, colour_tex_uv, zoom).r;",
	"  vec4 remap_col = texture1D(palette, idx);",
	"  vec4 rgb_col = texture2DLod(colour_tex, colour_tex_uv, zoom);",
	"",
	"  gl_FragData[0].a = rgb ? rgb_col.a : remap_col.a;",
	"  gl_FragData[0].rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;",
	"}",
};

/** GLSL 1.50 fragment shader that performs a palette lookup to read the colour from an 8bpp texture. */
static const char *_frag_shader_rgb_mask_blend_150[] = {
	"#version 150\n",
	"uniform sampler2D colour_tex;",
	"uniform sampler1D palette;",
	"uniform sampler2D remap_tex;",
	"uniform float zoom;",
	"uniform bool rgb;",
	"in vec2 colour_tex_uv;",
	"out vec4 colour;",
	"",
	_frag_shader_remap_func,
	"",
	"void main() {",
	"  float idx = textureLod(remap_tex, colour_tex_uv, zoom).r;",
	"  vec4 remap_col = texture(palette, idx);",
	"  vec4 rgb_col = textureLod(colour_tex, colour_tex_uv, zoom);",
	"",
	"  colour.a = rgb ? rgb_col.a : remap_col.a;",
	"  colour.rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;",
	"}",
};

/** Fragment shader that performs a palette lookup to read the colour from a sprite texture. */
static const char *_frag_shader_sprite_blend[] = {
	"#version 110\n",
	"#extension GL_ATI_shader_texture_lod: enable\n",
	"#extension GL_ARB_shader_texture_lod: enable\n",
	"uniform sampler2D colour_tex;",
	"uniform sampler1D palette;",
	"uniform sampler2D remap_tex;",
	"uniform sampler1D pal;",
	"uniform float zoom;",
	"uniform bool rgb;",
	"uniform bool crash;",
	"varying vec2 colour_tex_uv;",
	"",
	_frag_shader_remap_func,
	"",
	"void main() {",
	"  float idx = texture2DLod(remap_tex, colour_tex_uv, zoom).r;",
	"  float r = texture1D(pal, idx).r;",
	"  vec4 remap_col = texture1D(palette, idx);",
	"  vec4 rgb_col = texture2DLod(colour_tex, colour_tex_uv, zoom);",
	"",
	"  if (crash && idx == 0.0) rgb_col.rgb = vec2(dot(rgb_col.rgb, vec3(0.199325561523, 0.391342163085, 0.076004028320)), 0.0).rrr;"
	"  gl_FragData[0].a = rgb && (r > 0.0 || idx == 0.0) ? rgb_col.a : remap_col.a;",
	"  gl_FragData[0].rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;",
	"}",
};

/** GLSL 1.50 fragment shader that performs a palette lookup to read the colour from a sprite texture. */
static const char *_frag_shader_sprite_blend_150[] = {
	"#version 150\n",
	"uniform sampler2D colour_tex;",
	"uniform sampler1D palette;",
	"uniform sampler2D remap_tex;",
	"uniform sampler1D pal;",
	"uniform float zoom;",
	"uniform bool rgb;",
	"uniform bool crash;",
	"in vec2 colour_tex_uv;",
	"out vec4 colour;",
	"",
	_frag_shader_remap_func,
	"",
	"void main() {",
	"  float idx =  textureLod(remap_tex, colour_tex_uv, zoom).r;"
	"  float r = texture(pal, idx).r;",
	"  vec4 remap_col = texture(palette, r);",
	"  vec4 rgb_col = textureLod(colour_tex, colour_tex_uv, zoom);",
	"",
	"  if (crash && idx == 0.0) rgb_col.rgb = vec2(dot(rgb_col.rgb, vec3(0.199325561523, 0.391342163085, 0.076004028320)), 0.0).rrr;"
	"  colour.a = rgb && (r > 0.0 || idx == 0.0) ? rgb_col.a : remap_col.a;",
	"  colour.rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;",
	"}",
};