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) \ | 16 #define FRAGMENT_SHADER(Src) \ |
17 SetFragmentTexCoordPrecision(precision, \ | 17 SetFragmentTexCoordPrecision( \ |
18 SetFragmentSamplerType(sampler, SHADER0(Src))) | 18 precision, \ |
19 SetFragmentSamplerType(sampler, SetBlendModeFunctions(SHADER0(Src)))) | |
19 | 20 |
20 using gpu::gles2::GLES2Interface; | 21 using gpu::gles2::GLES2Interface; |
21 | 22 |
22 namespace cc { | 23 namespace cc { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 static void GetProgramUniformLocations(GLES2Interface* context, | 27 static void GetProgramUniformLocations(GLES2Interface* context, |
27 unsigned program, | 28 unsigned program, |
28 size_t count, | 29 size_t count, |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
659 void main() { | 660 void main() { |
660 gl_Position = matrix * a_position; | 661 gl_Position = matrix * a_position; |
661 v_texCoord = | 662 v_texCoord = |
662 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 663 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
663 } | 664 } |
664 // clang-format off | 665 // clang-format off |
665 ); // NOLINT(whitespace/parens) | 666 ); // NOLINT(whitespace/parens) |
666 // clang-format on | 667 // clang-format on |
667 } | 668 } |
668 | 669 |
670 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" | |
671 #define UNUSED_BLEND_MODE_UNIFORMS (is_default_blend_mode() ? 2 : 0) | |
672 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ | |
673 if (!is_default_blend_mode()) { \ | |
674 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ | |
675 backdrop_location_ = locations[POS]; \ | |
676 backdrop_rect_location_ = locations[POS + 1]; \ | |
677 } | |
678 | |
679 FragmentTexBlendMode::FragmentTexBlendMode() | |
680 : backdrop_location_(-1), | |
681 backdrop_rect_location_(-1), | |
682 blend_mode_(BlendModeNormal) { | |
683 } | |
684 | |
685 std::string FragmentTexBlendMode::SetBlendModeFunctions( | |
686 std::string shader_string) const { | |
687 if (shader_string.find("ApplyBlendMode") == std::string::npos) | |
688 return shader_string; | |
689 | |
690 if (is_default_blend_mode()) { | |
691 return "#define ApplyBlendMode(X) (X)\n" + shader_string; | |
692 } | |
693 | |
694 // clang-format off | |
695 static const std::string kFunctionApplyBlendMode = SHADER0( | |
696 // clang-format on | |
697 uniform SamplerType s_backdropTexture; | |
698 uniform TexCoordPrecision vec4 backdropRect; | |
699 | |
700 vec4 GetBackdropColor() { | |
701 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; | |
702 bgTexCoord.x /= backdropRect.z; | |
703 bgTexCoord.y /= backdropRect.w; | |
704 return TextureLookup(s_backdropTexture, bgTexCoord); | |
705 } | |
706 | |
707 vec4 ApplyBlendMode(vec4 src) { | |
708 vec4 dst = GetBackdropColor(); | |
709 return Blend(src, dst); | |
710 } | |
711 // clang-format off | |
712 ); | |
enne (OOO)
2014/10/22 19:00:18
Did the presubmit linter not yell at you for about
rosca
2014/10/22 19:35:02
Seemingly not. I should have run it locally. Thank
| |
713 // clang-format on | |
714 | |
715 return "precision mediump float;" + GetHelperFunctions() + | |
716 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; | |
717 } | |
718 | |
719 std::string FragmentTexBlendMode::GetHelperFunctions() const { | |
720 // clang-format off | |
721 static const std::string kFunctionHardLight = SHADER0( | |
722 // clang-format on | |
723 vec3 hardLight(vec4 src, vec4 dst) { | |
724 vec3 result; | |
725 result.r = | |
726 (2.0 * src.r <= src.a) | |
727 ? (2.0 * src.r * dst.r) | |
728 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); | |
729 result.g = | |
730 (2.0 * src.g <= src.a) | |
731 ? (2.0 * src.g * dst.g) | |
732 : (src.a * dst.a - 2.0 * (dst.a - dst.g) * (src.a - src.g)); | |
733 result.b = | |
734 (2.0 * src.b <= src.a) | |
735 ? (2.0 * src.b * dst.b) | |
736 : (src.a * dst.a - 2.0 * (dst.a - dst.b) * (src.a - src.b)); | |
737 result.rgb += src.rgb * (1.0 - dst.a) + dst.rgb * (1.0 - src.a); | |
738 return result; | |
739 } | |
740 // clang-format off | |
741 ); | |
742 | |
743 static const std::string kFunctionColorDodgeComponent = SHADER0( | |
744 // clang-format on | |
745 float getColorDodgeComponent( | |
746 float srcc, float srca, float dstc, float dsta) { | |
747 if (0.0 == dstc) | |
748 return srcc * (1.0 - dsta); | |
749 float d = srca - srcc; | |
750 if (0.0 == d) | |
751 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | |
752 d = min(dsta, dstc * srca / d); | |
753 return d * srca + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | |
754 } | |
755 // clang-format off | |
756 ); | |
757 | |
758 static const std::string kFunctionColorBurnComponent = SHADER0( | |
759 // clang-format on | |
760 float getColorBurnComponent( | |
761 float srcc, float srca, float dstc, float dsta) { | |
762 if (dsta == dstc) | |
763 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | |
764 if (0.0 == srcc) | |
765 return dstc * (1.0 - srca); | |
766 float d = max(0.0, dsta - (dsta - dstc) * srca / srcc); | |
767 return srca * d + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | |
768 } | |
769 // clang-format off | |
770 ); | |
771 | |
772 static const std::string kFunctionSoftLightComponentPosDstAlpha = SHADER0( | |
773 // clang-format on | |
774 float getSoftLightComponent( | |
775 float srcc, float srca, float dstc, float dsta) { | |
776 if (2.0 * srcc <= srca) { | |
777 return (dstc * dstc * (srca - 2.0 * srcc)) / dsta + | |
778 (1.0 - dsta) * srcc + dstc * (-srca + 2.0 * srcc + 1.0); | |
779 } else if (4.0 * dstc <= dsta) { | |
780 float DSqd = dstc * dstc; | |
781 float DCub = DSqd * dstc; | |
782 float DaSqd = dsta * dsta; | |
783 float DaCub = DaSqd * dsta; | |
784 return (-DaCub * srcc + | |
785 DaSqd * (srcc - dstc * (3.0 * srca - 6.0 * srcc - 1.0)) + | |
786 12.0 * dsta * DSqd * (srca - 2.0 * srcc) - | |
787 16.0 * DCub * (srca - 2.0 * srcc)) / | |
788 DaSqd; | |
789 } else { | |
790 return -sqrt(dsta * dstc) * (srca - 2.0 * srcc) - dsta * srcc + | |
791 dstc * (srca - 2.0 * srcc + 1.0) + srcc; | |
792 } | |
793 } | |
794 // clang-format off | |
795 ); | |
796 | |
797 static const std::string kFunctionLum = SHADER0( | |
798 // clang-format on | |
799 float luminance(vec3 color) { return dot(vec3(0.3, 0.59, 0.11), color); } | |
800 | |
801 vec3 set_luminance(vec3 hueSat, float alpha, vec3 lumColor) { | |
802 float diff = luminance(lumColor - hueSat); | |
803 vec3 outColor = hueSat + diff; | |
804 float outLum = luminance(outColor); | |
805 float minComp = min(min(outColor.r, outColor.g), outColor.b); | |
806 float maxComp = max(max(outColor.r, outColor.g), outColor.b); | |
807 if (minComp < 0.0) { | |
808 outColor = outLum + | |
809 ((outColor - vec3(outLum, outLum, outLum)) * outLum) / | |
810 (outLum - minComp); | |
811 } | |
812 if (maxComp > alpha) { | |
813 outColor = | |
814 outLum + | |
815 ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / | |
816 (maxComp - outLum); | |
817 } | |
818 return outColor; | |
819 } | |
820 // clang-format off | |
821 ); | |
822 | |
823 static const std::string kFunctionSat = SHADER0( | |
824 // clang-format on | |
825 float saturation(vec3 color) { | |
826 return max(max(color.r, color.g), color.b) - | |
827 min(min(color.r, color.g), color.b); | |
828 } | |
829 | |
830 vec3 set_saturation_helper( | |
831 float minComp, float midComp, float maxComp, float sat) { | |
832 if (minComp < maxComp) { | |
833 vec3 result; | |
834 result.r = 0.0; | |
835 result.g = sat * (midComp - minComp) / (maxComp - minComp); | |
836 result.b = sat; | |
837 return result; | |
838 } else { | |
839 return vec3(0, 0, 0); | |
840 } | |
841 } | |
842 | |
843 vec3 set_saturation(vec3 hueLumColor, vec3 satColor) { | |
844 float sat = saturation(satColor); | |
845 if (hueLumColor.r <= hueLumColor.g) { | |
846 if (hueLumColor.g <= hueLumColor.b) { | |
847 hueLumColor.rgb = set_saturation_helper( | |
848 hueLumColor.r, hueLumColor.g, hueLumColor.b, sat); | |
849 } else if (hueLumColor.r <= hueLumColor.b) { | |
850 hueLumColor.rbg = set_saturation_helper( | |
851 hueLumColor.r, hueLumColor.b, hueLumColor.g, sat); | |
852 } else { | |
853 hueLumColor.brg = set_saturation_helper( | |
854 hueLumColor.b, hueLumColor.r, hueLumColor.g, sat); | |
855 } | |
856 } else if (hueLumColor.r <= hueLumColor.b) { | |
857 hueLumColor.grb = set_saturation_helper( | |
858 hueLumColor.g, hueLumColor.r, hueLumColor.b, sat); | |
859 } else if (hueLumColor.g <= hueLumColor.b) { | |
860 hueLumColor.gbr = set_saturation_helper( | |
861 hueLumColor.g, hueLumColor.b, hueLumColor.r, sat); | |
862 } else { | |
863 hueLumColor.bgr = set_saturation_helper( | |
864 hueLumColor.b, hueLumColor.g, hueLumColor.r, sat); | |
865 } | |
866 return hueLumColor; | |
867 } | |
868 // clang-format off | |
869 ); | |
870 // clang-format on | |
871 | |
872 switch (blend_mode_) { | |
873 case BlendModeOverlay: | |
874 case BlendModeHardLight: | |
875 return kFunctionHardLight; | |
876 case BlendModeColorDodge: | |
877 return kFunctionColorDodgeComponent; | |
878 case BlendModeColorBurn: | |
879 return kFunctionColorBurnComponent; | |
880 case BlendModeSoftLight: | |
881 return kFunctionSoftLightComponentPosDstAlpha; | |
882 case BlendModeHue: | |
883 case BlendModeSaturation: | |
884 return kFunctionLum + kFunctionSat; | |
885 case BlendModeColor: | |
886 case BlendModeLuminosity: | |
887 return kFunctionLum; | |
888 default: | |
889 return std::string(); | |
890 } | |
891 } | |
892 | |
893 std::string FragmentTexBlendMode::GetBlendFunction() const { | |
894 return "vec4 Blend(vec4 src, vec4 dst) {" | |
895 " vec4 result;" | |
896 " result.a = src.a + (1.0 - src.a) * dst.a;" + | |
897 GetBlendFunctionBodyForRGB() + | |
898 " return result;" | |
899 "}"; | |
900 } | |
901 | |
902 std::string FragmentTexBlendMode::GetBlendFunctionBodyForRGB() const { | |
903 switch (blend_mode_) { | |
904 case BlendModeLighten: | |
905 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," | |
906 " (1.0 - dst.a) * src.rgb + dst.rgb);"; | |
907 case BlendModeOverlay: | |
908 return "result.rgb = hardLight(dst, src);"; | |
909 case BlendModeDarken: | |
910 return "result.rgb = min((1.0 - src.a) * dst.rgb + src.rgb," | |
911 " (1.0 - dst.a) * src.rgb + dst.rgb);"; | |
912 case BlendModeColorDodge: | |
913 return "result.r = getColorDodgeComponent(src.r, src.a, dst.r, dst.a);" | |
914 "result.g = getColorDodgeComponent(src.g, src.a, dst.g, dst.a);" | |
915 "result.b = getColorDodgeComponent(src.b, src.a, dst.b, dst.a);"; | |
916 case BlendModeColorBurn: | |
917 return "result.r = getColorBurnComponent(src.r, src.a, dst.r, dst.a);" | |
918 "result.g = getColorBurnComponent(src.g, src.a, dst.g, dst.a);" | |
919 "result.b = getColorBurnComponent(src.b, src.a, dst.b, dst.a);"; | |
920 case BlendModeHardLight: | |
921 return "result.rgb = hardLight(src, dst);"; | |
922 case BlendModeSoftLight: | |
923 return "if (0.0 == dst.a) {" | |
924 " result.rgb = src.rgb;" | |
925 "} else {" | |
926 " result.r = getSoftLightComponent(src.r, src.a, dst.r, dst.a);" | |
927 " result.g = getSoftLightComponent(src.g, src.a, dst.g, dst.a);" | |
928 " result.b = getSoftLightComponent(src.b, src.a, dst.b, dst.a);" | |
929 "}"; | |
930 case BlendModeDifference: | |
931 return "result.rgb = src.rgb + dst.rgb -" | |
932 " 2.0 * min(src.rgb * dst.a, dst.rgb * src.a);"; | |
933 case BlendModeExclusion: | |
934 return "result.rgb = dst.rgb + src.rgb - 2.0 * dst.rgb * src.rgb;"; | |
935 case BlendModeMultiply: | |
936 return "result.rgb = (1.0 - src.a) * dst.rgb +" | |
937 " (1.0 - dst.a) * src.rgb + src.rgb * dst.rgb;"; | |
938 case BlendModeHue: | |
939 return "vec4 dstSrcAlpha = dst * src.a;" | |
940 "result.rgb =" | |
941 " set_luminance(set_saturation(src.rgb * dst.a," | |
942 " dstSrcAlpha.rgb)," | |
943 " dstSrcAlpha.a," | |
944 " dstSrcAlpha.rgb);" | |
945 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; | |
946 case BlendModeSaturation: | |
947 return "vec4 dstSrcAlpha = dst * src.a;" | |
948 "result.rgb = set_luminance(set_saturation(dstSrcAlpha.rgb," | |
949 " src.rgb * dst.a)," | |
950 " dstSrcAlpha.a," | |
951 " dstSrcAlpha.rgb);" | |
952 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; | |
953 case BlendModeColor: | |
954 return "vec4 srcDstAlpha = src * dst.a;" | |
955 "result.rgb = set_luminance(srcDstAlpha.rgb," | |
956 " srcDstAlpha.a," | |
957 " dst.rgb * src.a);" | |
958 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; | |
959 case BlendModeLuminosity: | |
960 return "vec4 srcDstAlpha = src * dst.a;" | |
961 "result.rgb = set_luminance(dst.rgb * src.a," | |
962 " srcDstAlpha.a," | |
963 " srcDstAlpha.rgb);" | |
964 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; | |
965 default: | |
966 NOTREACHED(); | |
967 // simple alpha compositing | |
968 return "result.rgb = src.rgb * src.a + dst.rgb * dst.a * (1 - src.a)"; | |
969 } | |
970 } | |
971 | |
669 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 972 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
670 : sampler_location_(-1), alpha_location_(-1) { | 973 : sampler_location_(-1), alpha_location_(-1) { |
671 } | 974 } |
672 | 975 |
673 void FragmentTexAlphaBinding::Init(GLES2Interface* context, | 976 void FragmentTexAlphaBinding::Init(GLES2Interface* context, |
674 unsigned program, | 977 unsigned program, |
675 int* base_uniform_index) { | 978 int* base_uniform_index) { |
676 static const char* uniforms[] = { | 979 static const char* uniforms[] = { |
677 "s_texture", "alpha", | 980 "s_texture", "alpha", BLEND_MODE_UNIFORMS, |
678 }; | 981 }; |
679 int locations[arraysize(uniforms)]; | 982 int locations[arraysize(uniforms)]; |
680 | 983 |
681 GetProgramUniformLocations(context, | 984 GetProgramUniformLocations(context, |
682 program, | 985 program, |
683 arraysize(uniforms), | 986 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
684 uniforms, | 987 uniforms, |
685 locations, | 988 locations, |
686 base_uniform_index); | 989 base_uniform_index); |
687 sampler_location_ = locations[0]; | 990 sampler_location_ = locations[0]; |
688 alpha_location_ = locations[1]; | 991 alpha_location_ = locations[1]; |
992 BLEND_MODE_SET_LOCATIONS(locations, 2); | |
689 } | 993 } |
690 | 994 |
691 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding() | 995 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding() |
692 : sampler_location_(-1), | 996 : sampler_location_(-1), |
693 alpha_location_(-1), | 997 alpha_location_(-1), |
694 color_matrix_location_(-1), | 998 color_matrix_location_(-1), |
695 color_offset_location_(-1) { | 999 color_offset_location_(-1) { |
696 } | 1000 } |
697 | 1001 |
698 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context, | 1002 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context, |
699 unsigned program, | 1003 unsigned program, |
700 int* base_uniform_index) { | 1004 int* base_uniform_index) { |
701 static const char* uniforms[] = { | 1005 static const char* uniforms[] = { |
702 "s_texture", "alpha", "colorMatrix", "colorOffset", | 1006 "s_texture", "alpha", "colorMatrix", "colorOffset", BLEND_MODE_UNIFORMS, |
703 }; | 1007 }; |
704 int locations[arraysize(uniforms)]; | 1008 int locations[arraysize(uniforms)]; |
705 | 1009 |
706 GetProgramUniformLocations(context, | 1010 GetProgramUniformLocations(context, |
707 program, | 1011 program, |
708 arraysize(uniforms), | 1012 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
709 uniforms, | 1013 uniforms, |
710 locations, | 1014 locations, |
711 base_uniform_index); | 1015 base_uniform_index); |
712 sampler_location_ = locations[0]; | 1016 sampler_location_ = locations[0]; |
713 alpha_location_ = locations[1]; | 1017 alpha_location_ = locations[1]; |
714 color_matrix_location_ = locations[2]; | 1018 color_matrix_location_ = locations[2]; |
715 color_offset_location_ = locations[3]; | 1019 color_offset_location_ = locations[3]; |
1020 BLEND_MODE_SET_LOCATIONS(locations, 4); | |
716 } | 1021 } |
717 | 1022 |
718 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() : sampler_location_(-1) { | 1023 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() : sampler_location_(-1) { |
719 } | 1024 } |
720 | 1025 |
721 void FragmentTexOpaqueBinding::Init(GLES2Interface* context, | 1026 void FragmentTexOpaqueBinding::Init(GLES2Interface* context, |
722 unsigned program, | 1027 unsigned program, |
723 int* base_uniform_index) { | 1028 int* base_uniform_index) { |
724 static const char* uniforms[] = { | 1029 static const char* uniforms[] = { |
725 "s_texture", | 1030 "s_texture", |
(...skipping 14 matching lines...) Expand all Loading... | |
740 SamplerType sampler) const { | 1045 SamplerType sampler) const { |
741 // clang-format off | 1046 // clang-format off |
742 return FRAGMENT_SHADER( | 1047 return FRAGMENT_SHADER( |
743 // clang-format on | 1048 // clang-format on |
744 precision mediump float; | 1049 precision mediump float; |
745 varying TexCoordPrecision vec2 v_texCoord; | 1050 varying TexCoordPrecision vec2 v_texCoord; |
746 uniform SamplerType s_texture; | 1051 uniform SamplerType s_texture; |
747 uniform float alpha; | 1052 uniform float alpha; |
748 void main() { | 1053 void main() { |
749 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1054 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
750 gl_FragColor = texColor * alpha; | 1055 gl_FragColor = ApplyBlendMode(texColor * alpha); |
751 } | 1056 } |
752 // clang-format off | 1057 // clang-format off |
753 ); // NOLINT(whitespace/parens) | 1058 ); // NOLINT(whitespace/parens) |
754 // clang-format on | 1059 // clang-format on |
755 } | 1060 } |
756 | 1061 |
757 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( | 1062 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( |
758 TexCoordPrecision precision, | 1063 TexCoordPrecision precision, |
759 SamplerType sampler) const { | 1064 SamplerType sampler) const { |
760 // clang-format off | 1065 // clang-format off |
761 return FRAGMENT_SHADER( | 1066 return FRAGMENT_SHADER( |
762 // clang-format on | 1067 // clang-format on |
763 precision mediump float; | 1068 precision mediump float; |
764 varying TexCoordPrecision vec2 v_texCoord; | 1069 varying TexCoordPrecision vec2 v_texCoord; |
765 uniform SamplerType s_texture; | 1070 uniform SamplerType s_texture; |
766 uniform float alpha; | 1071 uniform float alpha; |
767 uniform mat4 colorMatrix; | 1072 uniform mat4 colorMatrix; |
768 uniform vec4 colorOffset; | 1073 uniform vec4 colorOffset; |
769 void main() { | 1074 void main() { |
770 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1075 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
771 float nonZeroAlpha = max(texColor.a, 0.00001); | 1076 float nonZeroAlpha = max(texColor.a, 0.00001); |
772 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1077 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
773 texColor = colorMatrix * texColor + colorOffset; | 1078 texColor = colorMatrix * texColor + colorOffset; |
774 texColor.rgb *= texColor.a; | 1079 texColor.rgb *= texColor.a; |
775 texColor = clamp(texColor, 0.0, 1.0); | 1080 texColor = clamp(texColor, 0.0, 1.0); |
776 gl_FragColor = texColor * alpha; | 1081 gl_FragColor = ApplyBlendMode(texColor * alpha); |
777 } | 1082 } |
778 // clang-format off | 1083 // clang-format off |
779 ); // NOLINT(whitespace/parens) | 1084 ); // NOLINT(whitespace/parens) |
780 // clang-format on | 1085 // clang-format on |
781 } | 1086 } |
782 | 1087 |
783 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 1088 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( |
784 TexCoordPrecision precision, | 1089 TexCoordPrecision precision, |
785 SamplerType sampler) const { | 1090 SamplerType sampler) const { |
786 // clang-format off | 1091 // clang-format off |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
959 } | 1264 } |
960 | 1265 |
961 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 1266 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
962 : sampler_location_(-1), alpha_location_(-1) { | 1267 : sampler_location_(-1), alpha_location_(-1) { |
963 } | 1268 } |
964 | 1269 |
965 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, | 1270 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context, |
966 unsigned program, | 1271 unsigned program, |
967 int* base_uniform_index) { | 1272 int* base_uniform_index) { |
968 static const char* uniforms[] = { | 1273 static const char* uniforms[] = { |
969 "s_texture", "alpha", | 1274 "s_texture", "alpha", BLEND_MODE_UNIFORMS, |
970 }; | 1275 }; |
971 int locations[arraysize(uniforms)]; | 1276 int locations[arraysize(uniforms)]; |
972 | 1277 |
973 GetProgramUniformLocations(context, | 1278 GetProgramUniformLocations(context, |
974 program, | 1279 program, |
975 arraysize(uniforms), | 1280 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
976 uniforms, | 1281 uniforms, |
977 locations, | 1282 locations, |
978 base_uniform_index); | 1283 base_uniform_index); |
979 sampler_location_ = locations[0]; | 1284 sampler_location_ = locations[0]; |
980 alpha_location_ = locations[1]; | 1285 alpha_location_ = locations[1]; |
1286 BLEND_MODE_SET_LOCATIONS(locations, 2); | |
981 } | 1287 } |
982 | 1288 |
983 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( | 1289 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( |
984 TexCoordPrecision precision, | 1290 TexCoordPrecision precision, |
985 SamplerType sampler) const { | 1291 SamplerType sampler) const { |
986 // clang-format off | 1292 // clang-format off |
987 return FRAGMENT_SHADER( | 1293 return FRAGMENT_SHADER( |
988 // clang-format on | 1294 // clang-format on |
989 precision mediump float; | 1295 precision mediump float; |
990 uniform SamplerType s_texture; | 1296 uniform SamplerType s_texture; |
991 uniform float alpha; | 1297 uniform float alpha; |
992 varying TexCoordPrecision vec2 v_texCoord; | 1298 varying TexCoordPrecision vec2 v_texCoord; |
993 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1299 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
994 | 1300 |
995 void main() { | 1301 void main() { |
996 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1302 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
997 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1303 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
998 vec2 d2 = min(d4.xz, d4.yw); | 1304 vec2 d2 = min(d4.xz, d4.yw); |
999 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1305 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1000 gl_FragColor = texColor * alpha * aa; | 1306 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); |
1001 } | 1307 } |
1002 // clang-format off | 1308 // clang-format off |
1003 ); // NOLINT(whitespace/parens) | 1309 ); // NOLINT(whitespace/parens) |
1004 // clang-format on | 1310 // clang-format on |
1005 } | 1311 } |
1006 | 1312 |
1007 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() | 1313 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding() |
1008 : sampler_location_(-1), | 1314 : sampler_location_(-1), |
1009 alpha_location_(-1), | 1315 alpha_location_(-1), |
1010 fragment_tex_transform_location_(-1) { | 1316 fragment_tex_transform_location_(-1) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1090 : sampler_location_(-1), | 1396 : sampler_location_(-1), |
1091 mask_sampler_location_(-1), | 1397 mask_sampler_location_(-1), |
1092 alpha_location_(-1), | 1398 alpha_location_(-1), |
1093 mask_tex_coord_scale_location_(-1) { | 1399 mask_tex_coord_scale_location_(-1) { |
1094 } | 1400 } |
1095 | 1401 |
1096 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, | 1402 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context, |
1097 unsigned program, | 1403 unsigned program, |
1098 int* base_uniform_index) { | 1404 int* base_uniform_index) { |
1099 static const char* uniforms[] = { | 1405 static const char* uniforms[] = { |
1100 "s_texture", "s_mask", "alpha", "maskTexCoordScale", "maskTexCoordOffset", | 1406 "s_texture", |
1407 "s_mask", | |
1408 "alpha", | |
1409 "maskTexCoordScale", | |
1410 "maskTexCoordOffset", | |
1411 BLEND_MODE_UNIFORMS, | |
1101 }; | 1412 }; |
1102 int locations[arraysize(uniforms)]; | 1413 int locations[arraysize(uniforms)]; |
1103 | 1414 |
1104 GetProgramUniformLocations(context, | 1415 GetProgramUniformLocations(context, |
1105 program, | 1416 program, |
1106 arraysize(uniforms), | 1417 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
1107 uniforms, | 1418 uniforms, |
1108 locations, | 1419 locations, |
1109 base_uniform_index); | 1420 base_uniform_index); |
1110 sampler_location_ = locations[0]; | 1421 sampler_location_ = locations[0]; |
1111 mask_sampler_location_ = locations[1]; | 1422 mask_sampler_location_ = locations[1]; |
1112 alpha_location_ = locations[2]; | 1423 alpha_location_ = locations[2]; |
1113 mask_tex_coord_scale_location_ = locations[3]; | 1424 mask_tex_coord_scale_location_ = locations[3]; |
1114 mask_tex_coord_offset_location_ = locations[4]; | 1425 mask_tex_coord_offset_location_ = locations[4]; |
1426 BLEND_MODE_SET_LOCATIONS(locations, 5); | |
1115 } | 1427 } |
1116 | 1428 |
1117 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( | 1429 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( |
1118 TexCoordPrecision precision, | 1430 TexCoordPrecision precision, |
1119 SamplerType sampler) const { | 1431 SamplerType sampler) const { |
1120 // clang-format off | 1432 // clang-format off |
1121 return FRAGMENT_SHADER( | 1433 return FRAGMENT_SHADER( |
1122 // clang-format on | 1434 // clang-format on |
1123 precision mediump float; | 1435 precision mediump float; |
1124 varying TexCoordPrecision vec2 v_texCoord; | 1436 varying TexCoordPrecision vec2 v_texCoord; |
1125 uniform SamplerType s_texture; | 1437 uniform SamplerType s_texture; |
1126 uniform SamplerType s_mask; | 1438 uniform SamplerType s_mask; |
1127 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1439 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1128 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1440 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1129 uniform float alpha; | 1441 uniform float alpha; |
1130 void main() { | 1442 void main() { |
1131 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1443 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1132 TexCoordPrecision vec2 maskTexCoord = | 1444 TexCoordPrecision vec2 maskTexCoord = |
1133 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1445 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1134 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1446 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1135 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1447 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1136 gl_FragColor = texColor * alpha * maskColor.w; | 1448 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); |
1137 } | 1449 } |
1138 // clang-format off | 1450 // clang-format off |
1139 ); // NOLINT(whitespace/parens) | 1451 ); // NOLINT(whitespace/parens) |
1140 // clang-format on | 1452 // clang-format on |
1141 } | 1453 } |
1142 | 1454 |
1143 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 1455 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
1144 : sampler_location_(-1), | 1456 : sampler_location_(-1), |
1145 mask_sampler_location_(-1), | 1457 mask_sampler_location_(-1), |
1146 alpha_location_(-1), | 1458 alpha_location_(-1), |
1147 mask_tex_coord_scale_location_(-1), | 1459 mask_tex_coord_scale_location_(-1), |
1148 mask_tex_coord_offset_location_(-1) { | 1460 mask_tex_coord_offset_location_(-1) { |
1149 } | 1461 } |
1150 | 1462 |
1151 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, | 1463 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context, |
1152 unsigned program, | 1464 unsigned program, |
1153 int* base_uniform_index) { | 1465 int* base_uniform_index) { |
1154 static const char* uniforms[] = { | 1466 static const char* uniforms[] = { |
1155 "s_texture", "s_mask", "alpha", "maskTexCoordScale", "maskTexCoordOffset", | 1467 "s_texture", |
1468 "s_mask", | |
1469 "alpha", | |
1470 "maskTexCoordScale", | |
1471 "maskTexCoordOffset", | |
1472 BLEND_MODE_UNIFORMS, | |
1156 }; | 1473 }; |
1157 int locations[arraysize(uniforms)]; | 1474 int locations[arraysize(uniforms)]; |
1158 | 1475 |
1159 GetProgramUniformLocations(context, | 1476 GetProgramUniformLocations(context, |
1160 program, | 1477 program, |
1161 arraysize(uniforms), | 1478 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
1162 uniforms, | 1479 uniforms, |
1163 locations, | 1480 locations, |
1164 base_uniform_index); | 1481 base_uniform_index); |
1165 sampler_location_ = locations[0]; | 1482 sampler_location_ = locations[0]; |
1166 mask_sampler_location_ = locations[1]; | 1483 mask_sampler_location_ = locations[1]; |
1167 alpha_location_ = locations[2]; | 1484 alpha_location_ = locations[2]; |
1168 mask_tex_coord_scale_location_ = locations[3]; | 1485 mask_tex_coord_scale_location_ = locations[3]; |
1169 mask_tex_coord_offset_location_ = locations[4]; | 1486 mask_tex_coord_offset_location_ = locations[4]; |
1487 BLEND_MODE_SET_LOCATIONS(locations, 5); | |
1170 } | 1488 } |
1171 | 1489 |
1172 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( | 1490 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( |
1173 TexCoordPrecision precision, | 1491 TexCoordPrecision precision, |
1174 SamplerType sampler) const { | 1492 SamplerType sampler) const { |
1175 // clang-format off | 1493 // clang-format off |
1176 return FRAGMENT_SHADER( | 1494 return FRAGMENT_SHADER( |
1177 // clang-format on | 1495 // clang-format on |
1178 precision mediump float; | 1496 precision mediump float; |
1179 uniform SamplerType s_texture; | 1497 uniform SamplerType s_texture; |
1180 uniform SamplerType s_mask; | 1498 uniform SamplerType s_mask; |
1181 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1499 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1182 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1500 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1183 uniform float alpha; | 1501 uniform float alpha; |
1184 varying TexCoordPrecision vec2 v_texCoord; | 1502 varying TexCoordPrecision vec2 v_texCoord; |
1185 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1503 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1186 | 1504 |
1187 void main() { | 1505 void main() { |
1188 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1506 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1189 TexCoordPrecision vec2 maskTexCoord = | 1507 TexCoordPrecision vec2 maskTexCoord = |
1190 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1508 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1191 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1509 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1192 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1510 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1193 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1511 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1194 vec2 d2 = min(d4.xz, d4.yw); | 1512 vec2 d2 = min(d4.xz, d4.yw); |
1195 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1513 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1196 gl_FragColor = texColor * alpha * maskColor.w * aa; | 1514 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); |
1197 } | 1515 } |
1198 // clang-format off | 1516 // clang-format off |
1199 ); // NOLINT(whitespace/parens) | 1517 ); // NOLINT(whitespace/parens) |
1200 // clang-format on | 1518 // clang-format on |
1201 } | 1519 } |
1202 | 1520 |
1203 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: | 1521 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: |
1204 FragmentShaderRGBATexAlphaMaskColorMatrixAA() | 1522 FragmentShaderRGBATexAlphaMaskColorMatrixAA() |
1205 : sampler_location_(-1), | 1523 : sampler_location_(-1), |
1206 mask_sampler_location_(-1), | 1524 mask_sampler_location_(-1), |
1207 alpha_location_(-1), | 1525 alpha_location_(-1), |
1208 mask_tex_coord_scale_location_(-1), | 1526 mask_tex_coord_scale_location_(-1), |
1209 color_matrix_location_(-1), | 1527 color_matrix_location_(-1), |
1210 color_offset_location_(-1) { | 1528 color_offset_location_(-1) { |
1211 } | 1529 } |
1212 | 1530 |
1213 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init( | 1531 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init( |
1214 GLES2Interface* context, | 1532 GLES2Interface* context, |
1215 unsigned program, | 1533 unsigned program, |
1216 int* base_uniform_index) { | 1534 int* base_uniform_index) { |
1217 static const char* uniforms[] = { | 1535 static const char* uniforms[] = { |
1218 "s_texture", | 1536 "s_texture", |
1219 "s_mask", | 1537 "s_mask", |
1220 "alpha", | 1538 "alpha", |
1221 "maskTexCoordScale", | 1539 "maskTexCoordScale", |
1222 "maskTexCoordOffset", | 1540 "maskTexCoordOffset", |
1223 "colorMatrix", | 1541 "colorMatrix", |
1224 "colorOffset", | 1542 "colorOffset", |
1543 BLEND_MODE_UNIFORMS, | |
1225 }; | 1544 }; |
1226 int locations[arraysize(uniforms)]; | 1545 int locations[arraysize(uniforms)]; |
1227 | 1546 |
1228 GetProgramUniformLocations(context, | 1547 GetProgramUniformLocations(context, |
1229 program, | 1548 program, |
1230 arraysize(uniforms), | 1549 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
1231 uniforms, | 1550 uniforms, |
1232 locations, | 1551 locations, |
1233 base_uniform_index); | 1552 base_uniform_index); |
1234 sampler_location_ = locations[0]; | 1553 sampler_location_ = locations[0]; |
1235 mask_sampler_location_ = locations[1]; | 1554 mask_sampler_location_ = locations[1]; |
1236 alpha_location_ = locations[2]; | 1555 alpha_location_ = locations[2]; |
1237 mask_tex_coord_scale_location_ = locations[3]; | 1556 mask_tex_coord_scale_location_ = locations[3]; |
1238 mask_tex_coord_offset_location_ = locations[4]; | 1557 mask_tex_coord_offset_location_ = locations[4]; |
1239 color_matrix_location_ = locations[5]; | 1558 color_matrix_location_ = locations[5]; |
1240 color_offset_location_ = locations[6]; | 1559 color_offset_location_ = locations[6]; |
1560 BLEND_MODE_SET_LOCATIONS(locations, 7); | |
1241 } | 1561 } |
1242 | 1562 |
1243 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( | 1563 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( |
1244 TexCoordPrecision precision, | 1564 TexCoordPrecision precision, |
1245 SamplerType sampler) const { | 1565 SamplerType sampler) const { |
1246 // clang-format off | 1566 // clang-format off |
1247 return FRAGMENT_SHADER( | 1567 return FRAGMENT_SHADER( |
1248 // clang-format on | 1568 // clang-format on |
1249 precision mediump float; | 1569 precision mediump float; |
1250 uniform SamplerType s_texture; | 1570 uniform SamplerType s_texture; |
(...skipping 13 matching lines...) Expand all Loading... | |
1264 texColor = colorMatrix * texColor + colorOffset; | 1584 texColor = colorMatrix * texColor + colorOffset; |
1265 texColor.rgb *= texColor.a; | 1585 texColor.rgb *= texColor.a; |
1266 texColor = clamp(texColor, 0.0, 1.0); | 1586 texColor = clamp(texColor, 0.0, 1.0); |
1267 TexCoordPrecision vec2 maskTexCoord = | 1587 TexCoordPrecision vec2 maskTexCoord = |
1268 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1588 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1269 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1589 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1270 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1590 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1271 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1591 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1272 vec2 d2 = min(d4.xz, d4.yw); | 1592 vec2 d2 = min(d4.xz, d4.yw); |
1273 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1593 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1274 gl_FragColor = texColor * alpha * maskColor.w * aa; | 1594 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); |
1275 } | 1595 } |
1276 // clang-format off | 1596 // clang-format off |
1277 ); // NOLINT(whitespace/parens) | 1597 ); // NOLINT(whitespace/parens) |
1278 // clang-format on | 1598 // clang-format on |
1279 } | 1599 } |
1280 | 1600 |
1281 FragmentShaderRGBATexAlphaColorMatrixAA:: | 1601 FragmentShaderRGBATexAlphaColorMatrixAA:: |
1282 FragmentShaderRGBATexAlphaColorMatrixAA() | 1602 FragmentShaderRGBATexAlphaColorMatrixAA() |
1283 : sampler_location_(-1), | 1603 : sampler_location_(-1), |
1284 alpha_location_(-1), | 1604 alpha_location_(-1), |
1285 color_matrix_location_(-1), | 1605 color_matrix_location_(-1), |
1286 color_offset_location_(-1) { | 1606 color_offset_location_(-1) { |
1287 } | 1607 } |
1288 | 1608 |
1289 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(GLES2Interface* context, | 1609 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(GLES2Interface* context, |
1290 unsigned program, | 1610 unsigned program, |
1291 int* base_uniform_index) { | 1611 int* base_uniform_index) { |
1292 static const char* uniforms[] = { | 1612 static const char* uniforms[] = { |
1293 "s_texture", "alpha", "colorMatrix", "colorOffset", | 1613 "s_texture", "alpha", "colorMatrix", "colorOffset", BLEND_MODE_UNIFORMS, |
1294 }; | 1614 }; |
1295 int locations[arraysize(uniforms)]; | 1615 int locations[arraysize(uniforms)]; |
1296 | 1616 |
1297 GetProgramUniformLocations(context, | 1617 GetProgramUniformLocations(context, |
1298 program, | 1618 program, |
1299 arraysize(uniforms), | 1619 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
1300 uniforms, | 1620 uniforms, |
1301 locations, | 1621 locations, |
1302 base_uniform_index); | 1622 base_uniform_index); |
1303 sampler_location_ = locations[0]; | 1623 sampler_location_ = locations[0]; |
1304 alpha_location_ = locations[1]; | 1624 alpha_location_ = locations[1]; |
1305 color_matrix_location_ = locations[2]; | 1625 color_matrix_location_ = locations[2]; |
1306 color_offset_location_ = locations[3]; | 1626 color_offset_location_ = locations[3]; |
1627 BLEND_MODE_SET_LOCATIONS(locations, 4); | |
1307 } | 1628 } |
1308 | 1629 |
1309 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( | 1630 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( |
1310 TexCoordPrecision precision, | 1631 TexCoordPrecision precision, |
1311 SamplerType sampler) const { | 1632 SamplerType sampler) const { |
1312 // clang-format off | 1633 // clang-format off |
1313 return FRAGMENT_SHADER( | 1634 return FRAGMENT_SHADER( |
1314 // clang-format on | 1635 // clang-format on |
1315 precision mediump float; | 1636 precision mediump float; |
1316 uniform SamplerType s_texture; | 1637 uniform SamplerType s_texture; |
1317 uniform float alpha; | 1638 uniform float alpha; |
1318 uniform mat4 colorMatrix; | 1639 uniform mat4 colorMatrix; |
1319 uniform vec4 colorOffset; | 1640 uniform vec4 colorOffset; |
1320 varying TexCoordPrecision vec2 v_texCoord; | 1641 varying TexCoordPrecision vec2 v_texCoord; |
1321 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1642 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1322 | 1643 |
1323 void main() { | 1644 void main() { |
1324 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1645 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1325 float nonZeroAlpha = max(texColor.a, 0.00001); | 1646 float nonZeroAlpha = max(texColor.a, 0.00001); |
1326 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1647 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1327 texColor = colorMatrix * texColor + colorOffset; | 1648 texColor = colorMatrix * texColor + colorOffset; |
1328 texColor.rgb *= texColor.a; | 1649 texColor.rgb *= texColor.a; |
1329 texColor = clamp(texColor, 0.0, 1.0); | 1650 texColor = clamp(texColor, 0.0, 1.0); |
1330 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1651 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1331 vec2 d2 = min(d4.xz, d4.yw); | 1652 vec2 d2 = min(d4.xz, d4.yw); |
1332 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1653 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1333 gl_FragColor = texColor * alpha * aa; | 1654 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); |
1334 } | 1655 } |
1335 // clang-format off | 1656 // clang-format off |
1336 ); // NOLINT(whitespace/parens) | 1657 ); // NOLINT(whitespace/parens) |
1337 // clang-format on | 1658 // clang-format on |
1338 } | 1659 } |
1339 | 1660 |
1340 FragmentShaderRGBATexAlphaMaskColorMatrix:: | 1661 FragmentShaderRGBATexAlphaMaskColorMatrix:: |
1341 FragmentShaderRGBATexAlphaMaskColorMatrix() | 1662 FragmentShaderRGBATexAlphaMaskColorMatrix() |
1342 : sampler_location_(-1), | 1663 : sampler_location_(-1), |
1343 mask_sampler_location_(-1), | 1664 mask_sampler_location_(-1), |
1344 alpha_location_(-1), | 1665 alpha_location_(-1), |
1345 mask_tex_coord_scale_location_(-1) { | 1666 mask_tex_coord_scale_location_(-1) { |
1346 } | 1667 } |
1347 | 1668 |
1348 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context, | 1669 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context, |
1349 unsigned program, | 1670 unsigned program, |
1350 int* base_uniform_index) { | 1671 int* base_uniform_index) { |
1351 static const char* uniforms[] = { | 1672 static const char* uniforms[] = { |
1352 "s_texture", | 1673 "s_texture", |
1353 "s_mask", | 1674 "s_mask", |
1354 "alpha", | 1675 "alpha", |
1355 "maskTexCoordScale", | 1676 "maskTexCoordScale", |
1356 "maskTexCoordOffset", | 1677 "maskTexCoordOffset", |
1357 "colorMatrix", | 1678 "colorMatrix", |
1358 "colorOffset", | 1679 "colorOffset", |
1680 BLEND_MODE_UNIFORMS, | |
1359 }; | 1681 }; |
1360 int locations[arraysize(uniforms)]; | 1682 int locations[arraysize(uniforms)]; |
1361 | 1683 |
1362 GetProgramUniformLocations(context, | 1684 GetProgramUniformLocations(context, |
1363 program, | 1685 program, |
1364 arraysize(uniforms), | 1686 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
1365 uniforms, | 1687 uniforms, |
1366 locations, | 1688 locations, |
1367 base_uniform_index); | 1689 base_uniform_index); |
1368 sampler_location_ = locations[0]; | 1690 sampler_location_ = locations[0]; |
1369 mask_sampler_location_ = locations[1]; | 1691 mask_sampler_location_ = locations[1]; |
1370 alpha_location_ = locations[2]; | 1692 alpha_location_ = locations[2]; |
1371 mask_tex_coord_scale_location_ = locations[3]; | 1693 mask_tex_coord_scale_location_ = locations[3]; |
1372 mask_tex_coord_offset_location_ = locations[4]; | 1694 mask_tex_coord_offset_location_ = locations[4]; |
1373 color_matrix_location_ = locations[5]; | 1695 color_matrix_location_ = locations[5]; |
1374 color_offset_location_ = locations[6]; | 1696 color_offset_location_ = locations[6]; |
1697 BLEND_MODE_SET_LOCATIONS(locations, 7); | |
1375 } | 1698 } |
1376 | 1699 |
1377 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( | 1700 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( |
1378 TexCoordPrecision precision, | 1701 TexCoordPrecision precision, |
1379 SamplerType sampler) const { | 1702 SamplerType sampler) const { |
1380 // clang-format off | 1703 // clang-format off |
1381 return FRAGMENT_SHADER( | 1704 return FRAGMENT_SHADER( |
1382 // clang-format on | 1705 // clang-format on |
1383 precision mediump float; | 1706 precision mediump float; |
1384 varying TexCoordPrecision vec2 v_texCoord; | 1707 varying TexCoordPrecision vec2 v_texCoord; |
1385 uniform SamplerType s_texture; | 1708 uniform SamplerType s_texture; |
1386 uniform SamplerType s_mask; | 1709 uniform SamplerType s_mask; |
1387 uniform vec2 maskTexCoordScale; | 1710 uniform vec2 maskTexCoordScale; |
1388 uniform vec2 maskTexCoordOffset; | 1711 uniform vec2 maskTexCoordOffset; |
1389 uniform mat4 colorMatrix; | 1712 uniform mat4 colorMatrix; |
1390 uniform vec4 colorOffset; | 1713 uniform vec4 colorOffset; |
1391 uniform float alpha; | 1714 uniform float alpha; |
1392 void main() { | 1715 void main() { |
1393 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1716 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1394 float nonZeroAlpha = max(texColor.a, 0.00001); | 1717 float nonZeroAlpha = max(texColor.a, 0.00001); |
1395 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1718 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1396 texColor = colorMatrix * texColor + colorOffset; | 1719 texColor = colorMatrix * texColor + colorOffset; |
1397 texColor.rgb *= texColor.a; | 1720 texColor.rgb *= texColor.a; |
1398 texColor = clamp(texColor, 0.0, 1.0); | 1721 texColor = clamp(texColor, 0.0, 1.0); |
1399 TexCoordPrecision vec2 maskTexCoord = | 1722 TexCoordPrecision vec2 maskTexCoord = |
1400 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1723 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1401 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1724 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1402 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1725 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1403 gl_FragColor = texColor * alpha * maskColor.w; | 1726 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); |
1404 } | 1727 } |
1405 // clang-format off | 1728 // clang-format off |
1406 ); // NOLINT(whitespace/parens) | 1729 ); // NOLINT(whitespace/parens) |
1407 // clang-format on | 1730 // clang-format on |
1408 } | 1731 } |
1409 | 1732 |
1410 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 1733 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
1411 : y_texture_location_(-1), | 1734 : y_texture_location_(-1), |
1412 u_texture_location_(-1), | 1735 u_texture_location_(-1), |
1413 v_texture_location_(-1), | 1736 v_texture_location_(-1), |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1656 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1979 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1657 float picker = abs(coord.x - coord.y); // NOLINT | 1980 float picker = abs(coord.x - coord.y); // NOLINT |
1658 gl_FragColor = mix(color1, color2, picker) * alpha; | 1981 gl_FragColor = mix(color1, color2, picker) * alpha; |
1659 } | 1982 } |
1660 // clang-format off | 1983 // clang-format off |
1661 ); // NOLINT(whitespace/parens) | 1984 ); // NOLINT(whitespace/parens) |
1662 // clang-format on | 1985 // clang-format on |
1663 } | 1986 } |
1664 | 1987 |
1665 } // namespace cc | 1988 } // namespace cc |
OLD | NEW |