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 "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 12 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
13 #include "third_party/khronos/GLES2/gl2.h" | 13 #include "third_party/khronos/GLES2/gl2.h" |
14 | 14 |
15 #define SHADER0(Src) #Src | 15 #define SHADER0(Src) #Src |
16 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) | 16 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) |
17 #define FRAGMENT_SHADER(Src) SetFragTexCoordPrecision(precision, SHADER0(Src)) | 17 #define FRAGMENT_SHADER(Src) SetFragmentTexCoordPrecision( \ |
| 18 precision, SetFragmentSamplerType(sampler, SHADER0(Src))) |
18 | 19 |
19 using blink::WebGraphicsContext3D; | 20 using blink::WebGraphicsContext3D; |
20 | 21 |
21 namespace cc { | 22 namespace cc { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 static void GetProgramUniformLocations(WebGraphicsContext3D* context, | 26 static void GetProgramUniformLocations(WebGraphicsContext3D* context, |
26 unsigned program, | 27 unsigned program, |
27 size_t count, | 28 size_t count, |
28 const char** uniforms, | 29 const char** uniforms, |
29 int* locations, | 30 int* locations, |
30 int* base_uniform_index) { | 31 int* base_uniform_index) { |
31 for (size_t i = 0; i < count; i++) { | 32 for (size_t i = 0; i < count; i++) { |
32 locations[i] = (*base_uniform_index)++; | 33 locations[i] = (*base_uniform_index)++; |
33 context->bindUniformLocationCHROMIUM(program, locations[i], uniforms[i]); | 34 context->bindUniformLocationCHROMIUM(program, locations[i], uniforms[i]); |
34 } | 35 } |
35 } | 36 } |
36 | 37 |
37 static std::string SetFragTexCoordPrecision( | 38 static std::string SetFragmentTexCoordPrecision( |
38 TexCoordPrecision requested_precision, std::string shader_string) { | 39 TexCoordPrecision requested_precision, std::string shader_string) { |
39 switch (requested_precision) { | 40 switch (requested_precision) { |
40 case TexCoordPrecisionHigh: | 41 case TexCoordPrecisionHigh: |
41 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); | 42 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); |
42 return | 43 return |
43 "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" | 44 "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" |
44 " #define TexCoordPrecision highp\n" | 45 " #define TexCoordPrecision highp\n" |
45 "#else\n" | 46 "#else\n" |
46 " #define TexCoordPrecision mediump\n" | 47 " #define TexCoordPrecision mediump\n" |
47 "#endif\n" + | 48 "#endif\n" + |
48 shader_string; | 49 shader_string; |
49 case TexCoordPrecisionMedium: | 50 case TexCoordPrecisionMedium: |
50 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); | 51 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); |
51 return "#define TexCoordPrecision mediump\n" + | 52 return "#define TexCoordPrecision mediump\n" + |
52 shader_string; | 53 shader_string; |
53 case TexCoordPrecisionNA: | 54 case TexCoordPrecisionNA: |
54 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); | 55 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); |
55 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); | 56 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); |
| 57 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); |
56 return shader_string; | 58 return shader_string; |
| 59 default: |
| 60 NOTREACHED(); |
| 61 break; |
57 } | 62 } |
58 return shader_string; | 63 return shader_string; |
59 } | 64 } |
60 | 65 |
61 static std::string SetVertexTexCoordPrecision(const char* shader_string) { | 66 static std::string SetVertexTexCoordPrecision(const char* shader_string) { |
62 // We unconditionally use highp in the vertex shader since | 67 // We unconditionally use highp in the vertex shader since |
63 // we are unlikely to be vertex shader bound when drawing large quads. | 68 // we are unlikely to be vertex shader bound when drawing large quads. |
64 // Also, some vertex shaders mutate the texture coordinate in such a | 69 // Also, some vertex shaders mutate the texture coordinate in such a |
65 // way that the effective precision might be lower than expected. | 70 // way that the effective precision might be lower than expected. |
66 return "#define TexCoordPrecision highp\n" + | 71 return "#define TexCoordPrecision highp\n" + |
(...skipping 16 matching lines...) Expand all Loading... |
83 range, &precision)); | 88 range, &precision)); |
84 *highp_threshold_cache = 1 << precision; | 89 *highp_threshold_cache = 1 << precision; |
85 } | 90 } |
86 | 91 |
87 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min); | 92 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min); |
88 if (x > highp_threshold || y > highp_threshold) | 93 if (x > highp_threshold || y > highp_threshold) |
89 return TexCoordPrecisionHigh; | 94 return TexCoordPrecisionHigh; |
90 return TexCoordPrecisionMedium; | 95 return TexCoordPrecisionMedium; |
91 } | 96 } |
92 | 97 |
| 98 static std::string SetFragmentSamplerType( |
| 99 SamplerType requested_type, std::string shader_string) { |
| 100 switch (requested_type) { |
| 101 case SamplerType2D: |
| 102 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); |
| 103 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); |
| 104 return |
| 105 "#define SamplerType sampler2D\n" |
| 106 "#define TextureLookup texture2D\n" + |
| 107 shader_string; |
| 108 case SamplerType2DRect: |
| 109 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); |
| 110 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); |
| 111 return |
| 112 "#extension GL_ARB_texture_rectangle : require\n" |
| 113 "#define SamplerType sampler2DRect\n" |
| 114 "#define TextureLookup texture2DRect\n" + |
| 115 shader_string; |
| 116 case SamplerTypeExternalOES: |
| 117 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); |
| 118 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); |
| 119 return |
| 120 "#extension GL_OES_EGL_image_external : require\n" |
| 121 "#define SamplerType samplerExternalOES\n" |
| 122 "#define TextureLookup texture2D\n" + |
| 123 shader_string; |
| 124 case SamplerTypeNA: |
| 125 DCHECK_EQ(shader_string.find("SamplerType"), std::string::npos); |
| 126 DCHECK_EQ(shader_string.find("TextureLookup"), std::string::npos); |
| 127 return shader_string; |
| 128 default: |
| 129 NOTREACHED(); |
| 130 break; |
| 131 } |
| 132 return shader_string; |
| 133 } |
| 134 |
93 } // namespace | 135 } // namespace |
94 | 136 |
95 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, | 137 TexCoordPrecision TexCoordPrecisionRequired(WebGraphicsContext3D* context, |
96 int *highp_threshold_cache, | 138 int *highp_threshold_cache, |
97 int highp_threshold_min, | 139 int highp_threshold_min, |
98 gfx::Point max_coordinate) { | 140 gfx::Point max_coordinate) { |
99 return TexCoordPrecisionRequired(context, | 141 return TexCoordPrecisionRequired(context, |
100 highp_threshold_cache, highp_threshold_min, | 142 highp_threshold_cache, highp_threshold_min, |
101 max_coordinate.x(), max_coordinate.y()); | 143 max_coordinate.x(), max_coordinate.y()); |
102 } | 144 } |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 | 690 |
649 GetProgramUniformLocations(context, | 691 GetProgramUniformLocations(context, |
650 program, | 692 program, |
651 arraysize(uniforms), | 693 arraysize(uniforms), |
652 uniforms, | 694 uniforms, |
653 locations, | 695 locations, |
654 base_uniform_index); | 696 base_uniform_index); |
655 sampler_location_ = locations[0]; | 697 sampler_location_ = locations[0]; |
656 } | 698 } |
657 | 699 |
658 FragmentShaderOESImageExternal::FragmentShaderOESImageExternal() | |
659 : sampler_location_(-1) {} | |
660 | |
661 void FragmentShaderOESImageExternal::Init(WebGraphicsContext3D* context, | |
662 unsigned program, | |
663 int* base_uniform_index) { | |
664 static const char* uniforms[] = { | |
665 "s_texture", | |
666 }; | |
667 int locations[arraysize(uniforms)]; | |
668 | |
669 GetProgramUniformLocations(context, | |
670 program, | |
671 arraysize(uniforms), | |
672 uniforms, | |
673 locations, | |
674 base_uniform_index); | |
675 sampler_location_ = locations[0]; | |
676 } | |
677 | |
678 std::string FragmentShaderOESImageExternal::GetShaderString( | |
679 TexCoordPrecision precision) const { | |
680 // Cannot use the SHADER() macro because of the '#' char | |
681 return "#extension GL_OES_EGL_image_external : require\n" + | |
682 FRAGMENT_SHADER( | |
683 precision mediump float; | |
684 varying TexCoordPrecision vec2 v_texCoord; | |
685 uniform samplerExternalOES s_texture; | |
686 void main() { | |
687 vec4 texColor = texture2D(s_texture, v_texCoord); | |
688 gl_FragColor = texColor; | |
689 } | |
690 ); // NOLINT(whitespace/parens) | |
691 } | |
692 | |
693 std::string FragmentShaderRGBATexAlpha::GetShaderString( | 700 std::string FragmentShaderRGBATexAlpha::GetShaderString( |
694 TexCoordPrecision precision) const { | 701 TexCoordPrecision precision, SamplerType sampler) const { |
695 return FRAGMENT_SHADER( | 702 return FRAGMENT_SHADER( |
696 precision mediump float; | 703 precision mediump float; |
697 varying TexCoordPrecision vec2 v_texCoord; | 704 varying TexCoordPrecision vec2 v_texCoord; |
698 uniform sampler2D s_texture; | 705 uniform SamplerType s_texture; |
699 uniform float alpha; | 706 uniform float alpha; |
700 void main() { | 707 void main() { |
701 vec4 texColor = texture2D(s_texture, v_texCoord); | 708 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
702 gl_FragColor = texColor * alpha; | 709 gl_FragColor = texColor * alpha; |
703 } | 710 } |
704 ); // NOLINT(whitespace/parens) | 711 ); // NOLINT(whitespace/parens) |
705 } | 712 } |
706 | 713 |
707 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( | 714 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( |
708 TexCoordPrecision precision) const { | 715 TexCoordPrecision precision, SamplerType sampler) const { |
709 return FRAGMENT_SHADER( | 716 return FRAGMENT_SHADER( |
710 precision mediump float; | 717 precision mediump float; |
711 varying TexCoordPrecision vec2 v_texCoord; | 718 varying TexCoordPrecision vec2 v_texCoord; |
712 uniform sampler2D s_texture; | 719 uniform SamplerType s_texture; |
713 uniform float alpha; | 720 uniform float alpha; |
714 uniform mat4 colorMatrix; | 721 uniform mat4 colorMatrix; |
715 uniform vec4 colorOffset; | 722 uniform vec4 colorOffset; |
716 void main() { | 723 void main() { |
717 vec4 texColor = texture2D(s_texture, v_texCoord); | 724 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
718 float nonZeroAlpha = max(texColor.a, 0.00001); | 725 float nonZeroAlpha = max(texColor.a, 0.00001); |
719 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 726 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
720 texColor = colorMatrix * texColor + colorOffset; | 727 texColor = colorMatrix * texColor + colorOffset; |
721 texColor.rgb *= texColor.a; | 728 texColor.rgb *= texColor.a; |
722 texColor = clamp(texColor, 0.0, 1.0); | 729 texColor = clamp(texColor, 0.0, 1.0); |
723 gl_FragColor = texColor * alpha; | 730 gl_FragColor = texColor * alpha; |
724 } | 731 } |
725 ); // NOLINT(whitespace/parens) | 732 ); // NOLINT(whitespace/parens) |
726 } | 733 } |
727 | 734 |
728 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 735 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
729 TexCoordPrecision precision) const { | 736 TexCoordPrecision precision, SamplerType sampler) const { |
730 return FRAGMENT_SHADER( | 737 return FRAGMENT_SHADER( |
731 precision mediump float; | 738 precision mediump float; |
732 varying TexCoordPrecision vec2 v_texCoord; | 739 varying TexCoordPrecision vec2 v_texCoord; |
733 varying float v_alpha; | 740 varying float v_alpha; |
734 uniform sampler2D s_texture; | 741 uniform SamplerType s_texture; |
735 void main() { | 742 void main() { |
736 vec4 texColor = texture2D(s_texture, v_texCoord); | 743 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
737 gl_FragColor = texColor * v_alpha; | 744 gl_FragColor = texColor * v_alpha; |
738 } | 745 } |
739 ); // NOLINT(whitespace/parens) | 746 ); // NOLINT(whitespace/parens) |
740 } | 747 } |
741 | 748 |
742 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( | 749 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( |
743 TexCoordPrecision precision) const { | 750 TexCoordPrecision precision, SamplerType sampler) const { |
744 return FRAGMENT_SHADER( | 751 return FRAGMENT_SHADER( |
745 precision mediump float; | 752 precision mediump float; |
746 varying TexCoordPrecision vec2 v_texCoord; | 753 varying TexCoordPrecision vec2 v_texCoord; |
747 varying float v_alpha; | 754 varying float v_alpha; |
748 uniform sampler2D s_texture; | 755 uniform SamplerType s_texture; |
749 void main() { | 756 void main() { |
750 vec4 texColor = texture2D(s_texture, v_texCoord); | 757 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
751 texColor.rgb *= texColor.a; | 758 texColor.rgb *= texColor.a; |
752 gl_FragColor = texColor * v_alpha; | 759 gl_FragColor = texColor * v_alpha; |
753 } | 760 } |
754 ); // NOLINT(whitespace/parens) | 761 ); // NOLINT(whitespace/parens) |
755 } | 762 } |
756 | 763 |
757 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() | 764 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() |
758 : background_color_location_(-1), | 765 : background_color_location_(-1), |
759 sampler_location_(-1) { | 766 sampler_location_(-1) { |
760 } | 767 } |
(...skipping 15 matching lines...) Expand all Loading... |
776 base_uniform_index); | 783 base_uniform_index); |
777 | 784 |
778 sampler_location_ = locations[0]; | 785 sampler_location_ = locations[0]; |
779 DCHECK_NE(sampler_location_, -1); | 786 DCHECK_NE(sampler_location_, -1); |
780 | 787 |
781 background_color_location_ = locations[1]; | 788 background_color_location_ = locations[1]; |
782 DCHECK_NE(background_color_location_, -1); | 789 DCHECK_NE(background_color_location_, -1); |
783 } | 790 } |
784 | 791 |
785 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( | 792 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( |
786 TexCoordPrecision precision) const { | 793 TexCoordPrecision precision, SamplerType sampler) const { |
787 return FRAGMENT_SHADER( | 794 return FRAGMENT_SHADER( |
788 precision mediump float; | 795 precision mediump float; |
789 varying TexCoordPrecision vec2 v_texCoord; | 796 varying TexCoordPrecision vec2 v_texCoord; |
790 varying float v_alpha; | 797 varying float v_alpha; |
791 uniform vec4 background_color; | 798 uniform vec4 background_color; |
792 uniform sampler2D s_texture; | 799 uniform SamplerType s_texture; |
793 void main() { | 800 void main() { |
794 vec4 texColor = texture2D(s_texture, v_texCoord); | 801 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
795 texColor += background_color * (1.0 - texColor.a); | 802 texColor += background_color * (1.0 - texColor.a); |
796 gl_FragColor = texColor * v_alpha; | 803 gl_FragColor = texColor * v_alpha; |
797 } | 804 } |
798 ); // NOLINT(whitespace/parens) | 805 ); // NOLINT(whitespace/parens) |
799 } | 806 } |
800 | 807 |
801 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( | 808 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( |
802 TexCoordPrecision precision) const { | 809 TexCoordPrecision precision, SamplerType sampler) const { |
803 return FRAGMENT_SHADER( | 810 return FRAGMENT_SHADER( |
804 precision mediump float; | 811 precision mediump float; |
805 varying TexCoordPrecision vec2 v_texCoord; | 812 varying TexCoordPrecision vec2 v_texCoord; |
806 varying float v_alpha; | 813 varying float v_alpha; |
807 uniform vec4 background_color; | 814 uniform vec4 background_color; |
808 uniform sampler2D s_texture; | 815 uniform SamplerType s_texture; |
809 void main() { | 816 void main() { |
810 vec4 texColor = texture2D(s_texture, v_texCoord); | 817 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
811 texColor.rgb *= texColor.a; | 818 texColor.rgb *= texColor.a; |
812 texColor += background_color * (1.0 - texColor.a); | 819 texColor += background_color * (1.0 - texColor.a); |
813 gl_FragColor = texColor * v_alpha; | 820 gl_FragColor = texColor * v_alpha; |
814 } | 821 } |
815 ); // NOLINT(whitespace/parens) | 822 ); // NOLINT(whitespace/parens) |
816 } | 823 } |
817 | 824 |
818 std::string FragmentShaderRGBATexRectVaryingAlpha::GetShaderString( | |
819 TexCoordPrecision precision) const { | |
820 return "#extension GL_ARB_texture_rectangle : require\n" + | |
821 FRAGMENT_SHADER( | |
822 precision mediump float; | |
823 varying TexCoordPrecision vec2 v_texCoord; | |
824 varying float v_alpha; | |
825 uniform sampler2DRect s_texture; | |
826 void main() { | |
827 vec4 texColor = texture2DRect(s_texture, v_texCoord); | |
828 gl_FragColor = texColor * v_alpha; | |
829 } | |
830 ); // NOLINT(whitespace/parens) | |
831 } | |
832 | |
833 std::string FragmentShaderRGBATexOpaque::GetShaderString( | 825 std::string FragmentShaderRGBATexOpaque::GetShaderString( |
834 TexCoordPrecision precision) const { | 826 TexCoordPrecision precision, SamplerType sampler) const { |
835 return FRAGMENT_SHADER( | 827 return FRAGMENT_SHADER( |
836 precision mediump float; | 828 precision mediump float; |
837 varying TexCoordPrecision vec2 v_texCoord; | 829 varying TexCoordPrecision vec2 v_texCoord; |
838 uniform sampler2D s_texture; | 830 uniform SamplerType s_texture; |
839 void main() { | 831 void main() { |
840 vec4 texColor = texture2D(s_texture, v_texCoord); | 832 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
841 gl_FragColor = vec4(texColor.rgb, 1.0); | 833 gl_FragColor = vec4(texColor.rgb, 1.0); |
842 } | 834 } |
843 ); // NOLINT(whitespace/parens) | 835 ); // NOLINT(whitespace/parens) |
844 } | 836 } |
845 | 837 |
846 std::string FragmentShaderRGBATex::GetShaderString( | 838 std::string FragmentShaderRGBATex::GetShaderString( |
847 TexCoordPrecision precision) const { | 839 TexCoordPrecision precision, SamplerType sampler) const { |
848 return FRAGMENT_SHADER( | 840 return FRAGMENT_SHADER( |
849 precision mediump float; | 841 precision mediump float; |
850 varying TexCoordPrecision vec2 v_texCoord; | 842 varying TexCoordPrecision vec2 v_texCoord; |
851 uniform sampler2D s_texture; | 843 uniform SamplerType s_texture; |
852 void main() { | 844 void main() { |
853 gl_FragColor = texture2D(s_texture, v_texCoord); | 845 gl_FragColor = TextureLookup(s_texture, v_texCoord); |
854 } | 846 } |
855 ); // NOLINT(whitespace/parens) | 847 ); // NOLINT(whitespace/parens) |
856 } | 848 } |
857 | 849 |
858 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( | 850 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( |
859 TexCoordPrecision precision) const { | 851 TexCoordPrecision precision, SamplerType sampler) const { |
860 return FRAGMENT_SHADER( | 852 return FRAGMENT_SHADER( |
861 precision mediump float; | 853 precision mediump float; |
862 varying TexCoordPrecision vec2 v_texCoord; | 854 varying TexCoordPrecision vec2 v_texCoord; |
863 uniform sampler2D s_texture; | 855 uniform SamplerType s_texture; |
864 uniform float alpha; | 856 uniform float alpha; |
865 void main() { | 857 void main() { |
866 vec4 texColor = texture2D(s_texture, v_texCoord); | 858 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
867 gl_FragColor = | 859 gl_FragColor = |
868 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | 860 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
869 } | 861 } |
870 ); // NOLINT(whitespace/parens) | 862 ); // NOLINT(whitespace/parens) |
871 } | 863 } |
872 | 864 |
873 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( | 865 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( |
874 TexCoordPrecision precision) const { | 866 TexCoordPrecision precision, SamplerType sampler) const { |
875 return FRAGMENT_SHADER( | 867 return FRAGMENT_SHADER( |
876 precision mediump float; | 868 precision mediump float; |
877 varying TexCoordPrecision vec2 v_texCoord; | 869 varying TexCoordPrecision vec2 v_texCoord; |
878 uniform sampler2D s_texture; | 870 uniform SamplerType s_texture; |
879 void main() { | 871 void main() { |
880 vec4 texColor = texture2D(s_texture, v_texCoord); | 872 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
881 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 873 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
882 } | 874 } |
883 ); // NOLINT(whitespace/parens) | 875 ); // NOLINT(whitespace/parens) |
884 } | 876 } |
885 | 877 |
886 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 878 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
887 : sampler_location_(-1), | 879 : sampler_location_(-1), |
888 alpha_location_(-1) {} | 880 alpha_location_(-1) {} |
889 | 881 |
890 void FragmentShaderRGBATexAlphaAA::Init(WebGraphicsContext3D* context, | 882 void FragmentShaderRGBATexAlphaAA::Init(WebGraphicsContext3D* context, |
891 unsigned program, | 883 unsigned program, |
892 int* base_uniform_index) { | 884 int* base_uniform_index) { |
893 static const char* uniforms[] = { | 885 static const char* uniforms[] = { |
894 "s_texture", | 886 "s_texture", |
895 "alpha", | 887 "alpha", |
896 }; | 888 }; |
897 int locations[arraysize(uniforms)]; | 889 int locations[arraysize(uniforms)]; |
898 | 890 |
899 GetProgramUniformLocations(context, | 891 GetProgramUniformLocations(context, |
900 program, | 892 program, |
901 arraysize(uniforms), | 893 arraysize(uniforms), |
902 uniforms, | 894 uniforms, |
903 locations, | 895 locations, |
904 base_uniform_index); | 896 base_uniform_index); |
905 sampler_location_ = locations[0]; | 897 sampler_location_ = locations[0]; |
906 alpha_location_ = locations[1]; | 898 alpha_location_ = locations[1]; |
907 } | 899 } |
908 | 900 |
909 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( | 901 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( |
910 TexCoordPrecision precision) const { | 902 TexCoordPrecision precision, SamplerType sampler) const { |
911 return FRAGMENT_SHADER( | 903 return FRAGMENT_SHADER( |
912 precision mediump float; | 904 precision mediump float; |
913 uniform sampler2D s_texture; | 905 uniform SamplerType s_texture; |
914 uniform float alpha; | 906 uniform float alpha; |
915 varying TexCoordPrecision vec2 v_texCoord; | 907 varying TexCoordPrecision vec2 v_texCoord; |
916 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 908 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
917 | 909 |
918 void main() { | 910 void main() { |
919 vec4 texColor = texture2D(s_texture, v_texCoord); | 911 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
920 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 912 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
921 vec2 d2 = min(d4.xz, d4.yw); | 913 vec2 d2 = min(d4.xz, d4.yw); |
922 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 914 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
923 gl_FragColor = texColor * alpha * aa; | 915 gl_FragColor = texColor * alpha * aa; |
924 } | 916 } |
925 ); // NOLINT(whitespace/parens) | 917 ); // NOLINT(whitespace/parens) |
926 } | 918 } |
927 | 919 |
928 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | 920 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() |
929 : sampler_location_(-1), | 921 : sampler_location_(-1), |
(...skipping 15 matching lines...) Expand all Loading... |
945 arraysize(uniforms), | 937 arraysize(uniforms), |
946 uniforms, | 938 uniforms, |
947 locations, | 939 locations, |
948 base_uniform_index); | 940 base_uniform_index); |
949 sampler_location_ = locations[0]; | 941 sampler_location_ = locations[0]; |
950 alpha_location_ = locations[1]; | 942 alpha_location_ = locations[1]; |
951 fragment_tex_transform_location_ = locations[2]; | 943 fragment_tex_transform_location_ = locations[2]; |
952 } | 944 } |
953 | 945 |
954 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( | 946 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( |
955 TexCoordPrecision precision) const { | 947 TexCoordPrecision precision, SamplerType sampler) const { |
956 return FRAGMENT_SHADER( | 948 return FRAGMENT_SHADER( |
957 precision mediump float; | 949 precision mediump float; |
958 uniform sampler2D s_texture; | 950 uniform SamplerType s_texture; |
959 uniform float alpha; | 951 uniform float alpha; |
960 uniform TexCoordPrecision vec4 fragmentTexTransform; | 952 uniform TexCoordPrecision vec4 fragmentTexTransform; |
961 varying TexCoordPrecision vec2 v_texCoord; | 953 varying TexCoordPrecision vec2 v_texCoord; |
962 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 954 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
963 | 955 |
964 void main() { | 956 void main() { |
965 TexCoordPrecision vec2 texCoord = | 957 TexCoordPrecision vec2 texCoord = |
966 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 958 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
967 fragmentTexTransform.xy; | 959 fragmentTexTransform.xy; |
968 vec4 texColor = texture2D(s_texture, texCoord); | 960 vec4 texColor = TextureLookup(s_texture, texCoord); |
969 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 961 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
970 vec2 d2 = min(d4.xz, d4.yw); | 962 vec2 d2 = min(d4.xz, d4.yw); |
971 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 963 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
972 gl_FragColor = texColor * alpha * aa; | 964 gl_FragColor = texColor * alpha * aa; |
973 } | 965 } |
974 ); // NOLINT(whitespace/parens) | 966 ); // NOLINT(whitespace/parens) |
975 } | 967 } |
976 | 968 |
977 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( | 969 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( |
978 TexCoordPrecision precision) const { | 970 TexCoordPrecision precision, SamplerType sampler) const { |
979 return FRAGMENT_SHADER( | 971 return FRAGMENT_SHADER( |
980 precision mediump float; | 972 precision mediump float; |
981 uniform sampler2D s_texture; | 973 uniform SamplerType s_texture; |
982 uniform float alpha; | 974 uniform float alpha; |
983 uniform TexCoordPrecision vec4 fragmentTexTransform; | 975 uniform TexCoordPrecision vec4 fragmentTexTransform; |
984 varying TexCoordPrecision vec2 v_texCoord; | 976 varying TexCoordPrecision vec2 v_texCoord; |
985 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 977 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
986 | 978 |
987 void main() { | 979 void main() { |
988 TexCoordPrecision vec2 texCoord = | 980 TexCoordPrecision vec2 texCoord = |
989 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 981 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
990 fragmentTexTransform.xy; | 982 fragmentTexTransform.xy; |
991 vec4 texColor = texture2D(s_texture, texCoord); | 983 vec4 texColor = TextureLookup(s_texture, texCoord); |
992 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 984 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
993 vec2 d2 = min(d4.xz, d4.yw); | 985 vec2 d2 = min(d4.xz, d4.yw); |
994 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 986 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
995 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * | 987 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, texColor.w) * |
996 alpha * aa; | 988 alpha * aa; |
997 } | 989 } |
998 ); // NOLINT(whitespace/parens) | 990 ); // NOLINT(whitespace/parens) |
999 } | 991 } |
1000 | 992 |
1001 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() | 993 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask() |
(...skipping 21 matching lines...) Expand all Loading... |
1023 locations, | 1015 locations, |
1024 base_uniform_index); | 1016 base_uniform_index); |
1025 sampler_location_ = locations[0]; | 1017 sampler_location_ = locations[0]; |
1026 mask_sampler_location_ = locations[1]; | 1018 mask_sampler_location_ = locations[1]; |
1027 alpha_location_ = locations[2]; | 1019 alpha_location_ = locations[2]; |
1028 mask_tex_coord_scale_location_ = locations[3]; | 1020 mask_tex_coord_scale_location_ = locations[3]; |
1029 mask_tex_coord_offset_location_ = locations[4]; | 1021 mask_tex_coord_offset_location_ = locations[4]; |
1030 } | 1022 } |
1031 | 1023 |
1032 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( | 1024 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( |
1033 TexCoordPrecision precision) const { | 1025 TexCoordPrecision precision, SamplerType sampler) const { |
1034 return FRAGMENT_SHADER( | 1026 return FRAGMENT_SHADER( |
1035 precision mediump float; | 1027 precision mediump float; |
1036 varying TexCoordPrecision vec2 v_texCoord; | 1028 varying TexCoordPrecision vec2 v_texCoord; |
1037 uniform sampler2D s_texture; | 1029 uniform SamplerType s_texture; |
1038 uniform sampler2D s_mask; | 1030 uniform SamplerType s_mask; |
1039 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1031 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1040 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1032 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1041 uniform float alpha; | 1033 uniform float alpha; |
1042 void main() { | 1034 void main() { |
1043 vec4 texColor = texture2D(s_texture, v_texCoord); | 1035 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1044 TexCoordPrecision vec2 maskTexCoord = | 1036 TexCoordPrecision vec2 maskTexCoord = |
1045 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1037 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1046 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1038 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1047 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 1039 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1048 gl_FragColor = texColor * alpha * maskColor.w; | 1040 gl_FragColor = texColor * alpha * maskColor.w; |
1049 } | 1041 } |
1050 ); // NOLINT(whitespace/parens) | 1042 ); // NOLINT(whitespace/parens) |
1051 } | 1043 } |
1052 | 1044 |
1053 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 1045 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
1054 : sampler_location_(-1), | 1046 : sampler_location_(-1), |
1055 mask_sampler_location_(-1), | 1047 mask_sampler_location_(-1), |
1056 alpha_location_(-1), | 1048 alpha_location_(-1), |
1057 mask_tex_coord_scale_location_(-1), | 1049 mask_tex_coord_scale_location_(-1), |
(...skipping 18 matching lines...) Expand all Loading... |
1076 locations, | 1068 locations, |
1077 base_uniform_index); | 1069 base_uniform_index); |
1078 sampler_location_ = locations[0]; | 1070 sampler_location_ = locations[0]; |
1079 mask_sampler_location_ = locations[1]; | 1071 mask_sampler_location_ = locations[1]; |
1080 alpha_location_ = locations[2]; | 1072 alpha_location_ = locations[2]; |
1081 mask_tex_coord_scale_location_ = locations[3]; | 1073 mask_tex_coord_scale_location_ = locations[3]; |
1082 mask_tex_coord_offset_location_ = locations[4]; | 1074 mask_tex_coord_offset_location_ = locations[4]; |
1083 } | 1075 } |
1084 | 1076 |
1085 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( | 1077 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( |
1086 TexCoordPrecision precision) const { | 1078 TexCoordPrecision precision, SamplerType sampler) const { |
1087 return FRAGMENT_SHADER( | 1079 return FRAGMENT_SHADER( |
1088 precision mediump float; | 1080 precision mediump float; |
1089 uniform sampler2D s_texture; | 1081 uniform SamplerType s_texture; |
1090 uniform sampler2D s_mask; | 1082 uniform SamplerType s_mask; |
1091 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1083 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1092 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1084 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1093 uniform float alpha; | 1085 uniform float alpha; |
1094 varying TexCoordPrecision vec2 v_texCoord; | 1086 varying TexCoordPrecision vec2 v_texCoord; |
1095 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1087 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1096 | 1088 |
1097 void main() { | 1089 void main() { |
1098 vec4 texColor = texture2D(s_texture, v_texCoord); | 1090 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1099 TexCoordPrecision vec2 maskTexCoord = | 1091 TexCoordPrecision vec2 maskTexCoord = |
1100 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1092 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1101 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1093 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1102 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 1094 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1103 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1095 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1104 vec2 d2 = min(d4.xz, d4.yw); | 1096 vec2 d2 = min(d4.xz, d4.yw); |
1105 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1097 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1106 gl_FragColor = texColor * alpha * maskColor.w * aa; | 1098 gl_FragColor = texColor * alpha * maskColor.w * aa; |
1107 } | 1099 } |
1108 ); // NOLINT(whitespace/parens) | 1100 ); // NOLINT(whitespace/parens) |
1109 } | 1101 } |
1110 | 1102 |
1111 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: | 1103 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: |
1112 FragmentShaderRGBATexAlphaMaskColorMatrixAA() | 1104 FragmentShaderRGBATexAlphaMaskColorMatrixAA() |
(...skipping 28 matching lines...) Expand all Loading... |
1141 sampler_location_ = locations[0]; | 1133 sampler_location_ = locations[0]; |
1142 mask_sampler_location_ = locations[1]; | 1134 mask_sampler_location_ = locations[1]; |
1143 alpha_location_ = locations[2]; | 1135 alpha_location_ = locations[2]; |
1144 mask_tex_coord_scale_location_ = locations[3]; | 1136 mask_tex_coord_scale_location_ = locations[3]; |
1145 mask_tex_coord_offset_location_ = locations[4]; | 1137 mask_tex_coord_offset_location_ = locations[4]; |
1146 color_matrix_location_ = locations[5]; | 1138 color_matrix_location_ = locations[5]; |
1147 color_offset_location_ = locations[6]; | 1139 color_offset_location_ = locations[6]; |
1148 } | 1140 } |
1149 | 1141 |
1150 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( | 1142 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( |
1151 TexCoordPrecision precision) const { | 1143 TexCoordPrecision precision, SamplerType sampler) const { |
1152 return FRAGMENT_SHADER( | 1144 return FRAGMENT_SHADER( |
1153 precision mediump float; | 1145 precision mediump float; |
1154 uniform sampler2D s_texture; | 1146 uniform SamplerType s_texture; |
1155 uniform sampler2D s_mask; | 1147 uniform SamplerType s_mask; |
1156 uniform vec2 maskTexCoordScale; | 1148 uniform vec2 maskTexCoordScale; |
1157 uniform vec2 maskTexCoordOffset; | 1149 uniform vec2 maskTexCoordOffset; |
1158 uniform mat4 colorMatrix; | 1150 uniform mat4 colorMatrix; |
1159 uniform vec4 colorOffset; | 1151 uniform vec4 colorOffset; |
1160 uniform float alpha; | 1152 uniform float alpha; |
1161 varying TexCoordPrecision vec2 v_texCoord; | 1153 varying TexCoordPrecision vec2 v_texCoord; |
1162 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1154 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1163 | 1155 |
1164 void main() { | 1156 void main() { |
1165 vec4 texColor = texture2D(s_texture, v_texCoord); | 1157 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1166 float nonZeroAlpha = max(texColor.a, 0.00001); | 1158 float nonZeroAlpha = max(texColor.a, 0.00001); |
1167 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1159 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1168 texColor = colorMatrix * texColor + colorOffset; | 1160 texColor = colorMatrix * texColor + colorOffset; |
1169 texColor.rgb *= texColor.a; | 1161 texColor.rgb *= texColor.a; |
1170 texColor = clamp(texColor, 0.0, 1.0); | 1162 texColor = clamp(texColor, 0.0, 1.0); |
1171 TexCoordPrecision vec2 maskTexCoord = | 1163 TexCoordPrecision vec2 maskTexCoord = |
1172 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1164 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1173 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1165 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1174 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 1166 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1175 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1167 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1176 vec2 d2 = min(d4.xz, d4.yw); | 1168 vec2 d2 = min(d4.xz, d4.yw); |
1177 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1169 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1178 gl_FragColor = texColor * alpha * maskColor.w * aa; | 1170 gl_FragColor = texColor * alpha * maskColor.w * aa; |
1179 } | 1171 } |
1180 ); // NOLINT(whitespace/parens) | 1172 ); // NOLINT(whitespace/parens) |
1181 } | 1173 } |
1182 | 1174 |
1183 FragmentShaderRGBATexAlphaColorMatrixAA:: | 1175 FragmentShaderRGBATexAlphaColorMatrixAA:: |
1184 FragmentShaderRGBATexAlphaColorMatrixAA() | 1176 FragmentShaderRGBATexAlphaColorMatrixAA() |
(...skipping 20 matching lines...) Expand all Loading... |
1205 uniforms, | 1197 uniforms, |
1206 locations, | 1198 locations, |
1207 base_uniform_index); | 1199 base_uniform_index); |
1208 sampler_location_ = locations[0]; | 1200 sampler_location_ = locations[0]; |
1209 alpha_location_ = locations[1]; | 1201 alpha_location_ = locations[1]; |
1210 color_matrix_location_ = locations[2]; | 1202 color_matrix_location_ = locations[2]; |
1211 color_offset_location_ = locations[3]; | 1203 color_offset_location_ = locations[3]; |
1212 } | 1204 } |
1213 | 1205 |
1214 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( | 1206 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( |
1215 TexCoordPrecision precision) const { | 1207 TexCoordPrecision precision, SamplerType sampler) const { |
1216 return FRAGMENT_SHADER( | 1208 return FRAGMENT_SHADER( |
1217 precision mediump float; | 1209 precision mediump float; |
1218 uniform sampler2D s_texture; | 1210 uniform SamplerType s_texture; |
1219 uniform float alpha; | 1211 uniform float alpha; |
1220 uniform mat4 colorMatrix; | 1212 uniform mat4 colorMatrix; |
1221 uniform vec4 colorOffset; | 1213 uniform vec4 colorOffset; |
1222 varying TexCoordPrecision vec2 v_texCoord; | 1214 varying TexCoordPrecision vec2 v_texCoord; |
1223 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1215 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1224 | 1216 |
1225 void main() { | 1217 void main() { |
1226 vec4 texColor = texture2D(s_texture, v_texCoord); | 1218 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1227 float nonZeroAlpha = max(texColor.a, 0.00001); | 1219 float nonZeroAlpha = max(texColor.a, 0.00001); |
1228 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1220 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1229 texColor = colorMatrix * texColor + colorOffset; | 1221 texColor = colorMatrix * texColor + colorOffset; |
1230 texColor.rgb *= texColor.a; | 1222 texColor.rgb *= texColor.a; |
1231 texColor = clamp(texColor, 0.0, 1.0); | 1223 texColor = clamp(texColor, 0.0, 1.0); |
1232 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1224 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1233 vec2 d2 = min(d4.xz, d4.yw); | 1225 vec2 d2 = min(d4.xz, d4.yw); |
1234 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1226 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1235 gl_FragColor = texColor * alpha * aa; | 1227 gl_FragColor = texColor * alpha * aa; |
1236 } | 1228 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 sampler_location_ = locations[0]; | 1260 sampler_location_ = locations[0]; |
1269 mask_sampler_location_ = locations[1]; | 1261 mask_sampler_location_ = locations[1]; |
1270 alpha_location_ = locations[2]; | 1262 alpha_location_ = locations[2]; |
1271 mask_tex_coord_scale_location_ = locations[3]; | 1263 mask_tex_coord_scale_location_ = locations[3]; |
1272 mask_tex_coord_offset_location_ = locations[4]; | 1264 mask_tex_coord_offset_location_ = locations[4]; |
1273 color_matrix_location_ = locations[5]; | 1265 color_matrix_location_ = locations[5]; |
1274 color_offset_location_ = locations[6]; | 1266 color_offset_location_ = locations[6]; |
1275 } | 1267 } |
1276 | 1268 |
1277 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( | 1269 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( |
1278 TexCoordPrecision precision) const { | 1270 TexCoordPrecision precision, SamplerType sampler) const { |
1279 return FRAGMENT_SHADER( | 1271 return FRAGMENT_SHADER( |
1280 precision mediump float; | 1272 precision mediump float; |
1281 varying TexCoordPrecision vec2 v_texCoord; | 1273 varying TexCoordPrecision vec2 v_texCoord; |
1282 uniform sampler2D s_texture; | 1274 uniform SamplerType s_texture; |
1283 uniform sampler2D s_mask; | 1275 uniform SamplerType s_mask; |
1284 uniform vec2 maskTexCoordScale; | 1276 uniform vec2 maskTexCoordScale; |
1285 uniform vec2 maskTexCoordOffset; | 1277 uniform vec2 maskTexCoordOffset; |
1286 uniform mat4 colorMatrix; | 1278 uniform mat4 colorMatrix; |
1287 uniform vec4 colorOffset; | 1279 uniform vec4 colorOffset; |
1288 uniform float alpha; | 1280 uniform float alpha; |
1289 void main() { | 1281 void main() { |
1290 vec4 texColor = texture2D(s_texture, v_texCoord); | 1282 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1291 float nonZeroAlpha = max(texColor.a, 0.00001); | 1283 float nonZeroAlpha = max(texColor.a, 0.00001); |
1292 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1284 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1293 texColor = colorMatrix * texColor + colorOffset; | 1285 texColor = colorMatrix * texColor + colorOffset; |
1294 texColor.rgb *= texColor.a; | 1286 texColor.rgb *= texColor.a; |
1295 texColor = clamp(texColor, 0.0, 1.0); | 1287 texColor = clamp(texColor, 0.0, 1.0); |
1296 TexCoordPrecision vec2 maskTexCoord = | 1288 TexCoordPrecision vec2 maskTexCoord = |
1297 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1289 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1298 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1290 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1299 vec4 maskColor = texture2D(s_mask, maskTexCoord); | 1291 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1300 gl_FragColor = texColor * alpha * maskColor.w; | 1292 gl_FragColor = texColor * alpha * maskColor.w; |
1301 } | 1293 } |
1302 ); // NOLINT(whitespace/parens) | 1294 ); // NOLINT(whitespace/parens) |
1303 } | 1295 } |
1304 | 1296 |
1305 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 1297 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
1306 : y_texture_location_(-1), | 1298 : y_texture_location_(-1), |
1307 u_texture_location_(-1), | 1299 u_texture_location_(-1), |
1308 v_texture_location_(-1), | 1300 v_texture_location_(-1), |
1309 alpha_location_(-1), | 1301 alpha_location_(-1), |
(...skipping 21 matching lines...) Expand all Loading... |
1331 base_uniform_index); | 1323 base_uniform_index); |
1332 y_texture_location_ = locations[0]; | 1324 y_texture_location_ = locations[0]; |
1333 u_texture_location_ = locations[1]; | 1325 u_texture_location_ = locations[1]; |
1334 v_texture_location_ = locations[2]; | 1326 v_texture_location_ = locations[2]; |
1335 alpha_location_ = locations[3]; | 1327 alpha_location_ = locations[3]; |
1336 yuv_matrix_location_ = locations[4]; | 1328 yuv_matrix_location_ = locations[4]; |
1337 yuv_adj_location_ = locations[5]; | 1329 yuv_adj_location_ = locations[5]; |
1338 } | 1330 } |
1339 | 1331 |
1340 std::string FragmentShaderYUVVideo::GetShaderString( | 1332 std::string FragmentShaderYUVVideo::GetShaderString( |
1341 TexCoordPrecision precision) const { | 1333 TexCoordPrecision precision, SamplerType sampler) const { |
1342 return FRAGMENT_SHADER( | 1334 return FRAGMENT_SHADER( |
1343 precision mediump float; | 1335 precision mediump float; |
1344 precision mediump int; | 1336 precision mediump int; |
1345 varying TexCoordPrecision vec2 v_texCoord; | 1337 varying TexCoordPrecision vec2 v_texCoord; |
1346 uniform sampler2D y_texture; | 1338 uniform SamplerType y_texture; |
1347 uniform sampler2D u_texture; | 1339 uniform SamplerType u_texture; |
1348 uniform sampler2D v_texture; | 1340 uniform SamplerType v_texture; |
1349 uniform float alpha; | 1341 uniform float alpha; |
1350 uniform vec3 yuv_adj; | 1342 uniform vec3 yuv_adj; |
1351 uniform mat3 yuv_matrix; | 1343 uniform mat3 yuv_matrix; |
1352 void main() { | 1344 void main() { |
1353 float y_raw = texture2D(y_texture, v_texCoord).x; | 1345 float y_raw = TextureLookup(y_texture, v_texCoord).x; |
1354 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 1346 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; |
1355 float v_unsigned = texture2D(v_texture, v_texCoord).x; | 1347 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; |
1356 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1348 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
1357 vec3 rgb = yuv_matrix * yuv; | 1349 vec3 rgb = yuv_matrix * yuv; |
1358 gl_FragColor = vec4(rgb, 1.0) * alpha; | 1350 gl_FragColor = vec4(rgb, 1.0) * alpha; |
1359 } | 1351 } |
1360 ); // NOLINT(whitespace/parens) | 1352 ); // NOLINT(whitespace/parens) |
1361 } | 1353 } |
1362 | 1354 |
1363 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() | 1355 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() |
1364 : y_texture_location_(-1), | 1356 : y_texture_location_(-1), |
1365 u_texture_location_(-1), | 1357 u_texture_location_(-1), |
(...skipping 27 matching lines...) Expand all Loading... |
1393 y_texture_location_ = locations[0]; | 1385 y_texture_location_ = locations[0]; |
1394 u_texture_location_ = locations[1]; | 1386 u_texture_location_ = locations[1]; |
1395 v_texture_location_ = locations[2]; | 1387 v_texture_location_ = locations[2]; |
1396 a_texture_location_ = locations[3]; | 1388 a_texture_location_ = locations[3]; |
1397 alpha_location_ = locations[4]; | 1389 alpha_location_ = locations[4]; |
1398 yuv_matrix_location_ = locations[5]; | 1390 yuv_matrix_location_ = locations[5]; |
1399 yuv_adj_location_ = locations[6]; | 1391 yuv_adj_location_ = locations[6]; |
1400 } | 1392 } |
1401 | 1393 |
1402 std::string FragmentShaderYUVAVideo::GetShaderString( | 1394 std::string FragmentShaderYUVAVideo::GetShaderString( |
1403 TexCoordPrecision precision) const { | 1395 TexCoordPrecision precision, SamplerType sampler) const { |
1404 return FRAGMENT_SHADER( | 1396 return FRAGMENT_SHADER( |
1405 precision mediump float; | 1397 precision mediump float; |
1406 precision mediump int; | 1398 precision mediump int; |
1407 varying TexCoordPrecision vec2 v_texCoord; | 1399 varying TexCoordPrecision vec2 v_texCoord; |
1408 uniform sampler2D y_texture; | 1400 uniform SamplerType y_texture; |
1409 uniform sampler2D u_texture; | 1401 uniform SamplerType u_texture; |
1410 uniform sampler2D v_texture; | 1402 uniform SamplerType v_texture; |
1411 uniform sampler2D a_texture; | 1403 uniform SamplerType a_texture; |
1412 uniform float alpha; | 1404 uniform float alpha; |
1413 uniform vec3 yuv_adj; | 1405 uniform vec3 yuv_adj; |
1414 uniform mat3 yuv_matrix; | 1406 uniform mat3 yuv_matrix; |
1415 void main() { | 1407 void main() { |
1416 float y_raw = texture2D(y_texture, v_texCoord).x; | 1408 float y_raw = TextureLookup(y_texture, v_texCoord).x; |
1417 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 1409 float u_unsigned = TextureLookup(u_texture, v_texCoord).x; |
1418 float v_unsigned = texture2D(v_texture, v_texCoord).x; | 1410 float v_unsigned = TextureLookup(v_texture, v_texCoord).x; |
1419 float a_raw = texture2D(a_texture, v_texCoord).x; | 1411 float a_raw = TextureLookup(a_texture, v_texCoord).x; |
1420 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 1412 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
1421 vec3 rgb = yuv_matrix * yuv; | 1413 vec3 rgb = yuv_matrix * yuv; |
1422 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); | 1414 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); |
1423 } | 1415 } |
1424 ); // NOLINT(whitespace/parens) | 1416 ); // NOLINT(whitespace/parens) |
1425 } | 1417 } |
1426 | 1418 |
1427 FragmentShaderColor::FragmentShaderColor() | 1419 FragmentShaderColor::FragmentShaderColor() |
1428 : color_location_(-1) {} | 1420 : color_location_(-1) {} |
1429 | 1421 |
1430 void FragmentShaderColor::Init(WebGraphicsContext3D* context, | 1422 void FragmentShaderColor::Init(WebGraphicsContext3D* context, |
1431 unsigned program, | 1423 unsigned program, |
1432 int* base_uniform_index) { | 1424 int* base_uniform_index) { |
1433 static const char* uniforms[] = { | 1425 static const char* uniforms[] = { |
1434 "color", | 1426 "color", |
1435 }; | 1427 }; |
1436 int locations[arraysize(uniforms)]; | 1428 int locations[arraysize(uniforms)]; |
1437 | 1429 |
1438 GetProgramUniformLocations(context, | 1430 GetProgramUniformLocations(context, |
1439 program, | 1431 program, |
1440 arraysize(uniforms), | 1432 arraysize(uniforms), |
1441 uniforms, | 1433 uniforms, |
1442 locations, | 1434 locations, |
1443 base_uniform_index); | 1435 base_uniform_index); |
1444 color_location_ = locations[0]; | 1436 color_location_ = locations[0]; |
1445 } | 1437 } |
1446 | 1438 |
1447 std::string FragmentShaderColor::GetShaderString( | 1439 std::string FragmentShaderColor::GetShaderString( |
1448 TexCoordPrecision precision) const { | 1440 TexCoordPrecision precision, SamplerType sampler) const { |
1449 return FRAGMENT_SHADER( | 1441 return FRAGMENT_SHADER( |
1450 precision mediump float; | 1442 precision mediump float; |
1451 uniform vec4 color; | 1443 uniform vec4 color; |
1452 void main() { | 1444 void main() { |
1453 gl_FragColor = color; | 1445 gl_FragColor = color; |
1454 } | 1446 } |
1455 ); // NOLINT(whitespace/parens) | 1447 ); // NOLINT(whitespace/parens) |
1456 } | 1448 } |
1457 | 1449 |
1458 FragmentShaderColorAA::FragmentShaderColorAA() | 1450 FragmentShaderColorAA::FragmentShaderColorAA() |
(...skipping 10 matching lines...) Expand all Loading... |
1469 GetProgramUniformLocations(context, | 1461 GetProgramUniformLocations(context, |
1470 program, | 1462 program, |
1471 arraysize(uniforms), | 1463 arraysize(uniforms), |
1472 uniforms, | 1464 uniforms, |
1473 locations, | 1465 locations, |
1474 base_uniform_index); | 1466 base_uniform_index); |
1475 color_location_ = locations[0]; | 1467 color_location_ = locations[0]; |
1476 } | 1468 } |
1477 | 1469 |
1478 std::string FragmentShaderColorAA::GetShaderString( | 1470 std::string FragmentShaderColorAA::GetShaderString( |
1479 TexCoordPrecision precision) const { | 1471 TexCoordPrecision precision, SamplerType sampler) const { |
1480 return FRAGMENT_SHADER( | 1472 return FRAGMENT_SHADER( |
1481 precision mediump float; | 1473 precision mediump float; |
1482 uniform vec4 color; | 1474 uniform vec4 color; |
1483 varying vec4 edge_dist[2]; // 8 edge distances. | 1475 varying vec4 edge_dist[2]; // 8 edge distances. |
1484 | 1476 |
1485 void main() { | 1477 void main() { |
1486 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1478 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1487 vec2 d2 = min(d4.xz, d4.yw); | 1479 vec2 d2 = min(d4.xz, d4.yw); |
1488 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1480 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1489 gl_FragColor = color * aa; | 1481 gl_FragColor = color * aa; |
(...skipping 23 matching lines...) Expand all Loading... |
1513 uniforms, | 1505 uniforms, |
1514 locations, | 1506 locations, |
1515 base_uniform_index); | 1507 base_uniform_index); |
1516 alpha_location_ = locations[0]; | 1508 alpha_location_ = locations[0]; |
1517 tex_transform_location_ = locations[1]; | 1509 tex_transform_location_ = locations[1]; |
1518 frequency_location_ = locations[2]; | 1510 frequency_location_ = locations[2]; |
1519 color_location_ = locations[3]; | 1511 color_location_ = locations[3]; |
1520 } | 1512 } |
1521 | 1513 |
1522 std::string FragmentShaderCheckerboard::GetShaderString( | 1514 std::string FragmentShaderCheckerboard::GetShaderString( |
1523 TexCoordPrecision precision) const { | 1515 TexCoordPrecision precision, SamplerType sampler) const { |
1524 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" | 1516 // Shader based on Example 13-17 of "OpenGL ES 2.0 Programming Guide" |
1525 // by Munshi, Ginsburg, Shreiner. | 1517 // by Munshi, Ginsburg, Shreiner. |
1526 return FRAGMENT_SHADER( | 1518 return FRAGMENT_SHADER( |
1527 precision mediump float; | 1519 precision mediump float; |
1528 precision mediump int; | 1520 precision mediump int; |
1529 varying vec2 v_texCoord; | 1521 varying vec2 v_texCoord; |
1530 uniform float alpha; | 1522 uniform float alpha; |
1531 uniform float frequency; | 1523 uniform float frequency; |
1532 uniform vec4 texTransform; | 1524 uniform vec4 texTransform; |
1533 uniform vec4 color; | 1525 uniform vec4 color; |
1534 void main() { | 1526 void main() { |
1535 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); | 1527 vec4 color1 = vec4(1.0, 1.0, 1.0, 1.0); |
1536 vec4 color2 = color; | 1528 vec4 color2 = color; |
1537 vec2 texCoord = | 1529 vec2 texCoord = |
1538 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 1530 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
1539 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1531 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1540 float picker = abs(coord.x - coord.y); // NOLINT | 1532 float picker = abs(coord.x - coord.y); // NOLINT |
1541 gl_FragColor = mix(color1, color2, picker) * alpha; | 1533 gl_FragColor = mix(color1, color2, picker) * alpha; |
1542 } | 1534 } |
1543 ); // NOLINT(whitespace/parens) | 1535 ); // NOLINT(whitespace/parens) |
1544 } | 1536 } |
1545 | 1537 |
1546 } // namespace cc | 1538 } // namespace cc |
OLD | NEW |