OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/shader.h" | 5 #include "cc/output/shader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 11 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
12 #include "gpu/command_buffer/client/gles2_interface.h" | 12 #include "gpu/command_buffer/client/gles2_interface.h" |
13 | 13 |
14 #define SHADER0(Src) #Src | 14 template <size_t size> |
15 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) | 15 std::string StripLambda(const char(&shader)[size]) { |
16 #define FRAGMENT_SHADER(Src) \ | 16 // Must contain at least "[]() {}" and trailing null (included in size). |
17 SetFragmentTexCoordPrecision( \ | 17 static_assert(size >= 8, |
18 precision, \ | 18 "String passed to StripLambda must be at least 8 characters"); |
19 SetFragmentSamplerType(sampler, SetBlendModeFunctions(SHADER0(Src)))) | 19 DCHECK_EQ(strncmp("[]() {", shader, 6), 0); |
| 20 DCHECK_EQ(shader[size - 2], '}'); |
| 21 return std::string(shader + 6, shader + size - 2); |
| 22 } |
| 23 |
| 24 // Shaders are passed in with lambda syntax, which tricks clang-format into |
| 25 // handling them correctly. StipLambda removes this. |
| 26 #define SHADER0(Src) StripLambda(#Src) |
| 27 #define VERTEX_SHADER(Head, Body) SetVertexTexCoordPrecision(Head + Body) |
| 28 #define FRAGMENT_SHADER(Head, Body) \ |
| 29 SetFragmentTexCoordPrecision( \ |
| 30 precision, \ |
| 31 SetFragmentSamplerType(sampler, SetBlendModeFunctions(Head + Body))) |
20 | 32 |
21 using gpu::gles2::GLES2Interface; | 33 using gpu::gles2::GLES2Interface; |
22 | 34 |
23 namespace cc { | 35 namespace cc { |
24 | 36 |
25 namespace { | 37 namespace { |
26 | 38 |
27 static void GetProgramUniformLocations(GLES2Interface* context, | 39 static void GetProgramUniformLocations(GLES2Interface* context, |
28 unsigned program, | 40 unsigned program, |
29 size_t count, | 41 size_t count, |
(...skipping 26 matching lines...) Expand all Loading... |
56 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); | 68 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); |
57 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); | 69 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); |
58 return shader_string; | 70 return shader_string; |
59 default: | 71 default: |
60 NOTREACHED(); | 72 NOTREACHED(); |
61 break; | 73 break; |
62 } | 74 } |
63 return shader_string; | 75 return shader_string; |
64 } | 76 } |
65 | 77 |
66 static std::string SetVertexTexCoordPrecision(const char* shader_string) { | 78 static std::string SetVertexTexCoordPrecision( |
| 79 const std::string& shader_string) { |
67 // We unconditionally use highp in the vertex shader since | 80 // We unconditionally use highp in the vertex shader since |
68 // we are unlikely to be vertex shader bound when drawing large quads. | 81 // we are unlikely to be vertex shader bound when drawing large quads. |
69 // Also, some vertex shaders mutate the texture coordinate in such a | 82 // Also, some vertex shaders mutate the texture coordinate in such a |
70 // way that the effective precision might be lower than expected. | 83 // way that the effective precision might be lower than expected. |
71 return "#define TexCoordPrecision highp\n" + std::string(shader_string); | 84 return "#define TexCoordPrecision highp\n" + shader_string; |
72 } | 85 } |
73 | 86 |
74 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, | 87 TexCoordPrecision TexCoordPrecisionRequired(GLES2Interface* context, |
75 int* highp_threshold_cache, | 88 int* highp_threshold_cache, |
76 int highp_threshold_min, | 89 int highp_threshold_min, |
77 int x, | 90 int x, |
78 int y) { | 91 int y) { |
79 if (*highp_threshold_cache == 0) { | 92 if (*highp_threshold_cache == 0) { |
80 // Initialize range and precision with minimum spec values for when | 93 // Initialize range and precision with minimum spec values for when |
81 // GetShaderPrecisionFormat is a test stub. | 94 // GetShaderPrecisionFormat is a test stub. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 GetProgramUniformLocations(context, | 180 GetProgramUniformLocations(context, |
168 program, | 181 program, |
169 arraysize(uniforms), | 182 arraysize(uniforms), |
170 uniforms, | 183 uniforms, |
171 locations, | 184 locations, |
172 base_uniform_index); | 185 base_uniform_index); |
173 matrix_location_ = locations[0]; | 186 matrix_location_ = locations[0]; |
174 } | 187 } |
175 | 188 |
176 std::string VertexShaderPosTex::GetShaderString() const { | 189 std::string VertexShaderPosTex::GetShaderString() const { |
177 // clang-format off | 190 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
178 return VERTEX_SHADER( | 191 } |
179 // clang-format on | 192 |
180 attribute vec4 a_position; | 193 std::string VertexShaderPosTex::GetShaderHead() { |
181 attribute TexCoordPrecision vec2 a_texCoord; | 194 return SHADER0([]() { |
182 uniform mat4 matrix; | 195 attribute vec4 a_position; |
183 varying TexCoordPrecision vec2 v_texCoord; | 196 attribute TexCoordPrecision vec2 a_texCoord; |
184 void main() { | 197 uniform mat4 matrix; |
185 gl_Position = matrix * a_position; | 198 varying TexCoordPrecision vec2 v_texCoord; |
186 v_texCoord = a_texCoord; | 199 }); |
187 } | 200 } |
188 // clang-format off | 201 |
189 ); // NOLINT(whitespace/parens) | 202 std::string VertexShaderPosTex::GetShaderBody() { |
190 // clang-format on | 203 return SHADER0([]() { |
| 204 void main() { |
| 205 gl_Position = matrix * a_position; |
| 206 v_texCoord = a_texCoord; |
| 207 } |
| 208 }); |
191 } | 209 } |
192 | 210 |
193 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() | 211 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() |
194 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) { | 212 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) { |
195 } | 213 } |
196 | 214 |
197 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, | 215 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, |
198 unsigned program, | 216 unsigned program, |
199 int* base_uniform_index) { | 217 int* base_uniform_index) { |
200 static const char* uniforms[] = { | 218 static const char* uniforms[] = { |
201 "matrix", "texScale", "texOffset", | 219 "matrix", "texScale", "texOffset", |
202 }; | 220 }; |
203 int locations[arraysize(uniforms)]; | 221 int locations[arraysize(uniforms)]; |
204 | 222 |
205 GetProgramUniformLocations(context, | 223 GetProgramUniformLocations(context, |
206 program, | 224 program, |
207 arraysize(uniforms), | 225 arraysize(uniforms), |
208 uniforms, | 226 uniforms, |
209 locations, | 227 locations, |
210 base_uniform_index); | 228 base_uniform_index); |
211 matrix_location_ = locations[0]; | 229 matrix_location_ = locations[0]; |
212 tex_scale_location_ = locations[1]; | 230 tex_scale_location_ = locations[1]; |
213 tex_offset_location_ = locations[2]; | 231 tex_offset_location_ = locations[2]; |
214 } | 232 } |
215 | 233 |
216 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { | 234 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { |
217 // clang-format off | 235 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
218 return VERTEX_SHADER( | 236 } |
219 // clang-format on | 237 |
220 precision mediump float; | 238 std::string VertexShaderPosTexYUVStretchOffset::GetShaderHead() { |
221 attribute vec4 a_position; | 239 return SHADER0([]() { |
222 attribute TexCoordPrecision vec2 a_texCoord; | 240 precision mediump float; |
223 uniform mat4 matrix; | 241 attribute vec4 a_position; |
224 varying TexCoordPrecision vec2 v_texCoord; | 242 attribute TexCoordPrecision vec2 a_texCoord; |
225 uniform TexCoordPrecision vec2 texScale; | 243 uniform mat4 matrix; |
226 uniform TexCoordPrecision vec2 texOffset; | 244 varying TexCoordPrecision vec2 v_texCoord; |
227 void main() { | 245 uniform TexCoordPrecision vec2 texScale; |
228 gl_Position = matrix * a_position; | 246 uniform TexCoordPrecision vec2 texOffset; |
229 v_texCoord = a_texCoord * texScale + texOffset; | 247 }); |
230 } | 248 } |
231 // clang-format off | 249 |
232 ); // NOLINT(whitespace/parens) | 250 std::string VertexShaderPosTexYUVStretchOffset::GetShaderBody() { |
233 // clang-format on | 251 return SHADER0([]() { |
| 252 void main() { |
| 253 gl_Position = matrix * a_position; |
| 254 v_texCoord = a_texCoord * texScale + texOffset; |
| 255 } |
| 256 }); |
234 } | 257 } |
235 | 258 |
236 VertexShaderPos::VertexShaderPos() : matrix_location_(-1) { | 259 VertexShaderPos::VertexShaderPos() : matrix_location_(-1) { |
237 } | 260 } |
238 | 261 |
239 void VertexShaderPos::Init(GLES2Interface* context, | 262 void VertexShaderPos::Init(GLES2Interface* context, |
240 unsigned program, | 263 unsigned program, |
241 int* base_uniform_index) { | 264 int* base_uniform_index) { |
242 static const char* uniforms[] = { | 265 static const char* uniforms[] = { |
243 "matrix", | 266 "matrix", |
244 }; | 267 }; |
245 int locations[arraysize(uniforms)]; | 268 int locations[arraysize(uniforms)]; |
246 | 269 |
247 GetProgramUniformLocations(context, | 270 GetProgramUniformLocations(context, |
248 program, | 271 program, |
249 arraysize(uniforms), | 272 arraysize(uniforms), |
250 uniforms, | 273 uniforms, |
251 locations, | 274 locations, |
252 base_uniform_index); | 275 base_uniform_index); |
253 matrix_location_ = locations[0]; | 276 matrix_location_ = locations[0]; |
254 } | 277 } |
255 | 278 |
256 std::string VertexShaderPos::GetShaderString() const { | 279 std::string VertexShaderPos::GetShaderString() const { |
257 // clang-format off | 280 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
258 return VERTEX_SHADER( | 281 } |
259 // clang-format on | 282 |
260 attribute vec4 a_position; | 283 std::string VertexShaderPos::GetShaderHead() { |
261 uniform mat4 matrix; | 284 return SHADER0([]() { |
262 void main() { gl_Position = matrix * a_position; } | 285 attribute vec4 a_position; |
263 // clang-format off | 286 uniform mat4 matrix; |
264 ); // NOLINT(whitespace/parens) | 287 }); |
265 // clang-format on | 288 } |
| 289 |
| 290 std::string VertexShaderPos::GetShaderBody() { |
| 291 return SHADER0([]() { |
| 292 void main() { gl_Position = matrix * a_position; } |
| 293 }); |
266 } | 294 } |
267 | 295 |
268 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 296 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
269 : matrix_location_(-1), | 297 : matrix_location_(-1), |
270 tex_transform_location_(-1), | 298 tex_transform_location_(-1), |
271 vertex_opacity_location_(-1) { | 299 vertex_opacity_location_(-1) { |
272 } | 300 } |
273 | 301 |
274 void VertexShaderPosTexTransform::Init(GLES2Interface* context, | 302 void VertexShaderPosTexTransform::Init(GLES2Interface* context, |
275 unsigned program, | 303 unsigned program, |
276 int* base_uniform_index) { | 304 int* base_uniform_index) { |
277 static const char* uniforms[] = { | 305 static const char* uniforms[] = { |
278 "matrix", "texTransform", "opacity", | 306 "matrix", "texTransform", "opacity", |
279 }; | 307 }; |
280 int locations[arraysize(uniforms)]; | 308 int locations[arraysize(uniforms)]; |
281 | 309 |
282 GetProgramUniformLocations(context, | 310 GetProgramUniformLocations(context, |
283 program, | 311 program, |
284 arraysize(uniforms), | 312 arraysize(uniforms), |
285 uniforms, | 313 uniforms, |
286 locations, | 314 locations, |
287 base_uniform_index); | 315 base_uniform_index); |
288 matrix_location_ = locations[0]; | 316 matrix_location_ = locations[0]; |
289 tex_transform_location_ = locations[1]; | 317 tex_transform_location_ = locations[1]; |
290 vertex_opacity_location_ = locations[2]; | 318 vertex_opacity_location_ = locations[2]; |
291 } | 319 } |
292 | 320 |
293 std::string VertexShaderPosTexTransform::GetShaderString() const { | 321 std::string VertexShaderPosTexTransform::GetShaderString() const { |
294 // clang-format off | 322 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
295 return VERTEX_SHADER( | 323 } |
296 // clang-format on | 324 |
297 attribute vec4 a_position; | 325 std::string VertexShaderPosTexTransform::GetShaderHead() { |
298 attribute TexCoordPrecision vec2 a_texCoord; | 326 return SHADER0([]() { |
299 attribute float a_index; | 327 attribute vec4 a_position; |
300 uniform mat4 matrix[8]; | 328 attribute TexCoordPrecision vec2 a_texCoord; |
301 uniform TexCoordPrecision vec4 texTransform[8]; | 329 attribute float a_index; |
302 uniform float opacity[32]; | 330 uniform mat4 matrix[8]; |
303 varying TexCoordPrecision vec2 v_texCoord; | 331 uniform TexCoordPrecision vec4 texTransform[8]; |
304 varying float v_alpha; | 332 uniform float opacity[32]; |
305 void main() { | 333 varying TexCoordPrecision vec2 v_texCoord; |
306 int quad_index = int(a_index * 0.25); // NOLINT | 334 varying float v_alpha; |
307 gl_Position = matrix[quad_index] * a_position; | 335 }); |
308 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; | 336 } |
309 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 337 |
310 v_alpha = opacity[int(a_index)]; // NOLINT | 338 std::string VertexShaderPosTexTransform::GetShaderBody() { |
311 } | 339 return SHADER0([]() { |
312 // clang-format off | 340 void main() { |
313 ); // NOLINT(whitespace/parens) | 341 int quad_index = int(a_index * 0.25); // NOLINT |
314 // clang-format on | 342 gl_Position = matrix[quad_index] * a_position; |
| 343 TexCoordPrecision vec4 texTrans = texTransform[quad_index]; |
| 344 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 345 v_alpha = opacity[int(a_index)]; // NOLINT |
| 346 } |
| 347 }); |
315 } | 348 } |
316 | 349 |
317 std::string VertexShaderPosTexIdentity::GetShaderString() const { | 350 std::string VertexShaderPosTexIdentity::GetShaderString() const { |
318 // clang-format off | 351 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
319 return VERTEX_SHADER( | 352 } |
320 // clang-format on | 353 |
321 attribute vec4 a_position; | 354 std::string VertexShaderPosTexIdentity::GetShaderHead() { |
322 varying TexCoordPrecision vec2 v_texCoord; | 355 return SHADER0([]() { |
323 void main() { | 356 attribute vec4 a_position; |
324 gl_Position = a_position; | 357 varying TexCoordPrecision vec2 v_texCoord; |
325 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 358 }); |
326 } | 359 } |
327 // clang-format off | 360 |
328 ); // NOLINT(whitespace/parens) | 361 std::string VertexShaderPosTexIdentity::GetShaderBody() { |
329 // clang-format on | 362 return SHADER0([]() { |
| 363 void main() { |
| 364 gl_Position = a_position; |
| 365 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 366 } |
| 367 }); |
330 } | 368 } |
331 | 369 |
332 VertexShaderQuad::VertexShaderQuad() | 370 VertexShaderQuad::VertexShaderQuad() |
333 : matrix_location_(-1), quad_location_(-1) { | 371 : matrix_location_(-1), quad_location_(-1) { |
334 } | 372 } |
335 | 373 |
336 void VertexShaderQuad::Init(GLES2Interface* context, | 374 void VertexShaderQuad::Init(GLES2Interface* context, |
337 unsigned program, | 375 unsigned program, |
338 int* base_uniform_index) { | 376 int* base_uniform_index) { |
339 static const char* uniforms[] = { | 377 static const char* uniforms[] = { |
340 "matrix", "quad", | 378 "matrix", "quad", |
341 }; | 379 }; |
342 int locations[arraysize(uniforms)]; | 380 int locations[arraysize(uniforms)]; |
343 | 381 |
344 GetProgramUniformLocations(context, | 382 GetProgramUniformLocations(context, |
345 program, | 383 program, |
346 arraysize(uniforms), | 384 arraysize(uniforms), |
347 uniforms, | 385 uniforms, |
348 locations, | 386 locations, |
349 base_uniform_index); | 387 base_uniform_index); |
350 matrix_location_ = locations[0]; | 388 matrix_location_ = locations[0]; |
351 quad_location_ = locations[1]; | 389 quad_location_ = locations[1]; |
352 } | 390 } |
353 | 391 |
354 std::string VertexShaderQuad::GetShaderString() const { | 392 std::string VertexShaderQuad::GetShaderString() const { |
| 393 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
| 394 } |
| 395 |
| 396 std::string VertexShaderQuad::GetShaderHead() { |
355 #if defined(OS_ANDROID) | 397 #if defined(OS_ANDROID) |
356 // TODO(epenner): Find the cause of this 'quad' uniform | 398 // TODO(epenner): Find the cause of this 'quad' uniform |
357 // being missing if we don't add dummy variables. | 399 // being missing if we don't add dummy variables. |
358 // http://crbug.com/240602 | 400 // http://crbug.com/240602 |
359 // clang-format off | 401 return SHADER0([]() { |
360 return VERTEX_SHADER( | 402 attribute TexCoordPrecision vec4 a_position; |
361 // clang-format on | 403 attribute float a_index; |
362 attribute TexCoordPrecision vec4 a_position; | 404 uniform mat4 matrix; |
363 attribute float a_index; | 405 uniform TexCoordPrecision vec2 quad[4]; |
364 uniform mat4 matrix; | 406 uniform TexCoordPrecision vec2 dummy_uniform; |
365 uniform TexCoordPrecision vec2 quad[4]; | 407 varying TexCoordPrecision vec2 dummy_varying; |
366 uniform TexCoordPrecision vec2 dummy_uniform; | 408 }); |
367 varying TexCoordPrecision vec2 dummy_varying; | |
368 void main() { | |
369 vec2 pos = quad[int(a_index)]; // NOLINT | |
370 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | |
371 dummy_varying = dummy_uniform; | |
372 } | |
373 // clang-format off | |
374 ); // NOLINT(whitespace/parens) | |
375 // clang-format on | |
376 #else | 409 #else |
377 // clang-format off | 410 return SHADER0([]() { |
378 return VERTEX_SHADER( | 411 attribute TexCoordPrecision vec4 a_position; |
379 // clang-format on | 412 attribute float a_index; |
380 attribute TexCoordPrecision vec4 a_position; | 413 uniform mat4 matrix; |
381 attribute float a_index; | 414 uniform TexCoordPrecision vec2 quad[4]; |
382 uniform mat4 matrix; | 415 }); |
383 uniform TexCoordPrecision vec2 quad[4]; | |
384 void main() { | |
385 vec2 pos = quad[int(a_index)]; // NOLINT | |
386 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | |
387 } | |
388 // clang-format off | |
389 ); // NOLINT(whitespace/parens) | |
390 // clang-format on | |
391 #endif | 416 #endif |
392 } | 417 } |
393 | 418 |
| 419 std::string VertexShaderQuad::GetShaderBody() { |
| 420 #if defined(OS_ANDROID) |
| 421 return SHADER0([]() { |
| 422 void main() { |
| 423 vec2 pos = quad[int(a_index)]; // NOLINT |
| 424 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
| 425 dummy_varying = dummy_uniform; |
| 426 } |
| 427 }); |
| 428 #else |
| 429 return SHADER0([]() { |
| 430 void main() { |
| 431 vec2 pos = quad[int(a_index)]; // NOLINT |
| 432 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
| 433 } |
| 434 }); |
| 435 #endif |
| 436 } |
| 437 |
394 VertexShaderQuadAA::VertexShaderQuadAA() | 438 VertexShaderQuadAA::VertexShaderQuadAA() |
395 : matrix_location_(-1), | 439 : matrix_location_(-1), |
396 viewport_location_(-1), | 440 viewport_location_(-1), |
397 quad_location_(-1), | 441 quad_location_(-1), |
398 edge_location_(-1) { | 442 edge_location_(-1) { |
399 } | 443 } |
400 | 444 |
401 void VertexShaderQuadAA::Init(GLES2Interface* context, | 445 void VertexShaderQuadAA::Init(GLES2Interface* context, |
402 unsigned program, | 446 unsigned program, |
403 int* base_uniform_index) { | 447 int* base_uniform_index) { |
404 static const char* uniforms[] = { | 448 static const char* uniforms[] = { |
405 "matrix", "viewport", "quad", "edge", | 449 "matrix", "viewport", "quad", "edge", |
406 }; | 450 }; |
407 int locations[arraysize(uniforms)]; | 451 int locations[arraysize(uniforms)]; |
408 | 452 |
409 GetProgramUniformLocations(context, | 453 GetProgramUniformLocations(context, |
410 program, | 454 program, |
411 arraysize(uniforms), | 455 arraysize(uniforms), |
412 uniforms, | 456 uniforms, |
413 locations, | 457 locations, |
414 base_uniform_index); | 458 base_uniform_index); |
415 matrix_location_ = locations[0]; | 459 matrix_location_ = locations[0]; |
416 viewport_location_ = locations[1]; | 460 viewport_location_ = locations[1]; |
417 quad_location_ = locations[2]; | 461 quad_location_ = locations[2]; |
418 edge_location_ = locations[3]; | 462 edge_location_ = locations[3]; |
419 } | 463 } |
420 | 464 |
421 std::string VertexShaderQuadAA::GetShaderString() const { | 465 std::string VertexShaderQuadAA::GetShaderString() const { |
422 // clang-format off | 466 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
423 return VERTEX_SHADER( | 467 } |
424 // clang-format on | |
425 attribute TexCoordPrecision vec4 a_position; | |
426 attribute float a_index; | |
427 uniform mat4 matrix; | |
428 uniform vec4 viewport; | |
429 uniform TexCoordPrecision vec2 quad[4]; | |
430 uniform TexCoordPrecision vec3 edge[8]; | |
431 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
432 | 468 |
433 void main() { | 469 std::string VertexShaderQuadAA::GetShaderHead() { |
434 vec2 pos = quad[int(a_index)]; // NOLINT | 470 return SHADER0([]() { |
435 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 471 attribute TexCoordPrecision vec4 a_position; |
436 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); | 472 attribute float a_index; |
437 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); | 473 uniform mat4 matrix; |
438 edge_dist[0] = vec4(dot(edge[0], screen_pos), | 474 uniform vec4 viewport; |
439 dot(edge[1], screen_pos), | 475 uniform TexCoordPrecision vec2 quad[4]; |
440 dot(edge[2], screen_pos), | 476 uniform TexCoordPrecision vec3 edge[8]; |
441 dot(edge[3], screen_pos)) * | 477 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
442 gl_Position.w; | 478 }); |
443 edge_dist[1] = vec4(dot(edge[4], screen_pos), | 479 } |
444 dot(edge[5], screen_pos), | 480 |
445 dot(edge[6], screen_pos), | 481 std::string VertexShaderQuadAA::GetShaderBody() { |
446 dot(edge[7], screen_pos)) * | 482 return SHADER0([]() { |
447 gl_Position.w; | 483 void main() { |
448 } | 484 vec2 pos = quad[int(a_index)]; // NOLINT |
449 // clang-format off | 485 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
450 ); // NOLINT(whitespace/parens) | 486 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); |
451 // clang-format on | 487 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); |
| 488 edge_dist[0] = vec4(dot(edge[0], screen_pos), dot(edge[1], screen_pos), |
| 489 dot(edge[2], screen_pos), dot(edge[3], screen_pos)) * |
| 490 gl_Position.w; |
| 491 edge_dist[1] = vec4(dot(edge[4], screen_pos), dot(edge[5], screen_pos), |
| 492 dot(edge[6], screen_pos), dot(edge[7], screen_pos)) * |
| 493 gl_Position.w; |
| 494 } |
| 495 }); |
452 } | 496 } |
453 | 497 |
454 VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA() | 498 VertexShaderQuadTexTransformAA::VertexShaderQuadTexTransformAA() |
455 : matrix_location_(-1), | 499 : matrix_location_(-1), |
456 viewport_location_(-1), | 500 viewport_location_(-1), |
457 quad_location_(-1), | 501 quad_location_(-1), |
458 edge_location_(-1), | 502 edge_location_(-1), |
459 tex_transform_location_(-1) { | 503 tex_transform_location_(-1) { |
460 } | 504 } |
461 | 505 |
(...skipping 12 matching lines...) Expand all Loading... |
474 locations, | 518 locations, |
475 base_uniform_index); | 519 base_uniform_index); |
476 matrix_location_ = locations[0]; | 520 matrix_location_ = locations[0]; |
477 viewport_location_ = locations[1]; | 521 viewport_location_ = locations[1]; |
478 quad_location_ = locations[2]; | 522 quad_location_ = locations[2]; |
479 edge_location_ = locations[3]; | 523 edge_location_ = locations[3]; |
480 tex_transform_location_ = locations[4]; | 524 tex_transform_location_ = locations[4]; |
481 } | 525 } |
482 | 526 |
483 std::string VertexShaderQuadTexTransformAA::GetShaderString() const { | 527 std::string VertexShaderQuadTexTransformAA::GetShaderString() const { |
484 // clang-format off | 528 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
485 return VERTEX_SHADER( | 529 } |
486 // clang-format on | |
487 attribute TexCoordPrecision vec4 a_position; | |
488 attribute float a_index; | |
489 uniform mat4 matrix; | |
490 uniform vec4 viewport; | |
491 uniform TexCoordPrecision vec2 quad[4]; | |
492 uniform TexCoordPrecision vec3 edge[8]; | |
493 uniform TexCoordPrecision vec4 texTrans; | |
494 varying TexCoordPrecision vec2 v_texCoord; | |
495 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
496 | 530 |
497 void main() { | 531 std::string VertexShaderQuadTexTransformAA::GetShaderHead() { |
498 vec2 pos = quad[int(a_index)]; // NOLINT | 532 return SHADER0([]() { |
499 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 533 attribute TexCoordPrecision vec4 a_position; |
500 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); | 534 attribute float a_index; |
501 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); | 535 uniform mat4 matrix; |
502 edge_dist[0] = vec4(dot(edge[0], screen_pos), | 536 uniform vec4 viewport; |
503 dot(edge[1], screen_pos), | 537 uniform TexCoordPrecision vec2 quad[4]; |
504 dot(edge[2], screen_pos), | 538 uniform TexCoordPrecision vec3 edge[8]; |
505 dot(edge[3], screen_pos)) * | 539 uniform TexCoordPrecision vec4 texTrans; |
506 gl_Position.w; | 540 varying TexCoordPrecision vec2 v_texCoord; |
507 edge_dist[1] = vec4(dot(edge[4], screen_pos), | 541 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
508 dot(edge[5], screen_pos), | 542 }); |
509 dot(edge[6], screen_pos), | 543 } |
510 dot(edge[7], screen_pos)) * | 544 |
511 gl_Position.w; | 545 std::string VertexShaderQuadTexTransformAA::GetShaderBody() { |
512 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy; | 546 return SHADER0([]() { |
513 } | 547 void main() { |
514 // clang-format off | 548 vec2 pos = quad[int(a_index)]; // NOLINT |
515 ); // NOLINT(whitespace/parens) | 549 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
516 // clang-format on | 550 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); |
| 551 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); |
| 552 edge_dist[0] = vec4(dot(edge[0], screen_pos), dot(edge[1], screen_pos), |
| 553 dot(edge[2], screen_pos), dot(edge[3], screen_pos)) * |
| 554 gl_Position.w; |
| 555 edge_dist[1] = vec4(dot(edge[4], screen_pos), dot(edge[5], screen_pos), |
| 556 dot(edge[6], screen_pos), dot(edge[7], screen_pos)) * |
| 557 gl_Position.w; |
| 558 v_texCoord = (pos.xy + vec2(0.5)) * texTrans.zw + texTrans.xy; |
| 559 } |
| 560 }); |
517 } | 561 } |
518 | 562 |
519 VertexShaderTile::VertexShaderTile() | 563 VertexShaderTile::VertexShaderTile() |
520 : matrix_location_(-1), | 564 : matrix_location_(-1), |
521 quad_location_(-1), | 565 quad_location_(-1), |
522 vertex_tex_transform_location_(-1) { | 566 vertex_tex_transform_location_(-1) { |
523 } | 567 } |
524 | 568 |
525 void VertexShaderTile::Init(GLES2Interface* context, | 569 void VertexShaderTile::Init(GLES2Interface* context, |
526 unsigned program, | 570 unsigned program, |
527 int* base_uniform_index) { | 571 int* base_uniform_index) { |
528 static const char* uniforms[] = { | 572 static const char* uniforms[] = { |
529 "matrix", "quad", "vertexTexTransform", | 573 "matrix", "quad", "vertexTexTransform", |
530 }; | 574 }; |
531 int locations[arraysize(uniforms)]; | 575 int locations[arraysize(uniforms)]; |
532 | 576 |
533 GetProgramUniformLocations(context, | 577 GetProgramUniformLocations(context, |
534 program, | 578 program, |
535 arraysize(uniforms), | 579 arraysize(uniforms), |
536 uniforms, | 580 uniforms, |
537 locations, | 581 locations, |
538 base_uniform_index); | 582 base_uniform_index); |
539 matrix_location_ = locations[0]; | 583 matrix_location_ = locations[0]; |
540 quad_location_ = locations[1]; | 584 quad_location_ = locations[1]; |
541 vertex_tex_transform_location_ = locations[2]; | 585 vertex_tex_transform_location_ = locations[2]; |
542 } | 586 } |
543 | 587 |
544 std::string VertexShaderTile::GetShaderString() const { | 588 std::string VertexShaderTile::GetShaderString() const { |
545 // clang-format off | 589 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
546 return VERTEX_SHADER( | 590 } |
547 // clang-format on | 591 |
548 attribute TexCoordPrecision vec4 a_position; | 592 std::string VertexShaderTile::GetShaderHead() { |
549 attribute TexCoordPrecision vec2 a_texCoord; | 593 return SHADER0([]() { |
550 attribute float a_index; | 594 attribute TexCoordPrecision vec4 a_position; |
551 uniform mat4 matrix; | 595 attribute TexCoordPrecision vec2 a_texCoord; |
552 uniform TexCoordPrecision vec2 quad[4]; | 596 attribute float a_index; |
553 uniform TexCoordPrecision vec4 vertexTexTransform; | 597 uniform mat4 matrix; |
554 varying TexCoordPrecision vec2 v_texCoord; | 598 uniform TexCoordPrecision vec2 quad[4]; |
555 void main() { | 599 uniform TexCoordPrecision vec4 vertexTexTransform; |
556 vec2 pos = quad[int(a_index)]; // NOLINT | 600 varying TexCoordPrecision vec2 v_texCoord; |
557 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 601 }); |
558 v_texCoord = a_texCoord * vertexTexTransform.zw + vertexTexTransform.xy; | 602 } |
559 } | 603 |
560 // clang-format off | 604 std::string VertexShaderTile::GetShaderBody() { |
561 ); // NOLINT(whitespace/parens) | 605 return SHADER0([]() { |
562 // clang-format on | 606 void main() { |
| 607 vec2 pos = quad[int(a_index)]; // NOLINT |
| 608 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
| 609 v_texCoord = a_texCoord * vertexTexTransform.zw + vertexTexTransform.xy; |
| 610 } |
| 611 }); |
563 } | 612 } |
564 | 613 |
565 VertexShaderTileAA::VertexShaderTileAA() | 614 VertexShaderTileAA::VertexShaderTileAA() |
566 : matrix_location_(-1), | 615 : matrix_location_(-1), |
567 viewport_location_(-1), | 616 viewport_location_(-1), |
568 quad_location_(-1), | 617 quad_location_(-1), |
569 edge_location_(-1), | 618 edge_location_(-1), |
570 vertex_tex_transform_location_(-1) { | 619 vertex_tex_transform_location_(-1) { |
571 } | 620 } |
572 | 621 |
(...skipping 12 matching lines...) Expand all Loading... |
585 locations, | 634 locations, |
586 base_uniform_index); | 635 base_uniform_index); |
587 matrix_location_ = locations[0]; | 636 matrix_location_ = locations[0]; |
588 viewport_location_ = locations[1]; | 637 viewport_location_ = locations[1]; |
589 quad_location_ = locations[2]; | 638 quad_location_ = locations[2]; |
590 edge_location_ = locations[3]; | 639 edge_location_ = locations[3]; |
591 vertex_tex_transform_location_ = locations[4]; | 640 vertex_tex_transform_location_ = locations[4]; |
592 } | 641 } |
593 | 642 |
594 std::string VertexShaderTileAA::GetShaderString() const { | 643 std::string VertexShaderTileAA::GetShaderString() const { |
595 // clang-format off | 644 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
596 return VERTEX_SHADER( | 645 } |
597 // clang-format on | |
598 attribute TexCoordPrecision vec4 a_position; | |
599 attribute float a_index; | |
600 uniform mat4 matrix; | |
601 uniform vec4 viewport; | |
602 uniform TexCoordPrecision vec2 quad[4]; | |
603 uniform TexCoordPrecision vec3 edge[8]; | |
604 uniform TexCoordPrecision vec4 vertexTexTransform; | |
605 varying TexCoordPrecision vec2 v_texCoord; | |
606 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
607 | 646 |
608 void main() { | 647 std::string VertexShaderTileAA::GetShaderHead() { |
609 vec2 pos = quad[int(a_index)]; // NOLINT | 648 return SHADER0([]() { |
610 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); | 649 attribute TexCoordPrecision vec4 a_position; |
611 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); | 650 attribute float a_index; |
612 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); | 651 uniform mat4 matrix; |
613 edge_dist[0] = vec4(dot(edge[0], screen_pos), | 652 uniform vec4 viewport; |
614 dot(edge[1], screen_pos), | 653 uniform TexCoordPrecision vec2 quad[4]; |
615 dot(edge[2], screen_pos), | 654 uniform TexCoordPrecision vec3 edge[8]; |
616 dot(edge[3], screen_pos)) * | 655 uniform TexCoordPrecision vec4 vertexTexTransform; |
617 gl_Position.w; | 656 varying TexCoordPrecision vec2 v_texCoord; |
618 edge_dist[1] = vec4(dot(edge[4], screen_pos), | 657 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
619 dot(edge[5], screen_pos), | 658 }); |
620 dot(edge[6], screen_pos), | 659 } |
621 dot(edge[7], screen_pos)) * | 660 |
622 gl_Position.w; | 661 std::string VertexShaderTileAA::GetShaderBody() { |
623 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; | 662 return SHADER0([]() { |
624 } | 663 void main() { |
625 // clang-format off | 664 vec2 pos = quad[int(a_index)]; // NOLINT |
626 ); // NOLINT(whitespace/parens) | 665 gl_Position = matrix * vec4(pos, a_position.z, a_position.w); |
627 // clang-format on | 666 vec2 ndc_pos = 0.5 * (1.0 + gl_Position.xy / gl_Position.w); |
| 667 vec3 screen_pos = vec3(viewport.xy + viewport.zw * ndc_pos, 1.0); |
| 668 edge_dist[0] = vec4(dot(edge[0], screen_pos), dot(edge[1], screen_pos), |
| 669 dot(edge[2], screen_pos), dot(edge[3], screen_pos)) * |
| 670 gl_Position.w; |
| 671 edge_dist[1] = vec4(dot(edge[4], screen_pos), dot(edge[5], screen_pos), |
| 672 dot(edge[6], screen_pos), dot(edge[7], screen_pos)) * |
| 673 gl_Position.w; |
| 674 v_texCoord = pos.xy * vertexTexTransform.zw + vertexTexTransform.xy; |
| 675 } |
| 676 }); |
628 } | 677 } |
629 | 678 |
630 VertexShaderVideoTransform::VertexShaderVideoTransform() | 679 VertexShaderVideoTransform::VertexShaderVideoTransform() |
631 : matrix_location_(-1), tex_matrix_location_(-1) { | 680 : matrix_location_(-1), tex_matrix_location_(-1) { |
632 } | 681 } |
633 | 682 |
634 void VertexShaderVideoTransform::Init(GLES2Interface* context, | 683 void VertexShaderVideoTransform::Init(GLES2Interface* context, |
635 unsigned program, | 684 unsigned program, |
636 int* base_uniform_index) { | 685 int* base_uniform_index) { |
637 static const char* uniforms[] = { | 686 static const char* uniforms[] = { |
638 "matrix", "texMatrix", | 687 "matrix", "texMatrix", |
639 }; | 688 }; |
640 int locations[arraysize(uniforms)]; | 689 int locations[arraysize(uniforms)]; |
641 | 690 |
642 GetProgramUniformLocations(context, | 691 GetProgramUniformLocations(context, |
643 program, | 692 program, |
644 arraysize(uniforms), | 693 arraysize(uniforms), |
645 uniforms, | 694 uniforms, |
646 locations, | 695 locations, |
647 base_uniform_index); | 696 base_uniform_index); |
648 matrix_location_ = locations[0]; | 697 matrix_location_ = locations[0]; |
649 tex_matrix_location_ = locations[1]; | 698 tex_matrix_location_ = locations[1]; |
650 } | 699 } |
651 | 700 |
652 std::string VertexShaderVideoTransform::GetShaderString() const { | 701 std::string VertexShaderVideoTransform::GetShaderString() const { |
653 // clang-format off | 702 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
654 return VERTEX_SHADER( | 703 } |
655 // clang-format on | 704 |
656 attribute vec4 a_position; | 705 std::string VertexShaderVideoTransform::GetShaderHead() { |
657 attribute TexCoordPrecision vec2 a_texCoord; | 706 return SHADER0([]() { |
658 uniform mat4 matrix; | 707 attribute vec4 a_position; |
659 uniform TexCoordPrecision mat4 texMatrix; | 708 attribute TexCoordPrecision vec2 a_texCoord; |
660 varying TexCoordPrecision vec2 v_texCoord; | 709 uniform mat4 matrix; |
661 void main() { | 710 uniform TexCoordPrecision mat4 texMatrix; |
662 gl_Position = matrix * a_position; | 711 varying TexCoordPrecision vec2 v_texCoord; |
663 v_texCoord = | 712 }); |
664 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 713 } |
665 } | 714 |
666 // clang-format off | 715 std::string VertexShaderVideoTransform::GetShaderBody() { |
667 ); // NOLINT(whitespace/parens) | 716 return SHADER0([]() { |
668 // clang-format on | 717 void main() { |
| 718 gl_Position = matrix * a_position; |
| 719 v_texCoord = |
| 720 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
| 721 } |
| 722 }); |
669 } | 723 } |
670 | 724 |
671 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" | 725 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" |
672 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 2 : 0) | 726 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 2 : 0) |
673 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ | 727 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ |
674 if (has_blend_mode()) { \ | 728 if (has_blend_mode()) { \ |
675 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ | 729 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ |
676 backdrop_location_ = locations[POS]; \ | 730 backdrop_location_ = locations[POS]; \ |
677 backdrop_rect_location_ = locations[POS + 1]; \ | 731 backdrop_rect_location_ = locations[POS + 1]; \ |
678 } | 732 } |
679 | 733 |
680 FragmentTexBlendMode::FragmentTexBlendMode() | 734 FragmentTexBlendMode::FragmentTexBlendMode() |
681 : backdrop_location_(-1), | 735 : backdrop_location_(-1), |
682 backdrop_rect_location_(-1), | 736 backdrop_rect_location_(-1), |
683 blend_mode_(BlendModeNone) { | 737 blend_mode_(BlendModeNone) { |
684 } | 738 } |
685 | 739 |
686 std::string FragmentTexBlendMode::SetBlendModeFunctions( | 740 std::string FragmentTexBlendMode::SetBlendModeFunctions( |
687 std::string shader_string) const { | 741 std::string shader_string) const { |
688 if (shader_string.find("ApplyBlendMode") == std::string::npos) | 742 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
689 return shader_string; | 743 return shader_string; |
690 | 744 |
691 if (!has_blend_mode()) { | 745 if (!has_blend_mode()) { |
692 return "#define ApplyBlendMode(X) (X)\n" + shader_string; | 746 return "#define ApplyBlendMode(X) (X)\n" + shader_string; |
693 } | 747 } |
694 | 748 |
695 // clang-format off | 749 static const std::string kFunctionApplyBlendMode = SHADER0([]() { |
696 static const std::string kFunctionApplyBlendMode = SHADER0( | 750 uniform sampler2D s_backdropTexture; |
697 // clang-format on | 751 uniform TexCoordPrecision vec4 backdropRect; |
698 uniform sampler2D s_backdropTexture; | |
699 uniform TexCoordPrecision vec4 backdropRect; | |
700 | 752 |
701 vec4 GetBackdropColor() { | 753 vec4 GetBackdropColor() { |
702 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; | 754 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; |
703 bgTexCoord.x /= backdropRect.z; | 755 bgTexCoord.x /= backdropRect.z; |
704 bgTexCoord.y /= backdropRect.w; | 756 bgTexCoord.y /= backdropRect.w; |
705 return texture2D(s_backdropTexture, bgTexCoord); | 757 return texture2D(s_backdropTexture, bgTexCoord); |
706 } | 758 } |
707 | 759 |
708 vec4 ApplyBlendMode(vec4 src) { | 760 vec4 ApplyBlendMode(vec4 src) { |
709 vec4 dst = GetBackdropColor(); | 761 vec4 dst = GetBackdropColor(); |
710 return Blend(src, dst); | 762 return Blend(src, dst); |
711 } | 763 } |
712 // clang-format off | 764 }); |
713 ); // NOLINT(whitespace/parens) | |
714 // clang-format on | |
715 | 765 |
716 return "precision mediump float;" + GetHelperFunctions() + | 766 return "precision mediump float;" + GetHelperFunctions() + |
717 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; | 767 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; |
718 } | 768 } |
719 | 769 |
720 std::string FragmentTexBlendMode::GetHelperFunctions() const { | 770 std::string FragmentTexBlendMode::GetHelperFunctions() const { |
721 // clang-format off | 771 static const std::string kFunctionHardLight = SHADER0([]() { |
722 static const std::string kFunctionHardLight = SHADER0( | 772 vec3 hardLight(vec4 src, vec4 dst) { |
723 // clang-format on | 773 vec3 result; |
724 vec3 hardLight(vec4 src, vec4 dst) { | 774 result.r = |
| 775 (2.0 * src.r <= src.a) |
| 776 ? (2.0 * src.r * dst.r) |
| 777 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); |
| 778 result.g = |
| 779 (2.0 * src.g <= src.a) |
| 780 ? (2.0 * src.g * dst.g) |
| 781 : (src.a * dst.a - 2.0 * (dst.a - dst.g) * (src.a - src.g)); |
| 782 result.b = |
| 783 (2.0 * src.b <= src.a) |
| 784 ? (2.0 * src.b * dst.b) |
| 785 : (src.a * dst.a - 2.0 * (dst.a - dst.b) * (src.a - src.b)); |
| 786 result.rgb += src.rgb * (1.0 - dst.a) + dst.rgb * (1.0 - src.a); |
| 787 return result; |
| 788 } |
| 789 }); |
| 790 |
| 791 static const std::string kFunctionColorDodgeComponent = SHADER0([]() { |
| 792 float getColorDodgeComponent(float srcc, float srca, float dstc, |
| 793 float dsta) { |
| 794 if (0.0 == dstc) |
| 795 return srcc * (1.0 - dsta); |
| 796 float d = srca - srcc; |
| 797 if (0.0 == d) |
| 798 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 799 d = min(dsta, dstc * srca / d); |
| 800 return d * srca + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 801 } |
| 802 }); |
| 803 |
| 804 static const std::string kFunctionColorBurnComponent = SHADER0([]() { |
| 805 float getColorBurnComponent(float srcc, float srca, float dstc, |
| 806 float dsta) { |
| 807 if (dsta == dstc) |
| 808 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 809 if (0.0 == srcc) |
| 810 return dstc * (1.0 - srca); |
| 811 float d = max(0.0, dsta - (dsta - dstc) * srca / srcc); |
| 812 return srca * d + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 813 } |
| 814 }); |
| 815 |
| 816 static const std::string kFunctionSoftLightComponentPosDstAlpha = |
| 817 SHADER0([]() { |
| 818 float getSoftLightComponent(float srcc, float srca, float dstc, |
| 819 float dsta) { |
| 820 if (2.0 * srcc <= srca) { |
| 821 return (dstc * dstc * (srca - 2.0 * srcc)) / dsta + |
| 822 (1.0 - dsta) * srcc + dstc * (-srca + 2.0 * srcc + 1.0); |
| 823 } else if (4.0 * dstc <= dsta) { |
| 824 float DSqd = dstc * dstc; |
| 825 float DCub = DSqd * dstc; |
| 826 float DaSqd = dsta * dsta; |
| 827 float DaCub = DaSqd * dsta; |
| 828 return (-DaCub * srcc + |
| 829 DaSqd * (srcc - dstc * (3.0 * srca - 6.0 * srcc - 1.0)) + |
| 830 12.0 * dsta * DSqd * (srca - 2.0 * srcc) - |
| 831 16.0 * DCub * (srca - 2.0 * srcc)) / |
| 832 DaSqd; |
| 833 } else { |
| 834 return -sqrt(dsta * dstc) * (srca - 2.0 * srcc) - dsta * srcc + |
| 835 dstc * (srca - 2.0 * srcc + 1.0) + srcc; |
| 836 } |
| 837 } |
| 838 }); |
| 839 |
| 840 static const std::string kFunctionLum = SHADER0([]() { |
| 841 float luminance(vec3 color) { return dot(vec3(0.3, 0.59, 0.11), color); } |
| 842 |
| 843 vec3 set_luminance(vec3 hueSat, float alpha, vec3 lumColor) { |
| 844 float diff = luminance(lumColor - hueSat); |
| 845 vec3 outColor = hueSat + diff; |
| 846 float outLum = luminance(outColor); |
| 847 float minComp = min(min(outColor.r, outColor.g), outColor.b); |
| 848 float maxComp = max(max(outColor.r, outColor.g), outColor.b); |
| 849 if (minComp < 0.0 && outLum != minComp) { |
| 850 outColor = outLum + |
| 851 ((outColor - vec3(outLum, outLum, outLum)) * outLum) / |
| 852 (outLum - minComp); |
| 853 } |
| 854 if (maxComp > alpha && maxComp != outLum) { |
| 855 outColor = |
| 856 outLum + |
| 857 ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / |
| 858 (maxComp - outLum); |
| 859 } |
| 860 return outColor; |
| 861 } |
| 862 }); |
| 863 |
| 864 static const std::string kFunctionSat = SHADER0([]() { |
| 865 float saturation(vec3 color) { |
| 866 return max(max(color.r, color.g), color.b) - |
| 867 min(min(color.r, color.g), color.b); |
| 868 } |
| 869 |
| 870 vec3 set_saturation_helper(float minComp, float midComp, float maxComp, |
| 871 float sat) { |
| 872 if (minComp < maxComp) { |
725 vec3 result; | 873 vec3 result; |
726 result.r = | 874 result.r = 0.0; |
727 (2.0 * src.r <= src.a) | 875 result.g = sat * (midComp - minComp) / (maxComp - minComp); |
728 ? (2.0 * src.r * dst.r) | 876 result.b = sat; |
729 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); | |
730 result.g = | |
731 (2.0 * src.g <= src.a) | |
732 ? (2.0 * src.g * dst.g) | |
733 : (src.a * dst.a - 2.0 * (dst.a - dst.g) * (src.a - src.g)); | |
734 result.b = | |
735 (2.0 * src.b <= src.a) | |
736 ? (2.0 * src.b * dst.b) | |
737 : (src.a * dst.a - 2.0 * (dst.a - dst.b) * (src.a - src.b)); | |
738 result.rgb += src.rgb * (1.0 - dst.a) + dst.rgb * (1.0 - src.a); | |
739 return result; | 877 return result; |
| 878 } else { |
| 879 return vec3(0, 0, 0); |
740 } | 880 } |
741 // clang-format off | 881 } |
742 ); // NOLINT(whitespace/parens) | |
743 | 882 |
744 static const std::string kFunctionColorDodgeComponent = SHADER0( | 883 vec3 set_saturation(vec3 hueLumColor, vec3 satColor) { |
745 // clang-format on | 884 float sat = saturation(satColor); |
746 float getColorDodgeComponent( | 885 if (hueLumColor.r <= hueLumColor.g) { |
747 float srcc, float srca, float dstc, float dsta) { | 886 if (hueLumColor.g <= hueLumColor.b) { |
748 if (0.0 == dstc) | 887 hueLumColor.rgb = set_saturation_helper(hueLumColor.r, hueLumColor.g, |
749 return srcc * (1.0 - dsta); | 888 hueLumColor.b, sat); |
750 float d = srca - srcc; | 889 } else if (hueLumColor.r <= hueLumColor.b) { |
751 if (0.0 == d) | 890 hueLumColor.rbg = set_saturation_helper(hueLumColor.r, hueLumColor.b, |
752 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | 891 hueLumColor.g, sat); |
753 d = min(dsta, dstc * srca / d); | 892 } else { |
754 return d * srca + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | 893 hueLumColor.brg = set_saturation_helper(hueLumColor.b, hueLumColor.r, |
| 894 hueLumColor.g, sat); |
| 895 } |
| 896 } else if (hueLumColor.r <= hueLumColor.b) { |
| 897 hueLumColor.grb = set_saturation_helper(hueLumColor.g, hueLumColor.r, |
| 898 hueLumColor.b, sat); |
| 899 } else if (hueLumColor.g <= hueLumColor.b) { |
| 900 hueLumColor.gbr = set_saturation_helper(hueLumColor.g, hueLumColor.b, |
| 901 hueLumColor.r, sat); |
| 902 } else { |
| 903 hueLumColor.bgr = set_saturation_helper(hueLumColor.b, hueLumColor.g, |
| 904 hueLumColor.r, sat); |
755 } | 905 } |
756 // clang-format off | 906 return hueLumColor; |
757 ); // NOLINT(whitespace/parens) | 907 } |
758 | 908 }); |
759 static const std::string kFunctionColorBurnComponent = SHADER0( | |
760 // clang-format on | |
761 float getColorBurnComponent( | |
762 float srcc, float srca, float dstc, float dsta) { | |
763 if (dsta == dstc) | |
764 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | |
765 if (0.0 == srcc) | |
766 return dstc * (1.0 - srca); | |
767 float d = max(0.0, dsta - (dsta - dstc) * srca / srcc); | |
768 return srca * d + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | |
769 } | |
770 // clang-format off | |
771 ); // NOLINT(whitespace/parens) | |
772 | |
773 static const std::string kFunctionSoftLightComponentPosDstAlpha = SHADER0( | |
774 // clang-format on | |
775 float getSoftLightComponent( | |
776 float srcc, float srca, float dstc, float dsta) { | |
777 if (2.0 * srcc <= srca) { | |
778 return (dstc * dstc * (srca - 2.0 * srcc)) / dsta + | |
779 (1.0 - dsta) * srcc + dstc * (-srca + 2.0 * srcc + 1.0); | |
780 } else if (4.0 * dstc <= dsta) { | |
781 float DSqd = dstc * dstc; | |
782 float DCub = DSqd * dstc; | |
783 float DaSqd = dsta * dsta; | |
784 float DaCub = DaSqd * dsta; | |
785 return (-DaCub * srcc + | |
786 DaSqd * (srcc - dstc * (3.0 * srca - 6.0 * srcc - 1.0)) + | |
787 12.0 * dsta * DSqd * (srca - 2.0 * srcc) - | |
788 16.0 * DCub * (srca - 2.0 * srcc)) / | |
789 DaSqd; | |
790 } else { | |
791 return -sqrt(dsta * dstc) * (srca - 2.0 * srcc) - dsta * srcc + | |
792 dstc * (srca - 2.0 * srcc + 1.0) + srcc; | |
793 } | |
794 } | |
795 // clang-format off | |
796 ); // NOLINT(whitespace/parens) | |
797 | |
798 static const std::string kFunctionLum = SHADER0( | |
799 // clang-format on | |
800 float luminance(vec3 color) { return dot(vec3(0.3, 0.59, 0.11), color); } | |
801 | |
802 vec3 set_luminance(vec3 hueSat, float alpha, vec3 lumColor) { | |
803 float diff = luminance(lumColor - hueSat); | |
804 vec3 outColor = hueSat + diff; | |
805 float outLum = luminance(outColor); | |
806 float minComp = min(min(outColor.r, outColor.g), outColor.b); | |
807 float maxComp = max(max(outColor.r, outColor.g), outColor.b); | |
808 if (minComp < 0.0 && outLum != minComp) { | |
809 outColor = outLum + | |
810 ((outColor - vec3(outLum, outLum, outLum)) * outLum) / | |
811 (outLum - minComp); | |
812 } | |
813 if (maxComp > alpha && maxComp != outLum) { | |
814 outColor = | |
815 outLum + | |
816 ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / | |
817 (maxComp - outLum); | |
818 } | |
819 return outColor; | |
820 } | |
821 // clang-format off | |
822 ); // NOLINT(whitespace/parens) | |
823 | |
824 static const std::string kFunctionSat = SHADER0( | |
825 // clang-format on | |
826 float saturation(vec3 color) { | |
827 return max(max(color.r, color.g), color.b) - | |
828 min(min(color.r, color.g), color.b); | |
829 } | |
830 | |
831 vec3 set_saturation_helper( | |
832 float minComp, float midComp, float maxComp, float sat) { | |
833 if (minComp < maxComp) { | |
834 vec3 result; | |
835 result.r = 0.0; | |
836 result.g = sat * (midComp - minComp) / (maxComp - minComp); | |
837 result.b = sat; | |
838 return result; | |
839 } else { | |
840 return vec3(0, 0, 0); | |
841 } | |
842 } | |
843 | |
844 vec3 set_saturation(vec3 hueLumColor, vec3 satColor) { | |
845 float sat = saturation(satColor); | |
846 if (hueLumColor.r <= hueLumColor.g) { | |
847 if (hueLumColor.g <= hueLumColor.b) { | |
848 hueLumColor.rgb = set_saturation_helper( | |
849 hueLumColor.r, hueLumColor.g, hueLumColor.b, sat); | |
850 } else if (hueLumColor.r <= hueLumColor.b) { | |
851 hueLumColor.rbg = set_saturation_helper( | |
852 hueLumColor.r, hueLumColor.b, hueLumColor.g, sat); | |
853 } else { | |
854 hueLumColor.brg = set_saturation_helper( | |
855 hueLumColor.b, hueLumColor.r, hueLumColor.g, sat); | |
856 } | |
857 } else if (hueLumColor.r <= hueLumColor.b) { | |
858 hueLumColor.grb = set_saturation_helper( | |
859 hueLumColor.g, hueLumColor.r, hueLumColor.b, sat); | |
860 } else if (hueLumColor.g <= hueLumColor.b) { | |
861 hueLumColor.gbr = set_saturation_helper( | |
862 hueLumColor.g, hueLumColor.b, hueLumColor.r, sat); | |
863 } else { | |
864 hueLumColor.bgr = set_saturation_helper( | |
865 hueLumColor.b, hueLumColor.g, hueLumColor.r, sat); | |
866 } | |
867 return hueLumColor; | |
868 } | |
869 // clang-format off | |
870 ); // NOLINT(whitespace/parens) | |
871 // clang-format on | |
872 | 909 |
873 switch (blend_mode_) { | 910 switch (blend_mode_) { |
874 case BlendModeOverlay: | 911 case BlendModeOverlay: |
875 case BlendModeHardLight: | 912 case BlendModeHardLight: |
876 return kFunctionHardLight; | 913 return kFunctionHardLight; |
877 case BlendModeColorDodge: | 914 case BlendModeColorDodge: |
878 return kFunctionColorDodgeComponent; | 915 return kFunctionColorDodgeComponent; |
879 case BlendModeColorBurn: | 916 case BlendModeColorBurn: |
880 return kFunctionColorBurnComponent; | 917 return kFunctionColorBurnComponent; |
881 case BlendModeSoftLight: | 918 case BlendModeSoftLight: |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 arraysize(uniforms), | 1078 arraysize(uniforms), |
1042 uniforms, | 1079 uniforms, |
1043 locations, | 1080 locations, |
1044 base_uniform_index); | 1081 base_uniform_index); |
1045 sampler_location_ = locations[0]; | 1082 sampler_location_ = locations[0]; |
1046 } | 1083 } |
1047 | 1084 |
1048 std::string FragmentShaderRGBATexAlpha::GetShaderString( | 1085 std::string FragmentShaderRGBATexAlpha::GetShaderString( |
1049 TexCoordPrecision precision, | 1086 TexCoordPrecision precision, |
1050 SamplerType sampler) const { | 1087 SamplerType sampler) const { |
1051 // clang-format off | 1088 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1052 return FRAGMENT_SHADER( | 1089 } |
1053 // clang-format on | 1090 |
1054 precision mediump float; | 1091 std::string FragmentShaderRGBATexAlpha::GetShaderHead() { |
1055 varying TexCoordPrecision vec2 v_texCoord; | 1092 return SHADER0([]() { |
1056 uniform SamplerType s_texture; | 1093 precision mediump float; |
1057 uniform float alpha; | 1094 varying TexCoordPrecision vec2 v_texCoord; |
1058 void main() { | 1095 uniform SamplerType s_texture; |
1059 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1096 uniform float alpha; |
1060 gl_FragColor = ApplyBlendMode(texColor * alpha); | 1097 }); |
1061 } | 1098 } |
1062 // clang-format off | 1099 |
1063 ); // NOLINT(whitespace/parens) | 1100 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { |
1064 // clang-format on | 1101 return SHADER0([]() { |
| 1102 void main() { |
| 1103 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1104 gl_FragColor = ApplyBlendMode(texColor * alpha); |
| 1105 } |
| 1106 }); |
1065 } | 1107 } |
1066 | 1108 |
1067 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( | 1109 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( |
1068 TexCoordPrecision precision, | 1110 TexCoordPrecision precision, |
1069 SamplerType sampler) const { | 1111 SamplerType sampler) const { |
1070 // clang-format off | 1112 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1071 return FRAGMENT_SHADER( | 1113 } |
1072 // clang-format on | 1114 |
1073 precision mediump float; | 1115 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderHead() { |
1074 varying TexCoordPrecision vec2 v_texCoord; | 1116 return SHADER0([]() { |
1075 uniform SamplerType s_texture; | 1117 precision mediump float; |
1076 uniform float alpha; | 1118 varying TexCoordPrecision vec2 v_texCoord; |
1077 uniform mat4 colorMatrix; | 1119 uniform SamplerType s_texture; |
1078 uniform vec4 colorOffset; | 1120 uniform float alpha; |
1079 void main() { | 1121 uniform mat4 colorMatrix; |
1080 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1122 uniform vec4 colorOffset; |
1081 float nonZeroAlpha = max(texColor.a, 0.00001); | 1123 }); |
1082 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1124 } |
1083 texColor = colorMatrix * texColor + colorOffset; | 1125 |
1084 texColor.rgb *= texColor.a; | 1126 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() { |
1085 texColor = clamp(texColor, 0.0, 1.0); | 1127 return SHADER0([]() { |
1086 gl_FragColor = ApplyBlendMode(texColor * alpha); | 1128 void main() { |
1087 } | 1129 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1088 // clang-format off | 1130 float nonZeroAlpha = max(texColor.a, 0.00001); |
1089 ); // NOLINT(whitespace/parens) | 1131 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1090 // clang-format on | 1132 texColor = colorMatrix * texColor + colorOffset; |
| 1133 texColor.rgb *= texColor.a; |
| 1134 texColor = clamp(texColor, 0.0, 1.0); |
| 1135 gl_FragColor = ApplyBlendMode(texColor * alpha); |
| 1136 } |
| 1137 }); |
1091 } | 1138 } |
1092 | 1139 |
1093 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 1140 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
1094 TexCoordPrecision precision, | 1141 TexCoordPrecision precision, |
1095 SamplerType sampler) const { | 1142 SamplerType sampler) const { |
1096 // clang-format off | 1143 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1097 return FRAGMENT_SHADER( | 1144 } |
1098 // clang-format on | 1145 |
1099 precision mediump float; | 1146 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderHead() { |
1100 varying TexCoordPrecision vec2 v_texCoord; | 1147 return SHADER0([]() { |
1101 varying float v_alpha; | 1148 precision mediump float; |
1102 uniform SamplerType s_texture; | 1149 varying TexCoordPrecision vec2 v_texCoord; |
1103 void main() { | 1150 varying float v_alpha; |
1104 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1151 uniform SamplerType s_texture; |
1105 gl_FragColor = texColor * v_alpha; | 1152 }); |
1106 } | 1153 } |
1107 // clang-format off | 1154 |
1108 ); // NOLINT(whitespace/parens) | 1155 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderBody() { |
1109 // clang-format on | 1156 return SHADER0([]() { |
| 1157 void main() { |
| 1158 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1159 gl_FragColor = texColor * v_alpha; |
| 1160 } |
| 1161 }); |
1110 } | 1162 } |
1111 | 1163 |
1112 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( | 1164 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( |
1113 TexCoordPrecision precision, | 1165 TexCoordPrecision precision, |
1114 SamplerType sampler) const { | 1166 SamplerType sampler) const { |
1115 // clang-format off | 1167 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1116 return FRAGMENT_SHADER( | 1168 } |
1117 // clang-format on | 1169 |
1118 precision mediump float; | 1170 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderHead() { |
1119 varying TexCoordPrecision vec2 v_texCoord; | 1171 return SHADER0([]() { |
1120 varying float v_alpha; | 1172 precision mediump float; |
1121 uniform SamplerType s_texture; | 1173 varying TexCoordPrecision vec2 v_texCoord; |
1122 void main() { | 1174 varying float v_alpha; |
1123 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1175 uniform SamplerType s_texture; |
1124 texColor.rgb *= texColor.a; | 1176 }); |
1125 gl_FragColor = texColor * v_alpha; | 1177 } |
1126 } | 1178 |
1127 // clang-format off | 1179 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderBody() { |
1128 ); // NOLINT(whitespace/parens) | 1180 return SHADER0([]() { |
1129 // clang-format on | 1181 void main() { |
| 1182 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1183 texColor.rgb *= texColor.a; |
| 1184 gl_FragColor = texColor * v_alpha; |
| 1185 } |
| 1186 }); |
1130 } | 1187 } |
1131 | 1188 |
1132 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() | 1189 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() |
1133 : background_color_location_(-1), sampler_location_(-1) { | 1190 : background_color_location_(-1), sampler_location_(-1) { |
1134 } | 1191 } |
1135 | 1192 |
1136 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, | 1193 void FragmentTexBackgroundBinding::Init(GLES2Interface* context, |
1137 unsigned program, | 1194 unsigned program, |
1138 int* base_uniform_index) { | 1195 int* base_uniform_index) { |
1139 static const char* uniforms[] = { | 1196 static const char* uniforms[] = { |
(...skipping 11 matching lines...) Expand all Loading... |
1151 sampler_location_ = locations[0]; | 1208 sampler_location_ = locations[0]; |
1152 DCHECK_NE(sampler_location_, -1); | 1209 DCHECK_NE(sampler_location_, -1); |
1153 | 1210 |
1154 background_color_location_ = locations[1]; | 1211 background_color_location_ = locations[1]; |
1155 DCHECK_NE(background_color_location_, -1); | 1212 DCHECK_NE(background_color_location_, -1); |
1156 } | 1213 } |
1157 | 1214 |
1158 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( | 1215 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( |
1159 TexCoordPrecision precision, | 1216 TexCoordPrecision precision, |
1160 SamplerType sampler) const { | 1217 SamplerType sampler) const { |
1161 // clang-format off | 1218 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1162 return FRAGMENT_SHADER( | 1219 } |
1163 // clang-format on | 1220 |
1164 precision mediump float; | 1221 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderHead() { |
1165 varying TexCoordPrecision vec2 v_texCoord; | 1222 return SHADER0([]() { |
1166 varying float v_alpha; | 1223 precision mediump float; |
1167 uniform vec4 background_color; | 1224 varying TexCoordPrecision vec2 v_texCoord; |
1168 uniform SamplerType s_texture; | 1225 varying float v_alpha; |
1169 void main() { | 1226 uniform vec4 background_color; |
1170 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1227 uniform SamplerType s_texture; |
1171 texColor += background_color * (1.0 - texColor.a); | 1228 }); |
1172 gl_FragColor = texColor * v_alpha; | 1229 } |
1173 } | 1230 |
1174 // clang-format off | 1231 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderBody() { |
1175 ); // NOLINT(whitespace/parens) | 1232 return SHADER0([]() { |
1176 // clang-format on | 1233 void main() { |
| 1234 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1235 texColor += background_color * (1.0 - texColor.a); |
| 1236 gl_FragColor = texColor * v_alpha; |
| 1237 } |
| 1238 }); |
1177 } | 1239 } |
1178 | 1240 |
1179 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( | 1241 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( |
1180 TexCoordPrecision precision, | 1242 TexCoordPrecision precision, |
1181 SamplerType sampler) const { | 1243 SamplerType sampler) const { |
1182 // clang-format off | 1244 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1183 return FRAGMENT_SHADER( | 1245 } |
1184 // clang-format on | 1246 |
1185 precision mediump float; | 1247 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderHead() { |
1186 varying TexCoordPrecision vec2 v_texCoord; | 1248 return SHADER0([]() { |
1187 varying float v_alpha; | 1249 precision mediump float; |
1188 uniform vec4 background_color; | 1250 varying TexCoordPrecision vec2 v_texCoord; |
1189 uniform SamplerType s_texture; | 1251 varying float v_alpha; |
1190 void main() { | 1252 uniform vec4 background_color; |
1191 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1253 uniform SamplerType s_texture; |
1192 texColor.rgb *= texColor.a; | 1254 }); |
1193 texColor += background_color * (1.0 - texColor.a); | 1255 } |
1194 gl_FragColor = texColor * v_alpha; | 1256 |
1195 } | 1257 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderBody() { |
1196 // clang-format off | 1258 return SHADER0([]() { |
1197 ); // NOLINT(whitespace/parens) | 1259 void main() { |
1198 // clang-format on | 1260 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1261 texColor.rgb *= texColor.a; |
| 1262 texColor += background_color * (1.0 - texColor.a); |
| 1263 gl_FragColor = texColor * v_alpha; |
| 1264 } |
| 1265 }); |
1199 } | 1266 } |
1200 | 1267 |
1201 std::string FragmentShaderRGBATexOpaque::GetShaderString( | 1268 std::string FragmentShaderRGBATexOpaque::GetShaderString( |
1202 TexCoordPrecision precision, | 1269 TexCoordPrecision precision, |
1203 SamplerType sampler) const { | 1270 SamplerType sampler) const { |
1204 // clang-format off | 1271 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1205 return FRAGMENT_SHADER( | 1272 } |
1206 // clang-format on | 1273 |
1207 precision mediump float; | 1274 std::string FragmentShaderRGBATexOpaque::GetShaderHead() { |
1208 varying TexCoordPrecision vec2 v_texCoord; | 1275 return SHADER0([]() { |
1209 uniform SamplerType s_texture; | 1276 precision mediump float; |
1210 void main() { | 1277 varying TexCoordPrecision vec2 v_texCoord; |
1211 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1278 uniform SamplerType s_texture; |
1212 gl_FragColor = vec4(texColor.rgb, 1.0); | 1279 }); |
1213 } | 1280 } |
1214 // clang-format off | 1281 |
1215 ); // NOLINT(whitespace/parens) | 1282 std::string FragmentShaderRGBATexOpaque::GetShaderBody() { |
1216 // clang-format on | 1283 return SHADER0([]() { |
| 1284 void main() { |
| 1285 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1286 gl_FragColor = vec4(texColor.rgb, 1.0); |
| 1287 } |
| 1288 }); |
1217 } | 1289 } |
1218 | 1290 |
1219 std::string FragmentShaderRGBATex::GetShaderString(TexCoordPrecision precision, | 1291 std::string FragmentShaderRGBATex::GetShaderString(TexCoordPrecision precision, |
1220 SamplerType sampler) const { | 1292 SamplerType sampler) const { |
1221 // clang-format off | 1293 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1222 return FRAGMENT_SHADER( | 1294 } |
1223 // clang-format on | 1295 |
1224 precision mediump float; | 1296 std::string FragmentShaderRGBATex::GetShaderHead() { |
1225 varying TexCoordPrecision vec2 v_texCoord; | 1297 return SHADER0([]() { |
1226 uniform SamplerType s_texture; | 1298 precision mediump float; |
1227 void main() { gl_FragColor = TextureLookup(s_texture, v_texCoord); } | 1299 varying TexCoordPrecision vec2 v_texCoord; |
1228 // clang-format off | 1300 uniform SamplerType s_texture; |
1229 ); // NOLINT(whitespace/parens) | 1301 }); |
1230 // clang-format on | 1302 } |
| 1303 |
| 1304 std::string FragmentShaderRGBATex::GetShaderBody() { |
| 1305 return SHADER0([]() { |
| 1306 void main() { gl_FragColor = TextureLookup(s_texture, v_texCoord); } |
| 1307 }); |
1231 } | 1308 } |
1232 | 1309 |
1233 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( | 1310 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( |
1234 TexCoordPrecision precision, | 1311 TexCoordPrecision precision, |
1235 SamplerType sampler) const { | 1312 SamplerType sampler) const { |
1236 // clang-format off | 1313 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1237 return FRAGMENT_SHADER( | 1314 } |
1238 // clang-format on | 1315 |
1239 precision mediump float; | 1316 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderHead() { |
1240 varying TexCoordPrecision vec2 v_texCoord; | 1317 return SHADER0([]() { |
1241 uniform SamplerType s_texture; | 1318 precision mediump float; |
1242 uniform float alpha; | 1319 varying TexCoordPrecision vec2 v_texCoord; |
1243 void main() { | 1320 uniform SamplerType s_texture; |
1244 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1321 uniform float alpha; |
1245 gl_FragColor = | 1322 }); |
1246 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | 1323 } |
1247 } | 1324 |
1248 // clang-format off | 1325 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderBody() { |
1249 ); // NOLINT(whitespace/parens) | 1326 return SHADER0([]() { |
1250 // clang-format on | 1327 void main() { |
| 1328 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1329 gl_FragColor = |
| 1330 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
| 1331 } |
| 1332 }); |
1251 } | 1333 } |
1252 | 1334 |
1253 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( | 1335 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( |
1254 TexCoordPrecision precision, | 1336 TexCoordPrecision precision, |
1255 SamplerType sampler) const { | 1337 SamplerType sampler) const { |
1256 // clang-format off | 1338 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1257 return FRAGMENT_SHADER( | 1339 } |
1258 // clang-format on | 1340 |
1259 precision mediump float; | 1341 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderHead() { |
1260 varying TexCoordPrecision vec2 v_texCoord; | 1342 return SHADER0([]() { |
1261 uniform SamplerType s_texture; | 1343 precision mediump float; |
1262 void main() { | 1344 varying TexCoordPrecision vec2 v_texCoord; |
1263 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1345 uniform SamplerType s_texture; |
1264 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 1346 }); |
1265 } | 1347 } |
1266 // clang-format off | 1348 |
1267 ); // NOLINT(whitespace/parens) | 1349 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderBody() { |
1268 // clang-format on | 1350 return SHADER0([]() { |
| 1351 void main() { |
| 1352 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1353 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
| 1354 } |
| 1355 }); |
1269 } | 1356 } |
1270 | 1357 |
1271 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 1358 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
1272 : sampler_location_(-1), alpha_location_(-1) { | 1359 : sampler_location_(-1), alpha_location_(-1) { |
1273 } | 1360 } |
1274 | 1361 |
1275 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, | 1362 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, |
1276 unsigned program, | 1363 unsigned program, |
1277 int* base_uniform_index) { | 1364 int* base_uniform_index) { |
1278 static const char* uniforms[] = { | 1365 static const char* uniforms[] = { |
1279 "s_texture", "alpha", BLEND_MODE_UNIFORMS, | 1366 "s_texture", "alpha", BLEND_MODE_UNIFORMS, |
1280 }; | 1367 }; |
1281 int locations[arraysize(uniforms)]; | 1368 int locations[arraysize(uniforms)]; |
1282 | 1369 |
1283 GetProgramUniformLocations(context, | 1370 GetProgramUniformLocations(context, |
1284 program, | 1371 program, |
1285 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, | 1372 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
1286 uniforms, | 1373 uniforms, |
1287 locations, | 1374 locations, |
1288 base_uniform_index); | 1375 base_uniform_index); |
1289 sampler_location_ = locations[0]; | 1376 sampler_location_ = locations[0]; |
1290 alpha_location_ = locations[1]; | 1377 alpha_location_ = locations[1]; |
1291 BLEND_MODE_SET_LOCATIONS(locations, 2); | 1378 BLEND_MODE_SET_LOCATIONS(locations, 2); |
1292 } | 1379 } |
1293 | 1380 |
1294 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( | 1381 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( |
1295 TexCoordPrecision precision, | 1382 TexCoordPrecision precision, |
1296 SamplerType sampler) const { | 1383 SamplerType sampler) const { |
1297 // clang-format off | 1384 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1298 return FRAGMENT_SHADER( | 1385 } |
1299 // clang-format on | |
1300 precision mediump float; | |
1301 uniform SamplerType s_texture; | |
1302 uniform float alpha; | |
1303 varying TexCoordPrecision vec2 v_texCoord; | |
1304 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
1305 | 1386 |
1306 void main() { | 1387 std::string FragmentShaderRGBATexAlphaAA::GetShaderHead() { |
1307 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1388 return SHADER0([]() { |
1308 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1389 precision mediump float; |
1309 vec2 d2 = min(d4.xz, d4.yw); | 1390 uniform SamplerType s_texture; |
1310 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1391 uniform float alpha; |
1311 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); | 1392 varying TexCoordPrecision vec2 v_texCoord; |
1312 } | 1393 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1313 // clang-format off | 1394 }); |
1314 ); // NOLINT(whitespace/parens) | 1395 } |
1315 // clang-format on | 1396 |
| 1397 std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() { |
| 1398 return SHADER0([]() { |
| 1399 void main() { |
| 1400 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1401 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1402 vec2 d2 = min(d4.xz, d4.yw); |
| 1403 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1404 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); |
| 1405 } |
| 1406 }); |
1316 } | 1407 } |
1317 | 1408 |
1318 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | 1409 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() |
1319 : sampler_location_(-1), | 1410 : sampler_location_(-1), |
1320 alpha_location_(-1), | 1411 alpha_location_(-1), |
1321 fragment_tex_transform_location_(-1) { | 1412 fragment_tex_transform_location_(-1) { |
1322 } | 1413 } |
1323 | 1414 |
1324 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, | 1415 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, |
1325 unsigned program, | 1416 unsigned program, |
(...skipping 10 matching lines...) Expand all Loading... |
1336 locations, | 1427 locations, |
1337 base_uniform_index); | 1428 base_uniform_index); |
1338 sampler_location_ = locations[0]; | 1429 sampler_location_ = locations[0]; |
1339 alpha_location_ = locations[1]; | 1430 alpha_location_ = locations[1]; |
1340 fragment_tex_transform_location_ = locations[2]; | 1431 fragment_tex_transform_location_ = locations[2]; |
1341 } | 1432 } |
1342 | 1433 |
1343 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( | 1434 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( |
1344 TexCoordPrecision precision, | 1435 TexCoordPrecision precision, |
1345 SamplerType sampler) const { | 1436 SamplerType sampler) const { |
1346 // clang-format off | 1437 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1347 return FRAGMENT_SHADER( | 1438 } |
1348 // clang-format on | |
1349 precision mediump float; | |
1350 uniform SamplerType s_texture; | |
1351 uniform float alpha; | |
1352 uniform TexCoordPrecision vec4 fragmentTexTransform; | |
1353 varying TexCoordPrecision vec2 v_texCoord; | |
1354 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
1355 | 1439 |
1356 void main() { | 1440 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderHead() { |
1357 TexCoordPrecision vec2 texCoord = | 1441 return SHADER0([]() { |
1358 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 1442 precision mediump float; |
1359 fragmentTexTransform.xy; | 1443 uniform SamplerType s_texture; |
1360 vec4 texColor = TextureLookup(s_texture, texCoord); | 1444 uniform float alpha; |
1361 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1445 uniform TexCoordPrecision vec4 fragmentTexTransform; |
1362 vec2 d2 = min(d4.xz, d4.yw); | 1446 varying TexCoordPrecision vec2 v_texCoord; |
1363 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1447 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1364 gl_FragColor = texColor * alpha * aa; | 1448 }); |
1365 } | 1449 } |
1366 // clang-format off | 1450 |
1367 ); // NOLINT(whitespace/parens) | 1451 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderBody() { |
1368 // clang-format on | 1452 return SHADER0([]() { |
| 1453 void main() { |
| 1454 TexCoordPrecision vec2 texCoord = |
| 1455 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
| 1456 fragmentTexTransform.xy; |
| 1457 vec4 texColor = TextureLookup(s_texture, texCoord); |
| 1458 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1459 vec2 d2 = min(d4.xz, d4.yw); |
| 1460 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1461 gl_FragColor = texColor * alpha * aa; |
| 1462 } |
| 1463 }); |
1369 } | 1464 } |
1370 | 1465 |
1371 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( | 1466 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( |
1372 TexCoordPrecision precision, | 1467 TexCoordPrecision precision, |
1373 SamplerType sampler) const { | 1468 SamplerType sampler) const { |
1374 // clang-format off | 1469 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1375 return FRAGMENT_SHADER( | 1470 } |
1376 // clang-format on | |
1377 precision mediump float; | |
1378 uniform SamplerType s_texture; | |
1379 uniform float alpha; | |
1380 uniform TexCoordPrecision vec4 fragmentTexTransform; | |
1381 varying TexCoordPrecision vec2 v_texCoord; | |
1382 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
1383 | 1471 |
1384 void main() { | 1472 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderHead() { |
1385 TexCoordPrecision vec2 texCoord = | 1473 return SHADER0([]() { |
1386 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 1474 precision mediump float; |
1387 fragmentTexTransform.xy; | 1475 uniform SamplerType s_texture; |
1388 vec4 texColor = TextureLookup(s_texture, texCoord); | 1476 uniform float alpha; |
1389 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1477 uniform TexCoordPrecision vec4 fragmentTexTransform; |
1390 vec2 d2 = min(d4.xz, d4.yw); | 1478 varying TexCoordPrecision vec2 v_texCoord; |
1391 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1479 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1392 gl_FragColor = | 1480 }); |
1393 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * aa; | 1481 } |
1394 } | 1482 |
1395 // clang-format off | 1483 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderBody() { |
1396 ); // NOLINT(whitespace/parens) | 1484 return SHADER0([]() { |
1397 // clang-format on | 1485 void main() { |
| 1486 TexCoordPrecision vec2 texCoord = |
| 1487 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
| 1488 fragmentTexTransform.xy; |
| 1489 vec4 texColor = TextureLookup(s_texture, texCoord); |
| 1490 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1491 vec2 d2 = min(d4.xz, d4.yw); |
| 1492 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1493 gl_FragColor = |
| 1494 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * aa; |
| 1495 } |
| 1496 }); |
1398 } | 1497 } |
1399 | 1498 |
1400 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() | 1499 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() |
1401 : sampler_location_(-1), | 1500 : sampler_location_(-1), |
1402 mask_sampler_location_(-1), | 1501 mask_sampler_location_(-1), |
1403 alpha_location_(-1), | 1502 alpha_location_(-1), |
1404 mask_tex_coord_scale_location_(-1) { | 1503 mask_tex_coord_scale_location_(-1) { |
1405 } | 1504 } |
1406 | 1505 |
1407 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, | 1506 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, |
(...skipping 19 matching lines...) Expand all Loading... |
1427 mask_sampler_location_ = locations[1]; | 1526 mask_sampler_location_ = locations[1]; |
1428 alpha_location_ = locations[2]; | 1527 alpha_location_ = locations[2]; |
1429 mask_tex_coord_scale_location_ = locations[3]; | 1528 mask_tex_coord_scale_location_ = locations[3]; |
1430 mask_tex_coord_offset_location_ = locations[4]; | 1529 mask_tex_coord_offset_location_ = locations[4]; |
1431 BLEND_MODE_SET_LOCATIONS(locations, 5); | 1530 BLEND_MODE_SET_LOCATIONS(locations, 5); |
1432 } | 1531 } |
1433 | 1532 |
1434 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( | 1533 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( |
1435 TexCoordPrecision precision, | 1534 TexCoordPrecision precision, |
1436 SamplerType sampler) const { | 1535 SamplerType sampler) const { |
1437 // clang-format off | 1536 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1438 return FRAGMENT_SHADER( | 1537 } |
1439 // clang-format on | 1538 |
1440 precision mediump float; | 1539 std::string FragmentShaderRGBATexAlphaMask::GetShaderHead() { |
1441 varying TexCoordPrecision vec2 v_texCoord; | 1540 return SHADER0([]() { |
1442 uniform sampler2D s_texture; | 1541 precision mediump float; |
1443 uniform SamplerType s_mask; | 1542 varying TexCoordPrecision vec2 v_texCoord; |
1444 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1543 uniform sampler2D s_texture; |
1445 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1544 uniform SamplerType s_mask; |
1446 uniform float alpha; | 1545 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1447 void main() { | 1546 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1448 vec4 texColor = texture2D(s_texture, v_texCoord); | 1547 uniform float alpha; |
1449 TexCoordPrecision vec2 maskTexCoord = | 1548 }); |
1450 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1549 } |
1451 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1550 |
1452 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1551 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { |
1453 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); | 1552 return SHADER0([]() { |
1454 } | 1553 void main() { |
1455 // clang-format off | 1554 vec4 texColor = texture2D(s_texture, v_texCoord); |
1456 ); // NOLINT(whitespace/parens) | 1555 TexCoordPrecision vec2 maskTexCoord = |
1457 // clang-format on | 1556 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1557 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1558 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1559 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); |
| 1560 } |
| 1561 }); |
1458 } | 1562 } |
1459 | 1563 |
1460 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 1564 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
1461 : sampler_location_(-1), | 1565 : sampler_location_(-1), |
1462 mask_sampler_location_(-1), | 1566 mask_sampler_location_(-1), |
1463 alpha_location_(-1), | 1567 alpha_location_(-1), |
1464 mask_tex_coord_scale_location_(-1), | 1568 mask_tex_coord_scale_location_(-1), |
1465 mask_tex_coord_offset_location_(-1) { | 1569 mask_tex_coord_offset_location_(-1) { |
1466 } | 1570 } |
1467 | 1571 |
(...skipping 20 matching lines...) Expand all Loading... |
1488 mask_sampler_location_ = locations[1]; | 1592 mask_sampler_location_ = locations[1]; |
1489 alpha_location_ = locations[2]; | 1593 alpha_location_ = locations[2]; |
1490 mask_tex_coord_scale_location_ = locations[3]; | 1594 mask_tex_coord_scale_location_ = locations[3]; |
1491 mask_tex_coord_offset_location_ = locations[4]; | 1595 mask_tex_coord_offset_location_ = locations[4]; |
1492 BLEND_MODE_SET_LOCATIONS(locations, 5); | 1596 BLEND_MODE_SET_LOCATIONS(locations, 5); |
1493 } | 1597 } |
1494 | 1598 |
1495 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( | 1599 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( |
1496 TexCoordPrecision precision, | 1600 TexCoordPrecision precision, |
1497 SamplerType sampler) const { | 1601 SamplerType sampler) const { |
1498 // clang-format off | 1602 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1499 return FRAGMENT_SHADER( | 1603 } |
1500 // clang-format on | |
1501 precision mediump float; | |
1502 uniform sampler2D s_texture; | |
1503 uniform SamplerType s_mask; | |
1504 uniform TexCoordPrecision vec2 maskTexCoordScale; | |
1505 uniform TexCoordPrecision vec2 maskTexCoordOffset; | |
1506 uniform float alpha; | |
1507 varying TexCoordPrecision vec2 v_texCoord; | |
1508 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
1509 | 1604 |
1510 void main() { | 1605 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderHead() { |
1511 vec4 texColor = texture2D(s_texture, v_texCoord); | 1606 return SHADER0([]() { |
1512 TexCoordPrecision vec2 maskTexCoord = | 1607 precision mediump float; |
1513 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1608 uniform sampler2D s_texture; |
1514 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1609 uniform SamplerType s_mask; |
1515 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1610 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1516 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1611 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1517 vec2 d2 = min(d4.xz, d4.yw); | 1612 uniform float alpha; |
1518 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1613 varying TexCoordPrecision vec2 v_texCoord; |
1519 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); | 1614 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1520 } | 1615 }); |
1521 // clang-format off | 1616 } |
1522 ); // NOLINT(whitespace/parens) | 1617 |
1523 // clang-format on | 1618 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderBody() { |
| 1619 return SHADER0([]() { |
| 1620 void main() { |
| 1621 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1622 TexCoordPrecision vec2 maskTexCoord = |
| 1623 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1624 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1625 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1626 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1627 vec2 d2 = min(d4.xz, d4.yw); |
| 1628 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1629 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); |
| 1630 } |
| 1631 }); |
1524 } | 1632 } |
1525 | 1633 |
1526 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: | 1634 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: |
1527 FragmentShaderRGBATexAlphaMaskColorMatrixAA() | 1635 FragmentShaderRGBATexAlphaMaskColorMatrixAA() |
1528 : sampler_location_(-1), | 1636 : sampler_location_(-1), |
1529 mask_sampler_location_(-1), | 1637 mask_sampler_location_(-1), |
1530 alpha_location_(-1), | 1638 alpha_location_(-1), |
1531 mask_tex_coord_scale_location_(-1), | 1639 mask_tex_coord_scale_location_(-1), |
1532 color_matrix_location_(-1), | 1640 color_matrix_location_(-1), |
1533 color_offset_location_(-1) { | 1641 color_offset_location_(-1) { |
(...skipping 27 matching lines...) Expand all Loading... |
1561 mask_tex_coord_scale_location_ = locations[3]; | 1669 mask_tex_coord_scale_location_ = locations[3]; |
1562 mask_tex_coord_offset_location_ = locations[4]; | 1670 mask_tex_coord_offset_location_ = locations[4]; |
1563 color_matrix_location_ = locations[5]; | 1671 color_matrix_location_ = locations[5]; |
1564 color_offset_location_ = locations[6]; | 1672 color_offset_location_ = locations[6]; |
1565 BLEND_MODE_SET_LOCATIONS(locations, 7); | 1673 BLEND_MODE_SET_LOCATIONS(locations, 7); |
1566 } | 1674 } |
1567 | 1675 |
1568 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( | 1676 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( |
1569 TexCoordPrecision precision, | 1677 TexCoordPrecision precision, |
1570 SamplerType sampler) const { | 1678 SamplerType sampler) const { |
1571 // clang-format off | 1679 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1572 return FRAGMENT_SHADER( | 1680 } |
1573 // clang-format on | |
1574 precision mediump float; | |
1575 uniform sampler2D s_texture; | |
1576 uniform SamplerType s_mask; | |
1577 uniform vec2 maskTexCoordScale; | |
1578 uniform vec2 maskTexCoordOffset; | |
1579 uniform mat4 colorMatrix; | |
1580 uniform vec4 colorOffset; | |
1581 uniform float alpha; | |
1582 varying TexCoordPrecision vec2 v_texCoord; | |
1583 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
1584 | 1681 |
1585 void main() { | 1682 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderHead() { |
1586 vec4 texColor = texture2D(s_texture, v_texCoord); | 1683 return SHADER0([]() { |
1587 float nonZeroAlpha = max(texColor.a, 0.00001); | 1684 precision mediump float; |
1588 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1685 uniform sampler2D s_texture; |
1589 texColor = colorMatrix * texColor + colorOffset; | 1686 uniform SamplerType s_mask; |
1590 texColor.rgb *= texColor.a; | 1687 uniform vec2 maskTexCoordScale; |
1591 texColor = clamp(texColor, 0.0, 1.0); | 1688 uniform vec2 maskTexCoordOffset; |
1592 TexCoordPrecision vec2 maskTexCoord = | 1689 uniform mat4 colorMatrix; |
1593 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1690 uniform vec4 colorOffset; |
1594 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1691 uniform float alpha; |
1595 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1692 varying TexCoordPrecision vec2 v_texCoord; |
1596 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1693 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1597 vec2 d2 = min(d4.xz, d4.yw); | 1694 }); |
1598 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1695 } |
1599 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); | 1696 |
1600 } | 1697 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderBody() { |
1601 // clang-format off | 1698 return SHADER0([]() { |
1602 ); // NOLINT(whitespace/parens) | 1699 void main() { |
1603 // clang-format on | 1700 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 1701 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1702 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1703 texColor = colorMatrix * texColor + colorOffset; |
| 1704 texColor.rgb *= texColor.a; |
| 1705 texColor = clamp(texColor, 0.0, 1.0); |
| 1706 TexCoordPrecision vec2 maskTexCoord = |
| 1707 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1708 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1709 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1710 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1711 vec2 d2 = min(d4.xz, d4.yw); |
| 1712 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1713 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); |
| 1714 } |
| 1715 }); |
1604 } | 1716 } |
1605 | 1717 |
1606 FragmentShaderRGBATexAlphaColorMatrixAA:: | 1718 FragmentShaderRGBATexAlphaColorMatrixAA:: |
1607 FragmentShaderRGBATexAlphaColorMatrixAA() | 1719 FragmentShaderRGBATexAlphaColorMatrixAA() |
1608 : sampler_location_(-1), | 1720 : sampler_location_(-1), |
1609 alpha_location_(-1), | 1721 alpha_location_(-1), |
1610 color_matrix_location_(-1), | 1722 color_matrix_location_(-1), |
1611 color_offset_location_(-1) { | 1723 color_offset_location_(-1) { |
1612 } | 1724 } |
1613 | 1725 |
(...skipping 14 matching lines...) Expand all Loading... |
1628 sampler_location_ = locations[0]; | 1740 sampler_location_ = locations[0]; |
1629 alpha_location_ = locations[1]; | 1741 alpha_location_ = locations[1]; |
1630 color_matrix_location_ = locations[2]; | 1742 color_matrix_location_ = locations[2]; |
1631 color_offset_location_ = locations[3]; | 1743 color_offset_location_ = locations[3]; |
1632 BLEND_MODE_SET_LOCATIONS(locations, 4); | 1744 BLEND_MODE_SET_LOCATIONS(locations, 4); |
1633 } | 1745 } |
1634 | 1746 |
1635 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( | 1747 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( |
1636 TexCoordPrecision precision, | 1748 TexCoordPrecision precision, |
1637 SamplerType sampler) const { | 1749 SamplerType sampler) const { |
1638 // clang-format off | 1750 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1639 return FRAGMENT_SHADER( | 1751 } |
1640 // clang-format on | |
1641 precision mediump float; | |
1642 uniform SamplerType s_texture; | |
1643 uniform float alpha; | |
1644 uniform mat4 colorMatrix; | |
1645 uniform vec4 colorOffset; | |
1646 varying TexCoordPrecision vec2 v_texCoord; | |
1647 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | |
1648 | 1752 |
1649 void main() { | 1753 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderHead() { |
1650 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1754 return SHADER0([]() { |
1651 float nonZeroAlpha = max(texColor.a, 0.00001); | 1755 precision mediump float; |
1652 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1756 uniform SamplerType s_texture; |
1653 texColor = colorMatrix * texColor + colorOffset; | 1757 uniform float alpha; |
1654 texColor.rgb *= texColor.a; | 1758 uniform mat4 colorMatrix; |
1655 texColor = clamp(texColor, 0.0, 1.0); | 1759 uniform vec4 colorOffset; |
1656 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1760 varying TexCoordPrecision vec2 v_texCoord; |
1657 vec2 d2 = min(d4.xz, d4.yw); | 1761 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1658 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1762 }); |
1659 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); | 1763 } |
1660 } | 1764 |
1661 // clang-format off | 1765 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderBody() { |
1662 ); // NOLINT(whitespace/parens) | 1766 return SHADER0([]() { |
1663 // clang-format on | 1767 void main() { |
| 1768 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1769 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1770 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1771 texColor = colorMatrix * texColor + colorOffset; |
| 1772 texColor.rgb *= texColor.a; |
| 1773 texColor = clamp(texColor, 0.0, 1.0); |
| 1774 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1775 vec2 d2 = min(d4.xz, d4.yw); |
| 1776 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1777 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); |
| 1778 } |
| 1779 }); |
1664 } | 1780 } |
1665 | 1781 |
1666 FragmentShaderRGBATexAlphaMaskColorMatrix:: | 1782 FragmentShaderRGBATexAlphaMaskColorMatrix:: |
1667 FragmentShaderRGBATexAlphaMaskColorMatrix() | 1783 FragmentShaderRGBATexAlphaMaskColorMatrix() |
1668 : sampler_location_(-1), | 1784 : sampler_location_(-1), |
1669 mask_sampler_location_(-1), | 1785 mask_sampler_location_(-1), |
1670 alpha_location_(-1), | 1786 alpha_location_(-1), |
1671 mask_tex_coord_scale_location_(-1) { | 1787 mask_tex_coord_scale_location_(-1) { |
1672 } | 1788 } |
1673 | 1789 |
(...skipping 24 matching lines...) Expand all Loading... |
1698 mask_tex_coord_scale_location_ = locations[3]; | 1814 mask_tex_coord_scale_location_ = locations[3]; |
1699 mask_tex_coord_offset_location_ = locations[4]; | 1815 mask_tex_coord_offset_location_ = locations[4]; |
1700 color_matrix_location_ = locations[5]; | 1816 color_matrix_location_ = locations[5]; |
1701 color_offset_location_ = locations[6]; | 1817 color_offset_location_ = locations[6]; |
1702 BLEND_MODE_SET_LOCATIONS(locations, 7); | 1818 BLEND_MODE_SET_LOCATIONS(locations, 7); |
1703 } | 1819 } |
1704 | 1820 |
1705 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( | 1821 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( |
1706 TexCoordPrecision precision, | 1822 TexCoordPrecision precision, |
1707 SamplerType sampler) const { | 1823 SamplerType sampler) const { |
1708 // clang-format off | 1824 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1709 return FRAGMENT_SHADER( | 1825 } |
1710 // clang-format on | 1826 |
1711 precision mediump float; | 1827 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderHead() { |
1712 varying TexCoordPrecision vec2 v_texCoord; | 1828 return SHADER0([]() { |
1713 uniform sampler2D s_texture; | 1829 precision mediump float; |
1714 uniform SamplerType s_mask; | 1830 varying TexCoordPrecision vec2 v_texCoord; |
1715 uniform vec2 maskTexCoordScale; | 1831 uniform sampler2D s_texture; |
1716 uniform vec2 maskTexCoordOffset; | 1832 uniform SamplerType s_mask; |
1717 uniform mat4 colorMatrix; | 1833 uniform vec2 maskTexCoordScale; |
1718 uniform vec4 colorOffset; | 1834 uniform vec2 maskTexCoordOffset; |
1719 uniform float alpha; | 1835 uniform mat4 colorMatrix; |
1720 void main() { | 1836 uniform vec4 colorOffset; |
1721 vec4 texColor = texture2D(s_texture, v_texCoord); | 1837 uniform float alpha; |
1722 float nonZeroAlpha = max(texColor.a, 0.00001); | 1838 }); |
1723 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1839 } |
1724 texColor = colorMatrix * texColor + colorOffset; | 1840 |
1725 texColor.rgb *= texColor.a; | 1841 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderBody() { |
1726 texColor = clamp(texColor, 0.0, 1.0); | 1842 return SHADER0([]() { |
1727 TexCoordPrecision vec2 maskTexCoord = | 1843 void main() { |
1728 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1844 vec4 texColor = texture2D(s_texture, v_texCoord); |
1729 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1845 float nonZeroAlpha = max(texColor.a, 0.00001); |
1730 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1846 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1731 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); | 1847 texColor = colorMatrix * texColor + colorOffset; |
1732 } | 1848 texColor.rgb *= texColor.a; |
1733 // clang-format off | 1849 texColor = clamp(texColor, 0.0, 1.0); |
1734 ); // NOLINT(whitespace/parens) | 1850 TexCoordPrecision vec2 maskTexCoord = |
1735 // clang-format on | 1851 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1852 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1853 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1854 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); |
| 1855 } |
| 1856 }); |
1736 } | 1857 } |
1737 | 1858 |
1738 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 1859 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
1739 : y_texture_location_(-1), | 1860 : y_texture_location_(-1), |
1740 u_texture_location_(-1), | 1861 u_texture_location_(-1), |
1741 v_texture_location_(-1), | 1862 v_texture_location_(-1), |
1742 alpha_location_(-1), | 1863 alpha_location_(-1), |
1743 yuv_matrix_location_(-1), | 1864 yuv_matrix_location_(-1), |
1744 yuv_adj_location_(-1), | 1865 yuv_adj_location_(-1), |
1745 clamp_rect_location_(-1) { | 1866 clamp_rect_location_(-1) { |
(...skipping 21 matching lines...) Expand all Loading... |
1767 u_texture_location_ = locations[1]; | 1888 u_texture_location_ = locations[1]; |
1768 v_texture_location_ = locations[2]; | 1889 v_texture_location_ = locations[2]; |
1769 alpha_location_ = locations[3]; | 1890 alpha_location_ = locations[3]; |
1770 yuv_matrix_location_ = locations[4]; | 1891 yuv_matrix_location_ = locations[4]; |
1771 yuv_adj_location_ = locations[5]; | 1892 yuv_adj_location_ = locations[5]; |
1772 clamp_rect_location_ = locations[6]; | 1893 clamp_rect_location_ = locations[6]; |
1773 } | 1894 } |
1774 | 1895 |
1775 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, | 1896 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
1776 SamplerType sampler) const { | 1897 SamplerType sampler) const { |
1777 // clang-format off | 1898 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1778 return FRAGMENT_SHADER( | 1899 } |
1779 // clang-format on | 1900 |
1780 precision mediump float; | 1901 std::string FragmentShaderYUVVideo::GetShaderHead() { |
1781 precision mediump int; | 1902 return SHADER0([]() { |
1782 varying TexCoordPrecision vec2 v_texCoord; | 1903 precision mediump float; |
1783 uniform SamplerType y_texture; | 1904 precision mediump int; |
1784 uniform SamplerType u_texture; | 1905 varying TexCoordPrecision vec2 v_texCoord; |
1785 uniform SamplerType v_texture; | 1906 uniform SamplerType y_texture; |
1786 uniform float alpha; | 1907 uniform SamplerType u_texture; |
1787 uniform vec3 yuv_adj; | 1908 uniform SamplerType v_texture; |
1788 uniform mat3 yuv_matrix; | 1909 uniform float alpha; |
1789 uniform vec4 clamp_rect; | 1910 uniform vec3 yuv_adj; |
1790 void main() { | 1911 uniform mat3 yuv_matrix; |
1791 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); | 1912 uniform vec4 clamp_rect; |
1792 float y_raw = TextureLookup(y_texture, clamped).x; | 1913 }); |
1793 float u_unsigned = TextureLookup(u_texture, clamped).x; | 1914 } |
1794 float v_unsigned = TextureLookup(v_texture, clamped).x; | 1915 |
1795 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1916 std::string FragmentShaderYUVVideo::GetShaderBody() { |
1796 vec3 rgb = yuv_matrix * yuv; | 1917 return SHADER0([]() { |
1797 gl_FragColor = vec4(rgb, 1.0) * alpha; | 1918 void main() { |
1798 } | 1919 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); |
1799 // clang-format off | 1920 float y_raw = TextureLookup(y_texture, clamped).x; |
1800 ); // NOLINT(whitespace/parens) | 1921 float u_unsigned = TextureLookup(u_texture, clamped).x; |
1801 // clang-format on | 1922 float v_unsigned = TextureLookup(v_texture, clamped).x; |
| 1923 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
| 1924 vec3 rgb = yuv_matrix * yuv; |
| 1925 gl_FragColor = vec4(rgb, 1.0) * alpha; |
| 1926 } |
| 1927 }); |
1802 } | 1928 } |
1803 | 1929 |
1804 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() | 1930 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() |
1805 : y_texture_location_(-1), | 1931 : y_texture_location_(-1), |
1806 u_texture_location_(-1), | 1932 u_texture_location_(-1), |
1807 v_texture_location_(-1), | 1933 v_texture_location_(-1), |
1808 a_texture_location_(-1), | 1934 a_texture_location_(-1), |
1809 alpha_location_(-1), | 1935 alpha_location_(-1), |
1810 yuv_matrix_location_(-1), | 1936 yuv_matrix_location_(-1), |
1811 yuv_adj_location_(-1) { | 1937 yuv_adj_location_(-1) { |
(...skipping 26 matching lines...) Expand all Loading... |
1838 a_texture_location_ = locations[3]; | 1964 a_texture_location_ = locations[3]; |
1839 alpha_location_ = locations[4]; | 1965 alpha_location_ = locations[4]; |
1840 yuv_matrix_location_ = locations[5]; | 1966 yuv_matrix_location_ = locations[5]; |
1841 yuv_adj_location_ = locations[6]; | 1967 yuv_adj_location_ = locations[6]; |
1842 clamp_rect_location_ = locations[7]; | 1968 clamp_rect_location_ = locations[7]; |
1843 } | 1969 } |
1844 | 1970 |
1845 std::string FragmentShaderYUVAVideo::GetShaderString( | 1971 std::string FragmentShaderYUVAVideo::GetShaderString( |
1846 TexCoordPrecision precision, | 1972 TexCoordPrecision precision, |
1847 SamplerType sampler) const { | 1973 SamplerType sampler) const { |
1848 // clang-format off | 1974 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1849 return FRAGMENT_SHADER( | 1975 } |
1850 // clang-format on | 1976 |
1851 precision mediump float; | 1977 std::string FragmentShaderYUVAVideo::GetShaderHead() { |
1852 precision mediump int; | 1978 return SHADER0([]() { |
1853 varying TexCoordPrecision vec2 v_texCoord; | 1979 precision mediump float; |
1854 uniform SamplerType y_texture; | 1980 precision mediump int; |
1855 uniform SamplerType u_texture; | 1981 varying TexCoordPrecision vec2 v_texCoord; |
1856 uniform SamplerType v_texture; | 1982 uniform SamplerType y_texture; |
1857 uniform SamplerType a_texture; | 1983 uniform SamplerType u_texture; |
1858 uniform float alpha; | 1984 uniform SamplerType v_texture; |
1859 uniform vec3 yuv_adj; | 1985 uniform SamplerType a_texture; |
1860 uniform mat3 yuv_matrix; | 1986 uniform float alpha; |
1861 uniform vec4 clamp_rect; | 1987 uniform vec3 yuv_adj; |
1862 void main() { | 1988 uniform mat3 yuv_matrix; |
1863 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); | 1989 uniform vec4 clamp_rect; |
1864 float y_raw = TextureLookup(y_texture, clamped).x; | 1990 }); |
1865 float u_unsigned = TextureLookup(u_texture, clamped).x; | 1991 } |
1866 float v_unsigned = TextureLookup(v_texture, clamped).x; | 1992 |
1867 float a_raw = TextureLookup(a_texture, clamped).x; | 1993 std::string FragmentShaderYUVAVideo::GetShaderBody() { |
1868 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1994 return SHADER0([]() { |
1869 vec3 rgb = yuv_matrix * yuv; | 1995 void main() { |
1870 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); | 1996 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); |
1871 } | 1997 float y_raw = TextureLookup(y_texture, clamped).x; |
1872 // clang-format off | 1998 float u_unsigned = TextureLookup(u_texture, clamped).x; |
1873 ); // NOLINT(whitespace/parens) | 1999 float v_unsigned = TextureLookup(v_texture, clamped).x; |
1874 // clang-format on | 2000 float a_raw = TextureLookup(a_texture, clamped).x; |
| 2001 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
| 2002 vec3 rgb = yuv_matrix * yuv; |
| 2003 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); |
| 2004 } |
| 2005 }); |
1875 } | 2006 } |
1876 | 2007 |
1877 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { | 2008 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { |
1878 } | 2009 } |
1879 | 2010 |
1880 void FragmentShaderColor::Init(GLES2Interface* context, | 2011 void FragmentShaderColor::Init(GLES2Interface* context, |
1881 unsigned program, | 2012 unsigned program, |
1882 int* base_uniform_index) { | 2013 int* base_uniform_index) { |
1883 static const char* uniforms[] = { | 2014 static const char* uniforms[] = { |
1884 "color", | 2015 "color", |
1885 }; | 2016 }; |
1886 int locations[arraysize(uniforms)]; | 2017 int locations[arraysize(uniforms)]; |
1887 | 2018 |
1888 GetProgramUniformLocations(context, | 2019 GetProgramUniformLocations(context, |
1889 program, | 2020 program, |
1890 arraysize(uniforms), | 2021 arraysize(uniforms), |
1891 uniforms, | 2022 uniforms, |
1892 locations, | 2023 locations, |
1893 base_uniform_index); | 2024 base_uniform_index); |
1894 color_location_ = locations[0]; | 2025 color_location_ = locations[0]; |
1895 } | 2026 } |
1896 | 2027 |
1897 std::string FragmentShaderColor::GetShaderString(TexCoordPrecision precision, | 2028 std::string FragmentShaderColor::GetShaderString(TexCoordPrecision precision, |
1898 SamplerType sampler) const { | 2029 SamplerType sampler) const { |
1899 // clang-format off | 2030 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1900 return FRAGMENT_SHADER( | 2031 } |
1901 // clang-format on | 2032 |
1902 precision mediump float; | 2033 std::string FragmentShaderColor::GetShaderHead() { |
1903 uniform vec4 color; | 2034 return SHADER0([]() { |
1904 void main() { gl_FragColor = color; } | 2035 precision mediump float; |
1905 // clang-format off | 2036 uniform vec4 color; |
1906 ); // NOLINT(whitespace/parens) | 2037 }); |
1907 // clang-format on | 2038 } |
| 2039 |
| 2040 std::string FragmentShaderColor::GetShaderBody() { |
| 2041 return SHADER0([]() { |
| 2042 void main() { gl_FragColor = color; } |
| 2043 }); |
1908 } | 2044 } |
1909 | 2045 |
1910 FragmentShaderColorAA::FragmentShaderColorAA() : color_location_(-1) { | 2046 FragmentShaderColorAA::FragmentShaderColorAA() : color_location_(-1) { |
1911 } | 2047 } |
1912 | 2048 |
1913 void FragmentShaderColorAA::Init(GLES2Interface* context, | 2049 void FragmentShaderColorAA::Init(GLES2Interface* context, |
1914 unsigned program, | 2050 unsigned program, |
1915 int* base_uniform_index) { | 2051 int* base_uniform_index) { |
1916 static const char* uniforms[] = { | 2052 static const char* uniforms[] = { |
1917 "color", | 2053 "color", |
1918 }; | 2054 }; |
1919 int locations[arraysize(uniforms)]; | 2055 int locations[arraysize(uniforms)]; |
1920 | 2056 |
1921 GetProgramUniformLocations(context, | 2057 GetProgramUniformLocations(context, |
1922 program, | 2058 program, |
1923 arraysize(uniforms), | 2059 arraysize(uniforms), |
1924 uniforms, | 2060 uniforms, |
1925 locations, | 2061 locations, |
1926 base_uniform_index); | 2062 base_uniform_index); |
1927 color_location_ = locations[0]; | 2063 color_location_ = locations[0]; |
1928 } | 2064 } |
1929 | 2065 |
1930 std::string FragmentShaderColorAA::GetShaderString(TexCoordPrecision precision, | 2066 std::string FragmentShaderColorAA::GetShaderString(TexCoordPrecision precision, |
1931 SamplerType sampler) const { | 2067 SamplerType sampler) const { |
1932 // clang-format off | 2068 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
1933 return FRAGMENT_SHADER( | 2069 } |
1934 // clang-format on | |
1935 precision mediump float; | |
1936 uniform vec4 color; | |
1937 varying vec4 edge_dist[2]; // 8 edge distances. | |
1938 | 2070 |
1939 void main() { | 2071 std::string FragmentShaderColorAA::GetShaderHead() { |
1940 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 2072 return SHADER0([]() { |
1941 vec2 d2 = min(d4.xz, d4.yw); | 2073 precision mediump float; |
1942 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 2074 uniform vec4 color; |
1943 gl_FragColor = color * aa; | 2075 varying vec4 edge_dist[2]; // 8 edge distances. |
1944 } | 2076 }); |
1945 // clang-format off | 2077 } |
1946 ); // NOLINT(whitespace/parens) | 2078 |
1947 // clang-format on | 2079 std::string FragmentShaderColorAA::GetShaderBody() { |
| 2080 return SHADER0([]() { |
| 2081 void main() { |
| 2082 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 2083 vec2 d2 = min(d4.xz, d4.yw); |
| 2084 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 2085 gl_FragColor = color * aa; |
| 2086 } |
| 2087 }); |
1948 } | 2088 } |
1949 | 2089 |
1950 FragmentShaderCheckerboard::FragmentShaderCheckerboard() | 2090 FragmentShaderCheckerboard::FragmentShaderCheckerboard() |
1951 : alpha_location_(-1), | 2091 : alpha_location_(-1), |
1952 tex_transform_location_(-1), | 2092 tex_transform_location_(-1), |
1953 frequency_location_(-1) { | 2093 frequency_location_(-1) { |
1954 } | 2094 } |
1955 | 2095 |
1956 void FragmentShaderCheckerboard::Init(GLES2Interface* context, | 2096 void FragmentShaderCheckerboard::Init(GLES2Interface* context, |
1957 unsigned program, | 2097 unsigned program, |
(...skipping 11 matching lines...) Expand all Loading... |
1969 base_uniform_index); | 2109 base_uniform_index); |
1970 alpha_location_ = locations[0]; | 2110 alpha_location_ = locations[0]; |
1971 tex_transform_location_ = locations[1]; | 2111 tex_transform_location_ = locations[1]; |
1972 frequency_location_ = locations[2]; | 2112 frequency_location_ = locations[2]; |
1973 color_location_ = locations[3]; | 2113 color_location_ = locations[3]; |
1974 } | 2114 } |
1975 | 2115 |
1976 std::string FragmentShaderCheckerboard::GetShaderString( | 2116 std::string FragmentShaderCheckerboard::GetShaderString( |
1977 TexCoordPrecision precision, | 2117 TexCoordPrecision precision, |
1978 SamplerType sampler) const { | 2118 SamplerType sampler) const { |
| 2119 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
| 2120 } |
| 2121 |
| 2122 std::string FragmentShaderCheckerboard::GetShaderHead() { |
| 2123 return SHADER0([]() { |
| 2124 precision mediump float; |
| 2125 precision mediump int; |
| 2126 varying vec2 v_texCoord; |
| 2127 uniform float alpha; |
| 2128 uniform float frequency; |
| 2129 uniform vec4 texTransform; |
| 2130 uniform vec4 color; |
| 2131 }); |
| 2132 } |
| 2133 |
| 2134 std::string FragmentShaderCheckerboard::GetShaderBody() { |
1979 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 2135 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
1980 // by Munshi, Ginsburg, Shreiner. | 2136 // by Munshi, Ginsburg, Shreiner. |
1981 // clang-format off | 2137 return SHADER0([]() { |
1982 return FRAGMENT_SHADER( | 2138 void main() { |
1983 // clang-format on | 2139 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
1984 precision mediump float; | 2140 vec4 color2 = color; |
1985 precision mediump int; | 2141 vec2 texCoord = |
1986 varying vec2 v_texCoord; | 2142 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
1987 uniform float alpha; | 2143 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1988 uniform float frequency; | 2144 float picker = abs(coord.x - coord.y); // NOLINT |
1989 uniform vec4 texTransform; | 2145 gl_FragColor = mix(color1, color2, picker) * alpha; |
1990 uniform vec4 color; | 2146 } |
1991 void main() { | 2147 }); |
1992 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | |
1993 vec4 color2 = color; | |
1994 vec2 texCoord = | |
1995 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | |
1996 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | |
1997 float picker = abs(coord.x - coord.y); // NOLINT | |
1998 gl_FragColor = mix(color1, color2, picker) * alpha; | |
1999 } | |
2000 // clang-format off | |
2001 ); // NOLINT(whitespace/parens) | |
2002 // clang-format on | |
2003 } | 2148 } |
2004 | 2149 |
2005 } // namespace cc | 2150 } // namespace cc |
OLD | NEW |