| 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 #define SHADER0(Src) #Src |
| 15 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) | 15 #define VERTEX_SHADER(Src) SetVertexTexCoordPrecision(SHADER0(Src)) |
| 16 #define FRAGMENT_SHADER(Src) SetFragmentTexCoordPrecision( \ | 16 #define FRAGMENT_SHADER(Src) \ |
| 17 precision, SetFragmentSamplerType(sampler, SHADER0(Src))) | 17 SetFragmentTexCoordPrecision( \ |
| 18 precision, \ |
| 19 SetFragmentSamplerType(sampler, SetBlendModeFunctions(SHADER0(Src)))) |
| 18 | 20 |
| 19 using gpu::gles2::GLES2Interface; | 21 using gpu::gles2::GLES2Interface; |
| 20 | 22 |
| 21 namespace cc { | 23 namespace cc { |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 static void GetProgramUniformLocations(GLES2Interface* context, | 27 static void GetProgramUniformLocations(GLES2Interface* context, |
| 26 unsigned program, | 28 unsigned program, |
| 27 size_t count, | 29 size_t count, |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 uniform TexCoordPrecision mat4 texMatrix; | 621 uniform TexCoordPrecision mat4 texMatrix; |
| 620 varying TexCoordPrecision vec2 v_texCoord; | 622 varying TexCoordPrecision vec2 v_texCoord; |
| 621 void main() { | 623 void main() { |
| 622 gl_Position = matrix * a_position; | 624 gl_Position = matrix * a_position; |
| 623 v_texCoord = | 625 v_texCoord = |
| 624 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 626 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
| 625 } | 627 } |
| 626 ); // NOLINT(whitespace/parens) | 628 ); // NOLINT(whitespace/parens) |
| 627 } | 629 } |
| 628 | 630 |
| 631 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" |
| 632 #define UNUSED_BLEND_MODE_UNIFORMS (is_default_blend_mode() ? 2 : 0) |
| 633 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ |
| 634 if (!is_default_blend_mode()) { \ |
| 635 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ |
| 636 backdrop_location_ = locations[POS]; \ |
| 637 backdrop_rect_location_ = locations[POS + 1]; \ |
| 638 } |
| 639 |
| 640 FragmentTexBlendMode::FragmentTexBlendMode() |
| 641 : backdrop_location_(-1), |
| 642 backdrop_rect_location_(-1), |
| 643 blend_mode_(SkXfermode::kSrcOver_Mode) { |
| 644 } |
| 645 |
| 646 bool FragmentTexBlendMode::is_blend_mode_supported( |
| 647 SkXfermode::Mode blend_mode) { |
| 648 return blend_mode == kDefaultBlendMode || |
| 649 (blend_mode >= kFirstBlendMode && blend_mode <= kLastBlendMode && |
| 650 blend_mode != SkXfermode::kScreen_Mode); |
| 651 } |
| 652 |
| 653 void FragmentTexBlendMode::SetBlendMode(SkXfermode::Mode blend_mode) { |
| 654 DCHECK(is_blend_mode_supported(blend_mode)); |
| 655 if (!is_blend_mode_supported(blend_mode)) |
| 656 blend_mode_ = kDefaultBlendMode; |
| 657 else |
| 658 blend_mode_ = blend_mode; |
| 659 } |
| 660 |
| 661 std::string FragmentTexBlendMode::SetBlendModeFunctions( |
| 662 std::string shader_string) const { |
| 663 DCHECK(is_blend_mode_supported(blend_mode_)); |
| 664 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
| 665 return shader_string; |
| 666 |
| 667 if (is_default_blend_mode()) { |
| 668 return |
| 669 "#define ApplyBlendMode(X) (X)\n" + |
| 670 shader_string; |
| 671 } |
| 672 |
| 673 return SHADER0(precision mediump float;) |
| 674 + GetHelperFunctions() + |
| 675 SHADER0( |
| 676 uniform SamplerType s_backdropTexture; |
| 677 uniform TexCoordPrecision vec4 backdropRect; |
| 678 |
| 679 vec4 GetBackdropColor() { |
| 680 TexCoordPrecision vec2 bgTexCoord = |
| 681 gl_FragCoord.xy - backdropRect.xy; |
| 682 bgTexCoord.x /= backdropRect.z; |
| 683 bgTexCoord.y /= backdropRect.w; |
| 684 return TextureLookup(s_backdropTexture, bgTexCoord); |
| 685 } |
| 686 |
| 687 vec4 ApplyBlendMode(vec4 src) { |
| 688 vec4 dst = GetBackdropColor(); |
| 689 vec4 result; |
| 690 result.a = src.a + (1.0 - src.a) * dst.a;) |
| 691 |
| 692 + GetMainBlendingCode() + SHADER0( |
| 693 return result; |
| 694 }) |
| 695 + shader_string; |
| 696 } |
| 697 |
| 698 std::string FragmentTexBlendMode::GetHelperFunctions() const { |
| 699 static const std::string kFunctionHardLight = SHADER0( |
| 700 vec3 hardLight(vec4 src, vec4 dst) { |
| 701 vec3 result; |
| 702 result.r = (2.0 * src.r <= src.a) |
| 703 ? (2.0 * src.r * dst.r) |
| 704 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); |
| 705 result.g = (2.0 * src.g <= src.a) |
| 706 ? (2.0 * src.g * dst.g) |
| 707 : (src.a * dst.a - 2.0 * (dst.a - dst.g) * (src.a - src.g)); |
| 708 result.b = (2.0 * src.b <= src.a) |
| 709 ? (2.0 * src.b * dst.b) |
| 710 : (src.a * dst.a - 2.0 * (dst.a - dst.b) * (src.a - src.b)); |
| 711 result.rgb += src.rgb * (1.0 - dst.a) + dst.rgb * (1.0 - src.a); |
| 712 return result; |
| 713 } |
| 714 ); |
| 715 |
| 716 static const std::string kFunctionColorDodgeComponent = SHADER0( |
| 717 float getColorDodgeComponent(float srcc, float srca, |
| 718 float dstc, float dsta) { |
| 719 if (0.0 == dstc) |
| 720 return srcc * (1.0 - dsta); |
| 721 float d = srca - srcc; |
| 722 if (0.0 == d) |
| 723 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 724 d = min(dsta, dstc * srca / d); |
| 725 return d * srca + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 726 } |
| 727 ); |
| 728 |
| 729 static const std::string kFunctionColorBurnComponent = SHADER0( |
| 730 float getColorBurnComponent(float srcc, float srca, |
| 731 float dstc, float dsta) { |
| 732 if (dsta == dstc) |
| 733 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 734 if (0.0 == srcc) |
| 735 return dstc * (1.0 - srca); |
| 736 float d = max(0.0, dsta - (dsta - dstc) * srca / srcc); |
| 737 return srca * d + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 738 } |
| 739 ); |
| 740 |
| 741 static const std::string kFunctionSoftLightComponentPosDstAlpha = SHADER0( |
| 742 float getSoftLightComponent(float srcc, float srca, |
| 743 float dstc, float dsta) { |
| 744 if (2.0 * srcc <= srca) { |
| 745 return (dstc * dstc * (srca - 2.0 * srcc)) / dsta + |
| 746 (1.0 - dsta) * srcc + dstc * (-srca + 2.0 * srcc + 1.0); |
| 747 } else if (4.0 * dstc <= dsta) { |
| 748 float DSqd = dstc * dstc; |
| 749 float DCub = DSqd * dstc; |
| 750 float DaSqd = dsta * dsta; |
| 751 float DaCub = DaSqd * dsta; |
| 752 return (-DaCub * srcc + |
| 753 DaSqd * (srcc - dstc * (3.0 * srca - 6.0 * srcc - 1.0)) + |
| 754 12.0 * dsta * DSqd * (srca - 2.0 * srcc) - |
| 755 16.0 * DCub * (srca - 2.0 * srcc)) / |
| 756 DaSqd; |
| 757 } else { |
| 758 return -sqrt(dsta * dstc) * (srca - 2.0 * srcc) - dsta * srcc + |
| 759 dstc * (srca - 2.0 * srcc + 1.0) + srcc; |
| 760 } |
| 761 } |
| 762 ); |
| 763 |
| 764 static const std::string kFunctionLum = SHADER0( |
| 765 float luminance(vec3 color) { |
| 766 return dot(vec3(0.3, 0.59, 0.11), color); |
| 767 } |
| 768 vec3 set_luminance(vec3 hueSat, float alpha, vec3 lumColor) { |
| 769 float diff = luminance(lumColor - hueSat); |
| 770 vec3 outColor = hueSat + diff; |
| 771 float outLum = luminance(outColor); |
| 772 float minComp = min(min(outColor.r, outColor.g), outColor.b); |
| 773 float maxComp = max(max(outColor.r, outColor.g), outColor.b); |
| 774 if (minComp < 0.0) { |
| 775 outColor = outLum + |
| 776 ((outColor - vec3(outLum, outLum, outLum)) * outLum) / |
| 777 (outLum - minComp); |
| 778 } |
| 779 if (maxComp > alpha) { |
| 780 outColor = |
| 781 outLum + |
| 782 ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / |
| 783 (maxComp - outLum); |
| 784 } |
| 785 return outColor; |
| 786 } |
| 787 ); |
| 788 |
| 789 static const std::string kFunctionSat = SHADER0( |
| 790 float saturation(vec3 color) { |
| 791 return max(max(color.r, color.g), color.b) - |
| 792 min(min(color.r, color.g), color.b); |
| 793 } |
| 794 vec3 set_saturation_helper(float minComp, |
| 795 float midComp, |
| 796 float maxComp, |
| 797 float sat) { |
| 798 if (minComp < maxComp) { |
| 799 vec3 result; |
| 800 result.r = 0.0; |
| 801 result.g = sat * (midComp - minComp) / (maxComp - minComp); |
| 802 result.b = sat; |
| 803 return result; |
| 804 } else { |
| 805 return vec3(0, 0, 0); |
| 806 } |
| 807 } |
| 808 vec3 set_saturation(vec3 hueLumColor, vec3 satColor) { |
| 809 float sat = saturation(satColor); |
| 810 if (hueLumColor.r <= hueLumColor.g) { |
| 811 if (hueLumColor.g <= hueLumColor.b) { |
| 812 hueLumColor.rgb = set_saturation_helper( |
| 813 hueLumColor.r, hueLumColor.g, hueLumColor.b, sat); |
| 814 } else if (hueLumColor.r <= hueLumColor.b) { |
| 815 hueLumColor.rbg = set_saturation_helper( |
| 816 hueLumColor.r, hueLumColor.b, hueLumColor.g, sat); |
| 817 } else { |
| 818 hueLumColor.brg = set_saturation_helper( |
| 819 hueLumColor.b, hueLumColor.r, hueLumColor.g, sat); |
| 820 } |
| 821 } else if (hueLumColor.r <= hueLumColor.b) { |
| 822 hueLumColor.grb = set_saturation_helper( |
| 823 hueLumColor.g, hueLumColor.r, hueLumColor.b, sat); |
| 824 } else if (hueLumColor.g <= hueLumColor.b) { |
| 825 hueLumColor.gbr = set_saturation_helper( |
| 826 hueLumColor.g, hueLumColor.b, hueLumColor.r, sat); |
| 827 } else { |
| 828 hueLumColor.bgr = set_saturation_helper( |
| 829 hueLumColor.b, hueLumColor.g, hueLumColor.r, sat); |
| 830 } |
| 831 return hueLumColor; |
| 832 } |
| 833 ); |
| 834 |
| 835 switch (blend_mode_) { |
| 836 case SkXfermode::kOverlay_Mode: |
| 837 case SkXfermode::kHardLight_Mode: |
| 838 return kFunctionHardLight; |
| 839 case SkXfermode::kColorDodge_Mode: |
| 840 return kFunctionColorDodgeComponent; |
| 841 case SkXfermode::kColorBurn_Mode: |
| 842 return kFunctionColorBurnComponent; |
| 843 case SkXfermode::kSoftLight_Mode: |
| 844 return kFunctionSoftLightComponentPosDstAlpha; |
| 845 case SkXfermode::kHue_Mode: |
| 846 case SkXfermode::kSaturation_Mode: |
| 847 return kFunctionLum + kFunctionSat; |
| 848 case SkXfermode::kColor_Mode: |
| 849 case SkXfermode::kLuminosity_Mode: |
| 850 return kFunctionLum; |
| 851 default: |
| 852 return std::string(); |
| 853 } |
| 854 } |
| 855 |
| 856 std::string FragmentTexBlendMode::GetMainBlendingCode() const { |
| 857 switch (blend_mode_) { |
| 858 case SkXfermode::kLighten_Mode: |
| 859 return SHADER0( |
| 860 result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb, |
| 861 (1.0 - dst.a) * src.rgb + dst.rgb); |
| 862 ); |
| 863 case SkXfermode::kOverlay_Mode: |
| 864 return SHADER0( |
| 865 result.rgb = hardLight(dst, src); |
| 866 ); |
| 867 case SkXfermode::kDarken_Mode: |
| 868 return SHADER0( |
| 869 result.rgb = min((1.0 - src.a) * dst.rgb + src.rgb, |
| 870 (1.0 - dst.a) * src.rgb + dst.rgb); |
| 871 ); |
| 872 case SkXfermode::kColorDodge_Mode: |
| 873 return SHADER0( |
| 874 result.r = getColorDodgeComponent(src.r, src.a, dst.r, dst.a); |
| 875 result.g = getColorDodgeComponent(src.g, src.a, dst.g, dst.a); |
| 876 result.b = getColorDodgeComponent(src.b, src.a, dst.b, dst.a); |
| 877 ); |
| 878 case SkXfermode::kColorBurn_Mode: |
| 879 return SHADER0( |
| 880 result.r = getColorBurnComponent(src.r, src.a, dst.r, dst.a); |
| 881 result.g = getColorBurnComponent(src.g, src.a, dst.g, dst.a); |
| 882 result.b = getColorBurnComponent(src.b, src.a, dst.b, dst.a); |
| 883 ); |
| 884 case SkXfermode::kHardLight_Mode: |
| 885 return SHADER0( |
| 886 result.rgb = hardLight(src, dst); |
| 887 ); |
| 888 case SkXfermode::kSoftLight_Mode: |
| 889 return SHADER0( |
| 890 if (0.0 == dst.a) { |
| 891 result.rgba = src; |
| 892 } else { |
| 893 result.r = getSoftLightComponent(src.r, src.a, dst.r, dst.a); |
| 894 result.g = getSoftLightComponent(src.g, src.a, dst.g, dst.a); |
| 895 result.b = getSoftLightComponent(src.b, src.a, dst.b, dst.a); |
| 896 } |
| 897 ); |
| 898 case SkXfermode::kDifference_Mode: |
| 899 return SHADER0( |
| 900 result.rgb = src.rgb + dst.rgb - |
| 901 2.0 * min(src.rgb * dst.a, dst.rgb * src.a); |
| 902 ); |
| 903 case SkXfermode::kExclusion_Mode: |
| 904 return SHADER0( |
| 905 result.rgb = dst.rgb + src.rgb - 2.0 * dst.rgb * src.rgb; |
| 906 ); |
| 907 case SkXfermode::kMultiply_Mode: |
| 908 return SHADER0( |
| 909 result.rgb = (1.0 - src.a) * dst.rgb + |
| 910 (1.0 - dst.a) * src.rgb + src.rgb * dst.rgb; |
| 911 ); |
| 912 case SkXfermode::kHue_Mode: |
| 913 return SHADER0( |
| 914 vec4 dstSrcAlpha = dst * src.a; |
| 915 result.rgb = |
| 916 set_luminance(set_saturation(src.rgb * dst.a, dstSrcAlpha.rgb), |
| 917 dstSrcAlpha.a, |
| 918 dstSrcAlpha.rgb); |
| 919 |
| 920 result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb; |
| 921 ); |
| 922 case SkXfermode::kSaturation_Mode: |
| 923 return SHADER0( |
| 924 vec4 dstSrcAlpha = dst * src.a; |
| 925 result.rgb = |
| 926 set_luminance(set_saturation(dstSrcAlpha.rgb, src.rgb * dst.a), |
| 927 dstSrcAlpha.a, |
| 928 dstSrcAlpha.rgb); |
| 929 result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb; |
| 930 ); |
| 931 case SkXfermode::kColor_Mode: |
| 932 return SHADER0( |
| 933 vec4 srcDstAlpha = src * dst.a; |
| 934 result.rgb = |
| 935 set_luminance(srcDstAlpha.rgb, srcDstAlpha.a, dst.rgb * src.a); |
| 936 result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb; |
| 937 ); |
| 938 case SkXfermode::kLuminosity_Mode: |
| 939 return SHADER0( |
| 940 vec4 srcDstAlpha = src * dst.a; |
| 941 result.rgb = |
| 942 set_luminance(dst.rgb * src.a, srcDstAlpha.a, srcDstAlpha.rgb); |
| 943 result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb; |
| 944 ); |
| 945 default: |
| 946 NOTREACHED(); |
| 947 } |
| 948 |
| 949 return SHADER0( |
| 950 result = src; |
| 951 ); |
| 952 } |
| 953 |
| 629 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 954 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
| 630 : sampler_location_(-1), | 955 : sampler_location_(-1), |
| 631 alpha_location_(-1) {} | 956 alpha_location_(-1) {} |
| 632 | 957 |
| 633 void FragmentTexAlphaBinding::Init(GLES2Interface* context, | 958 void FragmentTexAlphaBinding::Init(GLES2Interface* context, |
| 634 unsigned program, | 959 unsigned program, |
| 635 int* base_uniform_index) { | 960 int* base_uniform_index) { |
| 636 static const char* uniforms[] = { | 961 static const char* uniforms[] = { |
| 637 "s_texture", | 962 "s_texture", |
| 638 "alpha", | 963 "alpha", |
| 964 BLEND_MODE_UNIFORMS, |
| 639 }; | 965 }; |
| 640 int locations[arraysize(uniforms)]; | 966 int locations[arraysize(uniforms)]; |
| 641 | 967 |
| 642 GetProgramUniformLocations(context, | 968 GetProgramUniformLocations(context, |
| 643 program, | 969 program, |
| 644 arraysize(uniforms), | 970 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
| 645 uniforms, | 971 uniforms, |
| 646 locations, | 972 locations, |
| 647 base_uniform_index); | 973 base_uniform_index); |
| 648 sampler_location_ = locations[0]; | 974 sampler_location_ = locations[0]; |
| 649 alpha_location_ = locations[1]; | 975 alpha_location_ = locations[1]; |
| 976 BLEND_MODE_SET_LOCATIONS(locations, 2); |
| 650 } | 977 } |
| 651 | 978 |
| 652 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding() | 979 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding() |
| 653 : sampler_location_(-1), | 980 : sampler_location_(-1), |
| 654 alpha_location_(-1), | 981 alpha_location_(-1), |
| 655 color_matrix_location_(-1), | 982 color_matrix_location_(-1), |
| 656 color_offset_location_(-1) {} | 983 color_offset_location_(-1) {} |
| 657 | 984 |
| 658 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context, | 985 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context, |
| 659 unsigned program, | 986 unsigned program, |
| 660 int* base_uniform_index) { | 987 int* base_uniform_index) { |
| 661 static const char* uniforms[] = { | 988 static const char* uniforms[] = { |
| 662 "s_texture", | 989 "s_texture", |
| 663 "alpha", | 990 "alpha", |
| 664 "colorMatrix", | 991 "colorMatrix", |
| 665 "colorOffset", | 992 "colorOffset", |
| 993 BLEND_MODE_UNIFORMS, |
| 666 }; | 994 }; |
| 667 int locations[arraysize(uniforms)]; | 995 int locations[arraysize(uniforms)]; |
| 668 | 996 |
| 669 GetProgramUniformLocations(context, | 997 GetProgramUniformLocations(context, |
| 670 program, | 998 program, |
| 671 arraysize(uniforms), | 999 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
| 672 uniforms, | 1000 uniforms, |
| 673 locations, | 1001 locations, |
| 674 base_uniform_index); | 1002 base_uniform_index); |
| 675 sampler_location_ = locations[0]; | 1003 sampler_location_ = locations[0]; |
| 676 alpha_location_ = locations[1]; | 1004 alpha_location_ = locations[1]; |
| 677 color_matrix_location_ = locations[2]; | 1005 color_matrix_location_ = locations[2]; |
| 678 color_offset_location_ = locations[3]; | 1006 color_offset_location_ = locations[3]; |
| 1007 BLEND_MODE_SET_LOCATIONS(locations, 4); |
| 679 } | 1008 } |
| 680 | 1009 |
| 681 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() | 1010 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() |
| 682 : sampler_location_(-1) {} | 1011 : sampler_location_(-1) {} |
| 683 | 1012 |
| 684 void FragmentTexOpaqueBinding::Init(GLES2Interface* context, | 1013 void FragmentTexOpaqueBinding::Init(GLES2Interface* context, |
| 685 unsigned program, | 1014 unsigned program, |
| 686 int* base_uniform_index) { | 1015 int* base_uniform_index) { |
| 687 static const char* uniforms[] = { | 1016 static const char* uniforms[] = { |
| 688 "s_texture", | 1017 "s_texture", |
| (...skipping 11 matching lines...) Expand all Loading... |
| 700 | 1029 |
| 701 std::string FragmentShaderRGBATexAlpha::GetShaderString( | 1030 std::string FragmentShaderRGBATexAlpha::GetShaderString( |
| 702 TexCoordPrecision precision, SamplerType sampler) const { | 1031 TexCoordPrecision precision, SamplerType sampler) const { |
| 703 return FRAGMENT_SHADER( | 1032 return FRAGMENT_SHADER( |
| 704 precision mediump float; | 1033 precision mediump float; |
| 705 varying TexCoordPrecision vec2 v_texCoord; | 1034 varying TexCoordPrecision vec2 v_texCoord; |
| 706 uniform SamplerType s_texture; | 1035 uniform SamplerType s_texture; |
| 707 uniform float alpha; | 1036 uniform float alpha; |
| 708 void main() { | 1037 void main() { |
| 709 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1038 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 710 gl_FragColor = texColor * alpha; | 1039 gl_FragColor = ApplyBlendMode(texColor * alpha); |
| 711 } | 1040 } |
| 712 ); // NOLINT(whitespace/parens) | 1041 ); // NOLINT(whitespace/parens) |
| 713 } | 1042 } |
| 714 | 1043 |
| 715 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( | 1044 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( |
| 716 TexCoordPrecision precision, SamplerType sampler) const { | 1045 TexCoordPrecision precision, SamplerType sampler) const { |
| 717 return FRAGMENT_SHADER( | 1046 return FRAGMENT_SHADER( |
| 718 precision mediump float; | 1047 precision mediump float; |
| 719 varying TexCoordPrecision vec2 v_texCoord; | 1048 varying TexCoordPrecision vec2 v_texCoord; |
| 720 uniform SamplerType s_texture; | 1049 uniform SamplerType s_texture; |
| 721 uniform float alpha; | 1050 uniform float alpha; |
| 722 uniform mat4 colorMatrix; | 1051 uniform mat4 colorMatrix; |
| 723 uniform vec4 colorOffset; | 1052 uniform vec4 colorOffset; |
| 724 void main() { | 1053 void main() { |
| 725 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1054 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 726 float nonZeroAlpha = max(texColor.a, 0.00001); | 1055 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 727 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1056 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 728 texColor = colorMatrix * texColor + colorOffset; | 1057 texColor = colorMatrix * texColor + colorOffset; |
| 729 texColor.rgb *= texColor.a; | 1058 texColor.rgb *= texColor.a; |
| 730 texColor = clamp(texColor, 0.0, 1.0); | 1059 texColor = clamp(texColor, 0.0, 1.0); |
| 731 gl_FragColor = texColor * alpha; | 1060 gl_FragColor = ApplyBlendMode(texColor * alpha); |
| 732 } | 1061 } |
| 733 ); // NOLINT(whitespace/parens) | 1062 ); // NOLINT(whitespace/parens) |
| 734 } | 1063 } |
| 735 | 1064 |
| 736 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 1065 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
| 737 TexCoordPrecision precision, SamplerType sampler) const { | 1066 TexCoordPrecision precision, SamplerType sampler) const { |
| 738 return FRAGMENT_SHADER( | 1067 return FRAGMENT_SHADER( |
| 739 precision mediump float; | 1068 precision mediump float; |
| 740 varying TexCoordPrecision vec2 v_texCoord; | 1069 varying TexCoordPrecision vec2 v_texCoord; |
| 741 varying float v_alpha; | 1070 varying float v_alpha; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 1208 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
| 880 : sampler_location_(-1), | 1209 : sampler_location_(-1), |
| 881 alpha_location_(-1) {} | 1210 alpha_location_(-1) {} |
| 882 | 1211 |
| 883 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, | 1212 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, |
| 884 unsigned program, | 1213 unsigned program, |
| 885 int* base_uniform_index) { | 1214 int* base_uniform_index) { |
| 886 static const char* uniforms[] = { | 1215 static const char* uniforms[] = { |
| 887 "s_texture", | 1216 "s_texture", |
| 888 "alpha", | 1217 "alpha", |
| 1218 BLEND_MODE_UNIFORMS, |
| 889 }; | 1219 }; |
| 890 int locations[arraysize(uniforms)]; | 1220 int locations[arraysize(uniforms)]; |
| 891 | 1221 |
| 892 GetProgramUniformLocations(context, | 1222 GetProgramUniformLocations(context, |
| 893 program, | 1223 program, |
| 894 arraysize(uniforms), | 1224 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
| 895 uniforms, | 1225 uniforms, |
| 896 locations, | 1226 locations, |
| 897 base_uniform_index); | 1227 base_uniform_index); |
| 898 sampler_location_ = locations[0]; | 1228 sampler_location_ = locations[0]; |
| 899 alpha_location_ = locations[1]; | 1229 alpha_location_ = locations[1]; |
| 1230 BLEND_MODE_SET_LOCATIONS(locations, 2); |
| 900 } | 1231 } |
| 901 | 1232 |
| 902 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( | 1233 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( |
| 903 TexCoordPrecision precision, SamplerType sampler) const { | 1234 TexCoordPrecision precision, SamplerType sampler) const { |
| 904 return FRAGMENT_SHADER( | 1235 return FRAGMENT_SHADER( |
| 905 precision mediump float; | 1236 precision mediump float; |
| 906 uniform SamplerType s_texture; | 1237 uniform SamplerType s_texture; |
| 907 uniform float alpha; | 1238 uniform float alpha; |
| 908 varying TexCoordPrecision vec2 v_texCoord; | 1239 varying TexCoordPrecision vec2 v_texCoord; |
| 909 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1240 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
| 910 | 1241 |
| 911 void main() { | 1242 void main() { |
| 912 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1243 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 913 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1244 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 914 vec2 d2 = min(d4.xz, d4.yw); | 1245 vec2 d2 = min(d4.xz, d4.yw); |
| 915 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1246 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 916 gl_FragColor = texColor * alpha * aa; | 1247 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); |
| 917 } | 1248 } |
| 918 ); // NOLINT(whitespace/parens) | 1249 ); // NOLINT(whitespace/parens) |
| 919 } | 1250 } |
| 920 | 1251 |
| 921 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | 1252 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() |
| 922 : sampler_location_(-1), | 1253 : sampler_location_(-1), |
| 923 alpha_location_(-1), | 1254 alpha_location_(-1), |
| 924 fragment_tex_transform_location_(-1) {} | 1255 fragment_tex_transform_location_(-1) {} |
| 925 | 1256 |
| 926 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, | 1257 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 | 1330 |
| 1000 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, | 1331 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, |
| 1001 unsigned program, | 1332 unsigned program, |
| 1002 int* base_uniform_index) { | 1333 int* base_uniform_index) { |
| 1003 static const char* uniforms[] = { | 1334 static const char* uniforms[] = { |
| 1004 "s_texture", | 1335 "s_texture", |
| 1005 "s_mask", | 1336 "s_mask", |
| 1006 "alpha", | 1337 "alpha", |
| 1007 "maskTexCoordScale", | 1338 "maskTexCoordScale", |
| 1008 "maskTexCoordOffset", | 1339 "maskTexCoordOffset", |
| 1340 BLEND_MODE_UNIFORMS, |
| 1009 }; | 1341 }; |
| 1010 int locations[arraysize(uniforms)]; | 1342 int locations[arraysize(uniforms)]; |
| 1011 | 1343 |
| 1012 GetProgramUniformLocations(context, | 1344 GetProgramUniformLocations(context, |
| 1013 program, | 1345 program, |
| 1014 arraysize(uniforms), | 1346 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
| 1015 uniforms, | 1347 uniforms, |
| 1016 locations, | 1348 locations, |
| 1017 base_uniform_index); | 1349 base_uniform_index); |
| 1018 sampler_location_ = locations[0]; | 1350 sampler_location_ = locations[0]; |
| 1019 mask_sampler_location_ = locations[1]; | 1351 mask_sampler_location_ = locations[1]; |
| 1020 alpha_location_ = locations[2]; | 1352 alpha_location_ = locations[2]; |
| 1021 mask_tex_coord_scale_location_ = locations[3]; | 1353 mask_tex_coord_scale_location_ = locations[3]; |
| 1022 mask_tex_coord_offset_location_ = locations[4]; | 1354 mask_tex_coord_offset_location_ = locations[4]; |
| 1355 BLEND_MODE_SET_LOCATIONS(locations, 5); |
| 1023 } | 1356 } |
| 1024 | 1357 |
| 1025 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( | 1358 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( |
| 1026 TexCoordPrecision precision, SamplerType sampler) const { | 1359 TexCoordPrecision precision, SamplerType sampler) const { |
| 1027 return FRAGMENT_SHADER( | 1360 return FRAGMENT_SHADER( |
| 1028 precision mediump float; | 1361 precision mediump float; |
| 1029 varying TexCoordPrecision vec2 v_texCoord; | 1362 varying TexCoordPrecision vec2 v_texCoord; |
| 1030 uniform SamplerType s_texture; | 1363 uniform SamplerType s_texture; |
| 1031 uniform SamplerType s_mask; | 1364 uniform SamplerType s_mask; |
| 1032 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1365 uniform TexCoordPrecision vec2 maskTexCoordScale; |
| 1033 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1366 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
| 1034 uniform float alpha; | 1367 uniform float alpha; |
| 1035 void main() { | 1368 void main() { |
| 1036 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1369 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1037 TexCoordPrecision vec2 maskTexCoord = | 1370 TexCoordPrecision vec2 maskTexCoord = |
| 1038 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1371 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1039 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1372 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1040 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1373 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1041 gl_FragColor = texColor * alpha * maskColor.w; | 1374 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); |
| 1042 } | 1375 } |
| 1043 ); // NOLINT(whitespace/parens) | 1376 ); // NOLINT(whitespace/parens) |
| 1044 } | 1377 } |
| 1045 | 1378 |
| 1046 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 1379 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
| 1047 : sampler_location_(-1), | 1380 : sampler_location_(-1), |
| 1048 mask_sampler_location_(-1), | 1381 mask_sampler_location_(-1), |
| 1049 alpha_location_(-1), | 1382 alpha_location_(-1), |
| 1050 mask_tex_coord_scale_location_(-1), | 1383 mask_tex_coord_scale_location_(-1), |
| 1051 mask_tex_coord_offset_location_(-1) {} | 1384 mask_tex_coord_offset_location_(-1) {} |
| 1052 | 1385 |
| 1053 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, | 1386 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, |
| 1054 unsigned program, | 1387 unsigned program, |
| 1055 int* base_uniform_index) { | 1388 int* base_uniform_index) { |
| 1056 static const char* uniforms[] = { | 1389 static const char* uniforms[] = { |
| 1057 "s_texture", | 1390 "s_texture", |
| 1058 "s_mask", | 1391 "s_mask", |
| 1059 "alpha", | 1392 "alpha", |
| 1060 "maskTexCoordScale", | 1393 "maskTexCoordScale", |
| 1061 "maskTexCoordOffset", | 1394 "maskTexCoordOffset", |
| 1395 BLEND_MODE_UNIFORMS, |
| 1062 }; | 1396 }; |
| 1063 int locations[arraysize(uniforms)]; | 1397 int locations[arraysize(uniforms)]; |
| 1064 | 1398 |
| 1065 GetProgramUniformLocations(context, | 1399 GetProgramUniformLocations(context, |
| 1066 program, | 1400 program, |
| 1067 arraysize(uniforms), | 1401 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
| 1068 uniforms, | 1402 uniforms, |
| 1069 locations, | 1403 locations, |
| 1070 base_uniform_index); | 1404 base_uniform_index); |
| 1071 sampler_location_ = locations[0]; | 1405 sampler_location_ = locations[0]; |
| 1072 mask_sampler_location_ = locations[1]; | 1406 mask_sampler_location_ = locations[1]; |
| 1073 alpha_location_ = locations[2]; | 1407 alpha_location_ = locations[2]; |
| 1074 mask_tex_coord_scale_location_ = locations[3]; | 1408 mask_tex_coord_scale_location_ = locations[3]; |
| 1075 mask_tex_coord_offset_location_ = locations[4]; | 1409 mask_tex_coord_offset_location_ = locations[4]; |
| 1410 BLEND_MODE_SET_LOCATIONS(locations, 5); |
| 1076 } | 1411 } |
| 1077 | 1412 |
| 1078 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( | 1413 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( |
| 1079 TexCoordPrecision precision, SamplerType sampler) const { | 1414 TexCoordPrecision precision, SamplerType sampler) const { |
| 1080 return FRAGMENT_SHADER( | 1415 return FRAGMENT_SHADER( |
| 1081 precision mediump float; | 1416 precision mediump float; |
| 1082 uniform SamplerType s_texture; | 1417 uniform SamplerType s_texture; |
| 1083 uniform SamplerType s_mask; | 1418 uniform SamplerType s_mask; |
| 1084 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1419 uniform TexCoordPrecision vec2 maskTexCoordScale; |
| 1085 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1420 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
| 1086 uniform float alpha; | 1421 uniform float alpha; |
| 1087 varying TexCoordPrecision vec2 v_texCoord; | 1422 varying TexCoordPrecision vec2 v_texCoord; |
| 1088 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1423 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
| 1089 | 1424 |
| 1090 void main() { | 1425 void main() { |
| 1091 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1426 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1092 TexCoordPrecision vec2 maskTexCoord = | 1427 TexCoordPrecision vec2 maskTexCoord = |
| 1093 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1428 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1094 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1429 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1095 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1430 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1096 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1431 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1097 vec2 d2 = min(d4.xz, d4.yw); | 1432 vec2 d2 = min(d4.xz, d4.yw); |
| 1098 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1433 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1099 gl_FragColor = texColor * alpha * maskColor.w * aa; | 1434 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); |
| 1100 } | 1435 } |
| 1101 ); // NOLINT(whitespace/parens) | 1436 ); // NOLINT(whitespace/parens) |
| 1102 } | 1437 } |
| 1103 | 1438 |
| 1104 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: | 1439 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: |
| 1105 FragmentShaderRGBATexAlphaMaskColorMatrixAA() | 1440 FragmentShaderRGBATexAlphaMaskColorMatrixAA() |
| 1106 : sampler_location_(-1), | 1441 : sampler_location_(-1), |
| 1107 mask_sampler_location_(-1), | 1442 mask_sampler_location_(-1), |
| 1108 alpha_location_(-1), | 1443 alpha_location_(-1), |
| 1109 mask_tex_coord_scale_location_(-1), | 1444 mask_tex_coord_scale_location_(-1), |
| 1110 color_matrix_location_(-1), | 1445 color_matrix_location_(-1), |
| 1111 color_offset_location_(-1) {} | 1446 color_offset_location_(-1) {} |
| 1112 | 1447 |
| 1113 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init( | 1448 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init( |
| 1114 GLES2Interface* context, | 1449 GLES2Interface* context, |
| 1115 unsigned program, | 1450 unsigned program, |
| 1116 int* base_uniform_index) { | 1451 int* base_uniform_index) { |
| 1117 static const char* uniforms[] = { | 1452 static const char* uniforms[] = { |
| 1118 "s_texture", | 1453 "s_texture", |
| 1119 "s_mask", | 1454 "s_mask", |
| 1120 "alpha", | 1455 "alpha", |
| 1121 "maskTexCoordScale", | 1456 "maskTexCoordScale", |
| 1122 "maskTexCoordOffset", | 1457 "maskTexCoordOffset", |
| 1123 "colorMatrix", | 1458 "colorMatrix", |
| 1124 "colorOffset", | 1459 "colorOffset", |
| 1460 BLEND_MODE_UNIFORMS, |
| 1125 }; | 1461 }; |
| 1126 int locations[arraysize(uniforms)]; | 1462 int locations[arraysize(uniforms)]; |
| 1127 | 1463 |
| 1128 GetProgramUniformLocations(context, | 1464 GetProgramUniformLocations(context, |
| 1129 program, | 1465 program, |
| 1130 arraysize(uniforms), | 1466 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
| 1131 uniforms, | 1467 uniforms, |
| 1132 locations, | 1468 locations, |
| 1133 base_uniform_index); | 1469 base_uniform_index); |
| 1134 sampler_location_ = locations[0]; | 1470 sampler_location_ = locations[0]; |
| 1135 mask_sampler_location_ = locations[1]; | 1471 mask_sampler_location_ = locations[1]; |
| 1136 alpha_location_ = locations[2]; | 1472 alpha_location_ = locations[2]; |
| 1137 mask_tex_coord_scale_location_ = locations[3]; | 1473 mask_tex_coord_scale_location_ = locations[3]; |
| 1138 mask_tex_coord_offset_location_ = locations[4]; | 1474 mask_tex_coord_offset_location_ = locations[4]; |
| 1139 color_matrix_location_ = locations[5]; | 1475 color_matrix_location_ = locations[5]; |
| 1140 color_offset_location_ = locations[6]; | 1476 color_offset_location_ = locations[6]; |
| 1477 BLEND_MODE_SET_LOCATIONS(locations, 7); |
| 1141 } | 1478 } |
| 1142 | 1479 |
| 1143 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( | 1480 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( |
| 1144 TexCoordPrecision precision, SamplerType sampler) const { | 1481 TexCoordPrecision precision, SamplerType sampler) const { |
| 1145 return FRAGMENT_SHADER( | 1482 return FRAGMENT_SHADER( |
| 1146 precision mediump float; | 1483 precision mediump float; |
| 1147 uniform SamplerType s_texture; | 1484 uniform SamplerType s_texture; |
| 1148 uniform SamplerType s_mask; | 1485 uniform SamplerType s_mask; |
| 1149 uniform vec2 maskTexCoordScale; | 1486 uniform vec2 maskTexCoordScale; |
| 1150 uniform vec2 maskTexCoordOffset; | 1487 uniform vec2 maskTexCoordOffset; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1161 texColor = colorMatrix * texColor + colorOffset; | 1498 texColor = colorMatrix * texColor + colorOffset; |
| 1162 texColor.rgb *= texColor.a; | 1499 texColor.rgb *= texColor.a; |
| 1163 texColor = clamp(texColor, 0.0, 1.0); | 1500 texColor = clamp(texColor, 0.0, 1.0); |
| 1164 TexCoordPrecision vec2 maskTexCoord = | 1501 TexCoordPrecision vec2 maskTexCoord = |
| 1165 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1502 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1166 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1503 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1167 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1504 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1168 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1505 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1169 vec2 d2 = min(d4.xz, d4.yw); | 1506 vec2 d2 = min(d4.xz, d4.yw); |
| 1170 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1507 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1171 gl_FragColor = texColor * alpha * maskColor.w * aa; | 1508 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); |
| 1172 } | 1509 } |
| 1173 ); // NOLINT(whitespace/parens) | 1510 ); // NOLINT(whitespace/parens) |
| 1174 } | 1511 } |
| 1175 | 1512 |
| 1176 FragmentShaderRGBATexAlphaColorMatrixAA:: | 1513 FragmentShaderRGBATexAlphaColorMatrixAA:: |
| 1177 FragmentShaderRGBATexAlphaColorMatrixAA() | 1514 FragmentShaderRGBATexAlphaColorMatrixAA() |
| 1178 : sampler_location_(-1), | 1515 : sampler_location_(-1), |
| 1179 alpha_location_(-1), | 1516 alpha_location_(-1), |
| 1180 color_matrix_location_(-1), | 1517 color_matrix_location_(-1), |
| 1181 color_offset_location_(-1) {} | 1518 color_offset_location_(-1) {} |
| 1182 | 1519 |
| 1183 void FragmentShaderRGBATexAlphaColorMatrixAA::Init( | 1520 void FragmentShaderRGBATexAlphaColorMatrixAA::Init( |
| 1184 GLES2Interface* context, | 1521 GLES2Interface* context, |
| 1185 unsigned program, | 1522 unsigned program, |
| 1186 int* base_uniform_index) { | 1523 int* base_uniform_index) { |
| 1187 static const char* uniforms[] = { | 1524 static const char* uniforms[] = { |
| 1188 "s_texture", | 1525 "s_texture", |
| 1189 "alpha", | 1526 "alpha", |
| 1190 "colorMatrix", | 1527 "colorMatrix", |
| 1191 "colorOffset", | 1528 "colorOffset", |
| 1529 BLEND_MODE_UNIFORMS, |
| 1192 }; | 1530 }; |
| 1193 int locations[arraysize(uniforms)]; | 1531 int locations[arraysize(uniforms)]; |
| 1194 | 1532 |
| 1195 GetProgramUniformLocations(context, | 1533 GetProgramUniformLocations(context, |
| 1196 program, | 1534 program, |
| 1197 arraysize(uniforms), | 1535 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
| 1198 uniforms, | 1536 uniforms, |
| 1199 locations, | 1537 locations, |
| 1200 base_uniform_index); | 1538 base_uniform_index); |
| 1201 sampler_location_ = locations[0]; | 1539 sampler_location_ = locations[0]; |
| 1202 alpha_location_ = locations[1]; | 1540 alpha_location_ = locations[1]; |
| 1203 color_matrix_location_ = locations[2]; | 1541 color_matrix_location_ = locations[2]; |
| 1204 color_offset_location_ = locations[3]; | 1542 color_offset_location_ = locations[3]; |
| 1543 BLEND_MODE_SET_LOCATIONS(locations, 4); |
| 1205 } | 1544 } |
| 1206 | 1545 |
| 1207 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( | 1546 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( |
| 1208 TexCoordPrecision precision, SamplerType sampler) const { | 1547 TexCoordPrecision precision, SamplerType sampler) const { |
| 1209 return FRAGMENT_SHADER( | 1548 return FRAGMENT_SHADER( |
| 1210 precision mediump float; | 1549 precision mediump float; |
| 1211 uniform SamplerType s_texture; | 1550 uniform SamplerType s_texture; |
| 1212 uniform float alpha; | 1551 uniform float alpha; |
| 1213 uniform mat4 colorMatrix; | 1552 uniform mat4 colorMatrix; |
| 1214 uniform vec4 colorOffset; | 1553 uniform vec4 colorOffset; |
| 1215 varying TexCoordPrecision vec2 v_texCoord; | 1554 varying TexCoordPrecision vec2 v_texCoord; |
| 1216 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1555 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
| 1217 | 1556 |
| 1218 void main() { | 1557 void main() { |
| 1219 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1558 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1220 float nonZeroAlpha = max(texColor.a, 0.00001); | 1559 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1221 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1560 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1222 texColor = colorMatrix * texColor + colorOffset; | 1561 texColor = colorMatrix * texColor + colorOffset; |
| 1223 texColor.rgb *= texColor.a; | 1562 texColor.rgb *= texColor.a; |
| 1224 texColor = clamp(texColor, 0.0, 1.0); | 1563 texColor = clamp(texColor, 0.0, 1.0); |
| 1225 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1564 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 1226 vec2 d2 = min(d4.xz, d4.yw); | 1565 vec2 d2 = min(d4.xz, d4.yw); |
| 1227 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1566 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 1228 gl_FragColor = texColor * alpha * aa; | 1567 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); |
| 1229 } | 1568 } |
| 1230 ); // NOLINT(whitespace/parens) | 1569 ); // NOLINT(whitespace/parens) |
| 1231 } | 1570 } |
| 1232 | 1571 |
| 1233 FragmentShaderRGBATexAlphaMaskColorMatrix:: | 1572 FragmentShaderRGBATexAlphaMaskColorMatrix:: |
| 1234 FragmentShaderRGBATexAlphaMaskColorMatrix() | 1573 FragmentShaderRGBATexAlphaMaskColorMatrix() |
| 1235 : sampler_location_(-1), | 1574 : sampler_location_(-1), |
| 1236 mask_sampler_location_(-1), | 1575 mask_sampler_location_(-1), |
| 1237 alpha_location_(-1), | 1576 alpha_location_(-1), |
| 1238 mask_tex_coord_scale_location_(-1) {} | 1577 mask_tex_coord_scale_location_(-1) {} |
| 1239 | 1578 |
| 1240 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init( | 1579 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init( |
| 1241 GLES2Interface* context, | 1580 GLES2Interface* context, |
| 1242 unsigned program, | 1581 unsigned program, |
| 1243 int* base_uniform_index) { | 1582 int* base_uniform_index) { |
| 1244 static const char* uniforms[] = { | 1583 static const char* uniforms[] = { |
| 1245 "s_texture", | 1584 "s_texture", |
| 1246 "s_mask", | 1585 "s_mask", |
| 1247 "alpha", | 1586 "alpha", |
| 1248 "maskTexCoordScale", | 1587 "maskTexCoordScale", |
| 1249 "maskTexCoordOffset", | 1588 "maskTexCoordOffset", |
| 1250 "colorMatrix", | 1589 "colorMatrix", |
| 1251 "colorOffset", | 1590 "colorOffset", |
| 1591 BLEND_MODE_UNIFORMS, |
| 1252 }; | 1592 }; |
| 1253 int locations[arraysize(uniforms)]; | 1593 int locations[arraysize(uniforms)]; |
| 1254 | 1594 |
| 1255 GetProgramUniformLocations(context, | 1595 GetProgramUniformLocations(context, |
| 1256 program, | 1596 program, |
| 1257 arraysize(uniforms), | 1597 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
| 1258 uniforms, | 1598 uniforms, |
| 1259 locations, | 1599 locations, |
| 1260 base_uniform_index); | 1600 base_uniform_index); |
| 1261 sampler_location_ = locations[0]; | 1601 sampler_location_ = locations[0]; |
| 1262 mask_sampler_location_ = locations[1]; | 1602 mask_sampler_location_ = locations[1]; |
| 1263 alpha_location_ = locations[2]; | 1603 alpha_location_ = locations[2]; |
| 1264 mask_tex_coord_scale_location_ = locations[3]; | 1604 mask_tex_coord_scale_location_ = locations[3]; |
| 1265 mask_tex_coord_offset_location_ = locations[4]; | 1605 mask_tex_coord_offset_location_ = locations[4]; |
| 1266 color_matrix_location_ = locations[5]; | 1606 color_matrix_location_ = locations[5]; |
| 1267 color_offset_location_ = locations[6]; | 1607 color_offset_location_ = locations[6]; |
| 1608 BLEND_MODE_SET_LOCATIONS(locations, 7); |
| 1268 } | 1609 } |
| 1269 | 1610 |
| 1270 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( | 1611 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( |
| 1271 TexCoordPrecision precision, SamplerType sampler) const { | 1612 TexCoordPrecision precision, SamplerType sampler) const { |
| 1272 return FRAGMENT_SHADER( | 1613 return FRAGMENT_SHADER( |
| 1273 precision mediump float; | 1614 precision mediump float; |
| 1274 varying TexCoordPrecision vec2 v_texCoord; | 1615 varying TexCoordPrecision vec2 v_texCoord; |
| 1275 uniform SamplerType s_texture; | 1616 uniform SamplerType s_texture; |
| 1276 uniform SamplerType s_mask; | 1617 uniform SamplerType s_mask; |
| 1277 uniform vec2 maskTexCoordScale; | 1618 uniform vec2 maskTexCoordScale; |
| 1278 uniform vec2 maskTexCoordOffset; | 1619 uniform vec2 maskTexCoordOffset; |
| 1279 uniform mat4 colorMatrix; | 1620 uniform mat4 colorMatrix; |
| 1280 uniform vec4 colorOffset; | 1621 uniform vec4 colorOffset; |
| 1281 uniform float alpha; | 1622 uniform float alpha; |
| 1282 void main() { | 1623 void main() { |
| 1283 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1624 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
| 1284 float nonZeroAlpha = max(texColor.a, 0.00001); | 1625 float nonZeroAlpha = max(texColor.a, 0.00001); |
| 1285 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1626 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
| 1286 texColor = colorMatrix * texColor + colorOffset; | 1627 texColor = colorMatrix * texColor + colorOffset; |
| 1287 texColor.rgb *= texColor.a; | 1628 texColor.rgb *= texColor.a; |
| 1288 texColor = clamp(texColor, 0.0, 1.0); | 1629 texColor = clamp(texColor, 0.0, 1.0); |
| 1289 TexCoordPrecision vec2 maskTexCoord = | 1630 TexCoordPrecision vec2 maskTexCoord = |
| 1290 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1631 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
| 1291 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1632 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
| 1292 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1633 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
| 1293 gl_FragColor = texColor * alpha * maskColor.w; | 1634 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); |
| 1294 } | 1635 } |
| 1295 ); // NOLINT(whitespace/parens) | 1636 ); // NOLINT(whitespace/parens) |
| 1296 } | 1637 } |
| 1297 | 1638 |
| 1298 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 1639 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
| 1299 : y_texture_location_(-1), | 1640 : y_texture_location_(-1), |
| 1300 u_texture_location_(-1), | 1641 u_texture_location_(-1), |
| 1301 v_texture_location_(-1), | 1642 v_texture_location_(-1), |
| 1302 alpha_location_(-1), | 1643 alpha_location_(-1), |
| 1303 yuv_matrix_location_(-1), | 1644 yuv_matrix_location_(-1), |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 vec2 texCoord = | 1871 vec2 texCoord = |
| 1531 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 1872 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
| 1532 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1873 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 1533 float picker = abs(coord.x - coord.y); // NOLINT | 1874 float picker = abs(coord.x - coord.y); // NOLINT |
| 1534 gl_FragColor = mix(color1, color2, picker) * alpha; | 1875 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 1535 } | 1876 } |
| 1536 ); // NOLINT(whitespace/parens) | 1877 ); // NOLINT(whitespace/parens) |
| 1537 } | 1878 } |
| 1538 | 1879 |
| 1539 } // namespace cc | 1880 } // namespace cc |
| OLD | NEW |