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" |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 float nonZeroAlpha = max(texColor.a, 0.00001); | 661 float nonZeroAlpha = max(texColor.a, 0.00001); |
662 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 662 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
663 texColor = colorMatrix * texColor + colorOffset; | 663 texColor = colorMatrix * texColor + colorOffset; |
664 texColor.rgb *= texColor.a; | 664 texColor.rgb *= texColor.a; |
665 texColor = clamp(texColor, 0.0, 1.0); | 665 texColor = clamp(texColor, 0.0, 1.0); |
666 gl_FragColor = texColor * alpha; | 666 gl_FragColor = texColor * alpha; |
667 } | 667 } |
668 ); // NOLINT(whitespace/parens) | 668 ); // NOLINT(whitespace/parens) |
669 } | 669 } |
670 | 670 |
671 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 671 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() |
| 672 : background_color_location_(-1), |
| 673 sampler_location_(-1) { |
| 674 } |
| 675 |
| 676 void FragmentTexBackgroundBinding::Init(WebGraphicsContext3D* context, |
| 677 unsigned program, |
| 678 bool using_bind_uniform, |
| 679 int* base_uniform_index) { |
| 680 static const char* shader_uniforms[] = { |
| 681 "s_texture", |
| 682 "background_color", |
| 683 }; |
| 684 int locations[2]; |
| 685 |
| 686 GetProgramUniformLocations(context, |
| 687 program, |
| 688 shader_uniforms, |
| 689 arraysize(shader_uniforms), |
| 690 arraysize(locations), |
| 691 locations, |
| 692 using_bind_uniform, |
| 693 base_uniform_index); |
| 694 |
| 695 sampler_location_ = locations[0]; |
| 696 DCHECK_NE(sampler_location_, -1); |
| 697 |
| 698 background_color_location_ = locations[1]; |
| 699 DCHECK_NE(background_color_location_, -1); |
| 700 } |
| 701 |
| 702 std::string FragmentShaderTexture::GetShaderString( |
672 TexCoordPrecision precision) const { | 703 TexCoordPrecision precision) const { |
673 return FRAGMENT_SHADER( | 704 return FRAGMENT_SHADER( |
674 precision mediump float; | 705 precision mediump float; |
675 varying TexCoordPrecision vec2 v_texCoord; | 706 varying TexCoordPrecision vec2 v_texCoord; |
676 varying float v_alpha; | 707 varying float v_alpha; |
677 uniform sampler2D s_texture; | 708 uniform sampler2D s_texture; |
| 709 uniform vec4 background_color; |
678 void main() { | 710 void main() { |
679 vec4 texColor = texture2D(s_texture, v_texCoord); | 711 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 712 texColor += background_color * (1.0 - texColor.a); |
680 gl_FragColor = texColor * v_alpha; | 713 gl_FragColor = texColor * v_alpha; |
681 } | 714 } |
682 ); // NOLINT(whitespace/parens) | 715 ); // NOLINT(whitespace/parens) |
683 } | 716 } |
684 | 717 |
685 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( | 718 std::string FragmentShaderNonPremulTexture::GetShaderString( |
686 TexCoordPrecision precision) const { | 719 TexCoordPrecision precision) const { |
687 return FRAGMENT_SHADER( | 720 return FRAGMENT_SHADER( |
688 precision mediump float; | 721 precision mediump float; |
689 varying TexCoordPrecision vec2 v_texCoord; | 722 varying TexCoordPrecision vec2 v_texCoord; |
690 varying float v_alpha; | 723 varying float v_alpha; |
691 uniform sampler2D s_texture; | 724 uniform sampler2D s_texture; |
| 725 uniform vec4 background_color; |
692 void main() { | 726 void main() { |
693 vec4 texColor = texture2D(s_texture, v_texCoord); | 727 vec4 texColor = texture2D(s_texture, v_texCoord); |
694 texColor.rgb *= texColor.a; | 728 texColor.rgb *= texColor.a; |
| 729 texColor += background_color * (1.0 - texColor.a); |
695 gl_FragColor = texColor * v_alpha; | 730 gl_FragColor = texColor * v_alpha; |
696 } | 731 } |
697 ); // NOLINT(whitespace/parens) | 732 ); // NOLINT(whitespace/parens) |
698 } | 733 } |
699 | 734 |
700 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString( | 735 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString( |
701 TexCoordPrecision precision) const { | 736 TexCoordPrecision precision) const { |
702 return "#extension GL_ARB_texture_rectangle : require\n" + | 737 return "#extension GL_ARB_texture_rectangle : require\n" + |
703 FRAGMENT_SHADER( | 738 FRAGMENT_SHADER( |
704 precision mediump float; | 739 precision mediump float; |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 vec2 texCoord = | 1595 vec2 texCoord = |
1561 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 1596 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
1562 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1597 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1563 float picker = abs(coord.x - coord.y); | 1598 float picker = abs(coord.x - coord.y); |
1564 gl_FragColor = mix(color1, color2, picker) * alpha; | 1599 gl_FragColor = mix(color1, color2, picker) * alpha; |
1565 } | 1600 } |
1566 ); // NOLINT(whitespace/parens) | 1601 ); // NOLINT(whitespace/parens) |
1567 } | 1602 } |
1568 | 1603 |
1569 } // namespace cc | 1604 } // namespace cc |
OLD | NEW |