OpenTTD Source: src/table/opengl_shader.h Source File

OpenTTD Source 1.11.0-RC1

opengl_shader.h
Go to the documentation of this file.
1 /* $Id$ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
13 static const char *_vertex_shader_sprite[] = {
14 "#version 110\n",
15 "uniform vec4 sprite;",
16 "uniform vec2 screen;",
17 "attribute vec2 position, colour_uv;",
18 "varying vec2 colour_tex_uv;",
19 "void main() {",
20 " vec2 size = sprite.zw / screen.xy;",
21 " vec2 offset = ((2.0 * sprite.xy + sprite.zw) / screen.xy - 1.0) * vec2(1.0, -1.0);",
22 " colour_tex_uv = colour_uv;",
23 " gl_Position = vec4(position * size + offset, 0.0, 1.0);",
24 "}",
25 };
26
28 static const char *_vertex_shader_sprite_150[] = {
29 "#version 150\n",
30 "uniform vec4 sprite;",
31 "uniform vec2 screen;",
32 "in vec2 position, colour_uv;",
33 "out vec2 colour_tex_uv;",
34 "void main() {",
35 " vec2 size = sprite.zw / screen.xy;",
36 " vec2 offset = ((2.0 * sprite.xy + sprite.zw) / screen.xy - 1.0) * vec2(1.0, -1.0);",
37 " colour_tex_uv = colour_uv;",
38 " gl_Position = vec4(position * size + offset, 0.0, 1.0);",
39 "}",
40 };
41
43 static const char *_frag_shader_direct[] = {
44 "#version 110\n",
45 "uniform sampler2D colour_tex;",
46 "varying vec2 colour_tex_uv;",
47 "void main() {",
48 " gl_FragData[0] = texture2D(colour_tex, colour_tex_uv);",
49 "}",
50 };
51
53 static const char *_frag_shader_direct_150[] = {
54 "#version 150\n",
55 "uniform sampler2D colour_tex;",
56 "in vec2 colour_tex_uv;",
57 "out vec4 colour;",
58 "void main() {",
59 " colour = texture(colour_tex, colour_tex_uv);",
60 "}",
61 };
62
64 static const char *_frag_shader_palette[] = {
65 "#version 110\n",
66 "uniform sampler2D colour_tex;",
67 "uniform sampler1D palette;",
68 "varying vec2 colour_tex_uv;",
69 "void main() {",
70 " float idx = texture2D(colour_tex, colour_tex_uv).r;",
71 " gl_FragData[0] = texture1D(palette, idx);",
72 "}",
73 };
74
76 static const char *_frag_shader_palette_150[] = {
77 "#version 150\n",
78 "uniform sampler2D colour_tex;",
79 "uniform sampler1D palette;",
80 "in vec2 colour_tex_uv;",
81 "out vec4 colour;",
82 "void main() {",
83 " float idx = texture(colour_tex, colour_tex_uv).r;",
84 " colour = texture(palette, idx);",
85 "}",
86 };
87
88
90 static const char *_frag_shader_remap_func = \
91 "float max3(vec3 v) {"
92 " return max(max(v.x, v.y), v.z);"
93 "}"
94 ""
95 "vec3 adj_brightness(vec3 colour, float brightness) {"
96 " vec3 adj = colour * (brightness > 0.0 ? brightness / 0.5 : 1.0);"
97 " vec3 ob_vec = clamp(adj - 1.0, 0.0, 1.0);"
98 " float ob = (ob_vec.r + ob_vec.g + ob_vec.b) / 2.0;"
99 ""
100 " return clamp(adj + ob * (1.0 - adj), 0.0, 1.0);"
101 "}";
102
104 static const char *_frag_shader_rgb_mask_blend[] = {
105 "#version 110\n",
106 "#extension GL_ATI_shader_texture_lod: enable\n",
107 "#extension GL_ARB_shader_texture_lod: enable\n",
108 "uniform sampler2D colour_tex;",
109 "uniform sampler1D palette;",
110 "uniform sampler2D remap_tex;",
111 "uniform bool rgb;",
112 "uniform float zoom;",
113 "varying vec2 colour_tex_uv;",
114 "",
115 _frag_shader_remap_func,
116 "",
117 "void main() {",
118 " float idx = texture2DLod(remap_tex, colour_tex_uv, zoom).r;",
119 " vec4 remap_col = texture1D(palette, idx);",
120 " vec4 rgb_col = texture2DLod(colour_tex, colour_tex_uv, zoom);",
121 "",
122 " gl_FragData[0].a = rgb ? rgb_col.a : remap_col.a;",
123 " gl_FragData[0].rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;",
124 "}",
125 };
126
128 static const char *_frag_shader_rgb_mask_blend_150[] = {
129 "#version 150\n",
130 "uniform sampler2D colour_tex;",
131 "uniform sampler1D palette;",
132 "uniform sampler2D remap_tex;",
133 "uniform float zoom;",
134 "uniform bool rgb;",
135 "in vec2 colour_tex_uv;",
136 "out vec4 colour;",
137 "",
138 _frag_shader_remap_func,
139 "",
140 "void main() {",
141 " float idx = textureLod(remap_tex, colour_tex_uv, zoom).r;",
142 " vec4 remap_col = texture(palette, idx);",
143 " vec4 rgb_col = textureLod(colour_tex, colour_tex_uv, zoom);",
144 "",
145 " colour.a = rgb ? rgb_col.a : remap_col.a;",
146 " colour.rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;",
147 "}",
148 };
149
151 static const char *_frag_shader_sprite_blend[] = {
152 "#version 110\n",
153 "#extension GL_ATI_shader_texture_lod: enable\n",
154 "#extension GL_ARB_shader_texture_lod: enable\n",
155 "uniform sampler2D colour_tex;",
156 "uniform sampler1D palette;",
157 "uniform sampler2D remap_tex;",
158 "uniform sampler1D pal;",
159 "uniform float zoom;",
160 "uniform bool rgb;",
161 "uniform bool crash;",
162 "varying vec2 colour_tex_uv;",
163 "",
164 _frag_shader_remap_func,
165 "",
166 "void main() {",
167 " float idx = texture2DLod(remap_tex, colour_tex_uv, zoom).r;",
168 " float r = texture1D(pal, idx).r;",
169 " vec4 remap_col = texture1D(palette, idx);",
170 " vec4 rgb_col = texture2DLod(colour_tex, colour_tex_uv, zoom);",
171 "",
172 " if (crash && idx == 0.0) rgb_col.rgb = vec2(dot(rgb_col.rgb, vec3(0.199325561523, 0.391342163085, 0.076004028320)), 0.0).rrr;"
173 " gl_FragData[0].a = rgb && (r > 0.0 || idx == 0.0) ? rgb_col.a : remap_col.a;",
174 " gl_FragData[0].rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;",
175 "}",
176 };
177
179 static const char *_frag_shader_sprite_blend_150[] = {
180 "#version 150\n",
181 "uniform sampler2D colour_tex;",
182 "uniform sampler1D palette;",
183 "uniform sampler2D remap_tex;",
184 "uniform sampler1D pal;",
185 "uniform float zoom;",
186 "uniform bool rgb;",
187 "uniform bool crash;",
188 "in vec2 colour_tex_uv;",
189 "out vec4 colour;",
190 "",
191 _frag_shader_remap_func,
192 "",
193 "void main() {",
194 " float idx = textureLod(remap_tex, colour_tex_uv, zoom).r;"
195 " float r = texture(pal, idx).r;",
196 " vec4 remap_col = texture(palette, r);",
197 " vec4 rgb_col = textureLod(colour_tex, colour_tex_uv, zoom);",
198 "",
199 " if (crash && idx == 0.0) rgb_col.rgb = vec2(dot(rgb_col.rgb, vec3(0.199325561523, 0.391342163085, 0.076004028320)), 0.0).rrr;"
200 " colour.a = rgb && (r > 0.0 || idx == 0.0) ? rgb_col.a : remap_col.a;",
201 " colour.rgb = idx > 0.0 ? adj_brightness(remap_col.rgb, max3(rgb_col.rgb)) : rgb_col.rgb;",
202 "}",
203 };
_frag_shader_palette
static const char * _frag_shader_palette[]
Fragment shader that performs a palette lookup to read the colour from an 8bpp texture.
Definition: opengl_shader.h:64
_frag_shader_sprite_blend_150
static const char * _frag_shader_sprite_blend_150[]
GLSL 1.50 fragment shader that performs a palette lookup to read the colour from a sprite texture.
Definition: opengl_shader.h:179
_frag_shader_direct_150
static const char * _frag_shader_direct_150[]
GLSL 1.50 fragment shader that reads the fragment colour from a 32bpp texture.
Definition: opengl_shader.h:53
_vertex_shader_sprite
static const char * _vertex_shader_sprite[]
Vertex shader that positions a sprite on screen.
Definition: opengl_shader.h:13
_frag_shader_palette_150
static const char * _frag_shader_palette_150[]
GLSL 1.50 fragment shader that performs a palette lookup to read the colour from an 8bpp texture.
Definition: opengl_shader.h:76
_vertex_shader_sprite_150
static const char * _vertex_shader_sprite_150[]
GLSL 1.50 vertex shader that positions a sprite on screen.
Definition: opengl_shader.h:28
_frag_shader_rgb_mask_blend_150
static const char * _frag_shader_rgb_mask_blend_150[]
GLSL 1.50 fragment shader that performs a palette lookup to read the colour from an 8bpp texture.
Definition: opengl_shader.h:128
_frag_shader_sprite_blend
static const char * _frag_shader_sprite_blend[]
Fragment shader that performs a palette lookup to read the colour from a sprite texture.
Definition: opengl_shader.h:151
_frag_shader_remap_func
static const char * _frag_shader_remap_func
Fragment shader function for remap brightness modulation.
Definition: opengl_shader.h:90
_frag_shader_rgb_mask_blend
static const char * _frag_shader_rgb_mask_blend[]
Fragment shader that performs a palette lookup to read the colour from an 8bpp texture.
Definition: opengl_shader.h:104
_frag_shader_direct
static const char * _frag_shader_direct[]
Fragment shader that reads the fragment colour from a 32bpp texture.
Definition: opengl_shader.h:43