OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/output/shader.h" | 5 #include "cc/output/shader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 std::string VertexShaderVideoTransform::GetShaderBody() { | 734 std::string VertexShaderVideoTransform::GetShaderBody() { |
735 return SHADER0([]() { | 735 return SHADER0([]() { |
736 void main() { | 736 void main() { |
737 gl_Position = matrix * a_position; | 737 gl_Position = matrix * a_position; |
738 v_texCoord = | 738 v_texCoord = |
739 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 739 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
740 } | 740 } |
741 }); | 741 }); |
742 } | 742 } |
743 | 743 |
744 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" | 744 #define BLEND_MODE_UNIFORMS "s_backdropTexture", \ |
745 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 2 : 0) | 745 "s_originalBackdropTexture", \ |
746 "backdropRect" | |
747 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 3 : 0) | |
746 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ | 748 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ |
747 if (has_blend_mode()) { \ | 749 if (has_blend_mode()) { \ |
748 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ | 750 DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \ |
749 backdrop_location_ = locations[POS]; \ | 751 backdrop_location_ = locations[POS]; \ |
750 backdrop_rect_location_ = locations[POS + 1]; \ | 752 original_backdrop_location_ = locations[POS + 1]; \ |
753 backdrop_rect_location_ = locations[POS + 2]; \ | |
751 } | 754 } |
752 | 755 |
753 FragmentTexBlendMode::FragmentTexBlendMode() | 756 FragmentTexBlendMode::FragmentTexBlendMode() |
754 : backdrop_location_(-1), | 757 : backdrop_location_(-1), |
758 original_backdrop_location_(-1), | |
755 backdrop_rect_location_(-1), | 759 backdrop_rect_location_(-1), |
756 blend_mode_(BLEND_MODE_NONE) { | 760 blend_mode_(BLEND_MODE_NONE), |
761 mask_for_background_(false) { | |
757 } | 762 } |
758 | 763 |
759 std::string FragmentTexBlendMode::SetBlendModeFunctions( | 764 std::string FragmentTexBlendMode::SetBlendModeFunctions( |
760 std::string shader_string) const { | 765 std::string shader_string) const { |
761 if (shader_string.find("ApplyBlendMode") == std::string::npos) | 766 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
762 return shader_string; | 767 return shader_string; |
763 | 768 |
764 if (!has_blend_mode()) { | 769 if (!has_blend_mode()) { |
765 return "#define ApplyBlendMode(X) (X)\n" + shader_string; | 770 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; |
766 } | 771 } |
767 | 772 |
768 static const std::string kFunctionApplyBlendMode = SHADER0([]() { | 773 static const std::string kFunctionApplyBlendMode = SHADER0([]() { |
769 uniform sampler2D s_backdropTexture; | 774 uniform sampler2D s_backdropTexture; |
775 uniform sampler2D s_originalBackdropTexture; | |
770 uniform TexCoordPrecision vec4 backdropRect; | 776 uniform TexCoordPrecision vec4 backdropRect; |
771 | 777 |
772 vec4 GetBackdropColor() { | 778 vec4 GetBackdropColor(float mask) { |
773 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; | 779 TexCoordPrecision vec2 bgTexCoord = gl_FragCoord.xy - backdropRect.xy; |
774 bgTexCoord.x /= backdropRect.z; | 780 bgTexCoord.x /= backdropRect.z; |
775 bgTexCoord.y /= backdropRect.w; | 781 bgTexCoord.y /= backdropRect.w; }) + |
776 return texture2D(s_backdropTexture, bgTexCoord); | 782 (mask_for_background() |
777 } | 783 ? SHADER0([]() { |
enne (OOO)
2015/03/04 19:58:44
This is super hard to read. Can you put the two b
| |
778 | 784 vec4 backdrop = texture2D(s_backdropTexture, bgTexCoord); |
779 vec4 ApplyBlendMode(vec4 src) { | 785 vec4 original_backdrop = texture2D(s_originalBackdropTexture, bgTexCoord); |
780 vec4 dst = GetBackdropColor(); | 786 return mix(original_backdrop, backdrop, mask); } }) |
787 : SHADER0([]() { | |
788 return texture2D(s_backdropTexture, bgTexCoord); } }) ) + | |
789 SHADER0([]() { | |
790 vec4 ApplyBlendMode(vec4 src, float mask) { | |
791 vec4 dst = GetBackdropColor(mask); | |
781 return Blend(src, dst); | 792 return Blend(src, dst); |
782 } | 793 } |
783 }); | 794 }); |
784 | 795 |
785 return "precision mediump float;" + GetHelperFunctions() + | 796 return "precision mediump float;" + GetHelperFunctions() + |
786 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; | 797 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; |
787 } | 798 } |
788 | 799 |
789 std::string FragmentTexBlendMode::GetHelperFunctions() const { | 800 std::string FragmentTexBlendMode::GetHelperFunctions() const { |
790 static const std::string kFunctionHardLight = SHADER0([]() { | 801 static const std::string kFunctionHardLight = SHADER0([]() { |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1112 varying TexCoordPrecision vec2 v_texCoord; | 1123 varying TexCoordPrecision vec2 v_texCoord; |
1113 uniform SamplerType s_texture; | 1124 uniform SamplerType s_texture; |
1114 uniform float alpha; | 1125 uniform float alpha; |
1115 }); | 1126 }); |
1116 } | 1127 } |
1117 | 1128 |
1118 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { | 1129 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { |
1119 return SHADER0([]() { | 1130 return SHADER0([]() { |
1120 void main() { | 1131 void main() { |
1121 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1132 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1122 gl_FragColor = ApplyBlendMode(texColor * alpha); | 1133 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); |
1123 } | 1134 } |
1124 }); | 1135 }); |
1125 } | 1136 } |
1126 | 1137 |
1127 void FragmentShaderRGBATexAlpha::FillLocations( | 1138 void FragmentShaderRGBATexAlpha::FillLocations( |
1128 ShaderLocations* locations) const { | 1139 ShaderLocations* locations) const { |
1129 locations->sampler = sampler_location(); | 1140 locations->sampler = sampler_location(); |
1130 locations->alpha = alpha_location(); | 1141 locations->alpha = alpha_location(); |
1131 locations->backdrop = backdrop_location(); | 1142 locations->backdrop = backdrop_location(); |
1132 locations->backdrop_rect = backdrop_rect_location(); | 1143 locations->backdrop_rect = backdrop_rect_location(); |
(...skipping 18 matching lines...) Expand all Loading... | |
1151 | 1162 |
1152 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() { | 1163 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() { |
1153 return SHADER0([]() { | 1164 return SHADER0([]() { |
1154 void main() { | 1165 void main() { |
1155 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1166 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1156 float nonZeroAlpha = max(texColor.a, 0.00001); | 1167 float nonZeroAlpha = max(texColor.a, 0.00001); |
1157 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1168 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1158 texColor = colorMatrix * texColor + colorOffset; | 1169 texColor = colorMatrix * texColor + colorOffset; |
1159 texColor.rgb *= texColor.a; | 1170 texColor.rgb *= texColor.a; |
1160 texColor = clamp(texColor, 0.0, 1.0); | 1171 texColor = clamp(texColor, 0.0, 1.0); |
1161 gl_FragColor = ApplyBlendMode(texColor * alpha); | 1172 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); |
1162 } | 1173 } |
1163 }); | 1174 }); |
1164 } | 1175 } |
1165 | 1176 |
1166 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( | 1177 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( |
1167 ShaderLocations* locations) const { | 1178 ShaderLocations* locations) const { |
1168 locations->sampler = sampler_location(); | 1179 locations->sampler = sampler_location(); |
1169 locations->alpha = alpha_location(); | 1180 locations->alpha = alpha_location(); |
1170 locations->color_matrix = color_matrix_location(); | 1181 locations->color_matrix = color_matrix_location(); |
1171 locations->color_offset = color_offset_location(); | 1182 locations->color_offset = color_offset_location(); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1430 }); | 1441 }); |
1431 } | 1442 } |
1432 | 1443 |
1433 std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() { | 1444 std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() { |
1434 return SHADER0([]() { | 1445 return SHADER0([]() { |
1435 void main() { | 1446 void main() { |
1436 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1447 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1437 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1448 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1438 vec2 d2 = min(d4.xz, d4.yw); | 1449 vec2 d2 = min(d4.xz, d4.yw); |
1439 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1450 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1440 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); | 1451 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); |
1441 } | 1452 } |
1442 }); | 1453 }); |
1443 } | 1454 } |
1444 | 1455 |
1445 void FragmentShaderRGBATexAlphaAA::FillLocations( | 1456 void FragmentShaderRGBATexAlphaAA::FillLocations( |
1446 ShaderLocations* locations) const { | 1457 ShaderLocations* locations) const { |
1447 locations->sampler = sampler_location(); | 1458 locations->sampler = sampler_location(); |
1448 locations->alpha = alpha_location(); | 1459 locations->alpha = alpha_location(); |
1449 locations->backdrop = backdrop_location(); | 1460 locations->backdrop = backdrop_location(); |
1450 locations->backdrop_rect = backdrop_rect_location(); | 1461 locations->backdrop_rect = backdrop_rect_location(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1593 } | 1604 } |
1594 | 1605 |
1595 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { | 1606 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { |
1596 return SHADER0([]() { | 1607 return SHADER0([]() { |
1597 void main() { | 1608 void main() { |
1598 vec4 texColor = texture2D(s_texture, v_texCoord); | 1609 vec4 texColor = texture2D(s_texture, v_texCoord); |
1599 TexCoordPrecision vec2 maskTexCoord = | 1610 TexCoordPrecision vec2 maskTexCoord = |
1600 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1611 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1601 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1612 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1602 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1613 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1603 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); | 1614 gl_FragColor = ApplyBlendMode( |
1615 texColor * alpha * maskColor.w, maskColor.w); | |
1604 } | 1616 } |
1605 }); | 1617 }); |
1606 } | 1618 } |
1607 | 1619 |
1608 void FragmentShaderRGBATexAlphaMask::FillLocations( | 1620 void FragmentShaderRGBATexAlphaMask::FillLocations( |
1609 ShaderLocations* locations) const { | 1621 ShaderLocations* locations) const { |
1610 locations->sampler = sampler_location(); | 1622 locations->sampler = sampler_location(); |
1611 locations->mask_sampler = mask_sampler_location(); | 1623 locations->mask_sampler = mask_sampler_location(); |
1612 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); | 1624 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
1613 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); | 1625 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
1614 locations->alpha = alpha_location(); | 1626 locations->alpha = alpha_location(); |
1615 locations->backdrop = backdrop_location(); | 1627 locations->backdrop = backdrop_location(); |
1616 locations->backdrop_rect = backdrop_rect_location(); | 1628 locations->backdrop_rect = backdrop_rect_location(); |
1629 if (mask_for_background()) | |
1630 locations->original_backdrop = original_backdrop_location(); | |
1617 } | 1631 } |
1618 | 1632 |
1619 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() | 1633 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA() |
1620 : sampler_location_(-1), | 1634 : sampler_location_(-1), |
1621 mask_sampler_location_(-1), | 1635 mask_sampler_location_(-1), |
1622 alpha_location_(-1), | 1636 alpha_location_(-1), |
1623 mask_tex_coord_scale_location_(-1), | 1637 mask_tex_coord_scale_location_(-1), |
1624 mask_tex_coord_offset_location_(-1) { | 1638 mask_tex_coord_offset_location_(-1) { |
1625 } | 1639 } |
1626 | 1640 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1674 return SHADER0([]() { | 1688 return SHADER0([]() { |
1675 void main() { | 1689 void main() { |
1676 vec4 texColor = texture2D(s_texture, v_texCoord); | 1690 vec4 texColor = texture2D(s_texture, v_texCoord); |
1677 TexCoordPrecision vec2 maskTexCoord = | 1691 TexCoordPrecision vec2 maskTexCoord = |
1678 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1692 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1679 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1693 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1680 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1694 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1681 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1695 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1682 vec2 d2 = min(d4.xz, d4.yw); | 1696 vec2 d2 = min(d4.xz, d4.yw); |
1683 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1697 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1684 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); | 1698 gl_FragColor = ApplyBlendMode( |
1699 texColor * alpha * maskColor.w * aa, maskColor.w); | |
1685 } | 1700 } |
1686 }); | 1701 }); |
1687 } | 1702 } |
1688 | 1703 |
1689 void FragmentShaderRGBATexAlphaMaskAA::FillLocations( | 1704 void FragmentShaderRGBATexAlphaMaskAA::FillLocations( |
1690 ShaderLocations* locations) const { | 1705 ShaderLocations* locations) const { |
1691 locations->sampler = sampler_location(); | 1706 locations->sampler = sampler_location(); |
1692 locations->mask_sampler = mask_sampler_location(); | 1707 locations->mask_sampler = mask_sampler_location(); |
1693 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); | 1708 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
1694 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); | 1709 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
1695 locations->alpha = alpha_location(); | 1710 locations->alpha = alpha_location(); |
1696 locations->backdrop = backdrop_location(); | 1711 locations->backdrop = backdrop_location(); |
1697 locations->backdrop_rect = backdrop_rect_location(); | 1712 locations->backdrop_rect = backdrop_rect_location(); |
1713 if (mask_for_background()) | |
1714 locations->original_backdrop = original_backdrop_location(); | |
1698 } | 1715 } |
1699 | 1716 |
1700 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: | 1717 FragmentShaderRGBATexAlphaMaskColorMatrixAA:: |
1701 FragmentShaderRGBATexAlphaMaskColorMatrixAA() | 1718 FragmentShaderRGBATexAlphaMaskColorMatrixAA() |
1702 : sampler_location_(-1), | 1719 : sampler_location_(-1), |
1703 mask_sampler_location_(-1), | 1720 mask_sampler_location_(-1), |
1704 alpha_location_(-1), | 1721 alpha_location_(-1), |
1705 mask_tex_coord_scale_location_(-1), | 1722 mask_tex_coord_scale_location_(-1), |
1706 color_matrix_location_(-1), | 1723 color_matrix_location_(-1), |
1707 color_offset_location_(-1) { | 1724 color_offset_location_(-1) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1769 texColor = colorMatrix * texColor + colorOffset; | 1786 texColor = colorMatrix * texColor + colorOffset; |
1770 texColor.rgb *= texColor.a; | 1787 texColor.rgb *= texColor.a; |
1771 texColor = clamp(texColor, 0.0, 1.0); | 1788 texColor = clamp(texColor, 0.0, 1.0); |
1772 TexCoordPrecision vec2 maskTexCoord = | 1789 TexCoordPrecision vec2 maskTexCoord = |
1773 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1790 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1774 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1791 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1775 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1792 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1776 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1793 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1777 vec2 d2 = min(d4.xz, d4.yw); | 1794 vec2 d2 = min(d4.xz, d4.yw); |
1778 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1795 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1779 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w * aa); | 1796 gl_FragColor = ApplyBlendMode( |
1797 texColor * alpha * maskColor.w * aa, maskColor.w); | |
1780 } | 1798 } |
1781 }); | 1799 }); |
1782 } | 1800 } |
1783 | 1801 |
1784 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations( | 1802 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations( |
1785 ShaderLocations* locations) const { | 1803 ShaderLocations* locations) const { |
1786 locations->sampler = sampler_location(); | 1804 locations->sampler = sampler_location(); |
1787 locations->alpha = alpha_location(); | 1805 locations->alpha = alpha_location(); |
1788 locations->mask_sampler = mask_sampler_location(); | 1806 locations->mask_sampler = mask_sampler_location(); |
1789 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); | 1807 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
1790 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); | 1808 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
1791 locations->color_matrix = color_matrix_location(); | 1809 locations->color_matrix = color_matrix_location(); |
1792 locations->color_offset = color_offset_location(); | 1810 locations->color_offset = color_offset_location(); |
1793 locations->backdrop = backdrop_location(); | 1811 locations->backdrop = backdrop_location(); |
1794 locations->backdrop_rect = backdrop_rect_location(); | 1812 locations->backdrop_rect = backdrop_rect_location(); |
1813 if (mask_for_background()) | |
1814 locations->original_backdrop = original_backdrop_location(); | |
1795 } | 1815 } |
1796 | 1816 |
1797 FragmentShaderRGBATexAlphaColorMatrixAA:: | 1817 FragmentShaderRGBATexAlphaColorMatrixAA:: |
1798 FragmentShaderRGBATexAlphaColorMatrixAA() | 1818 FragmentShaderRGBATexAlphaColorMatrixAA() |
1799 : sampler_location_(-1), | 1819 : sampler_location_(-1), |
1800 alpha_location_(-1), | 1820 alpha_location_(-1), |
1801 color_matrix_location_(-1), | 1821 color_matrix_location_(-1), |
1802 color_offset_location_(-1) { | 1822 color_offset_location_(-1) { |
1803 } | 1823 } |
1804 | 1824 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1846 void main() { | 1866 void main() { |
1847 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1867 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1848 float nonZeroAlpha = max(texColor.a, 0.00001); | 1868 float nonZeroAlpha = max(texColor.a, 0.00001); |
1849 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1869 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1850 texColor = colorMatrix * texColor + colorOffset; | 1870 texColor = colorMatrix * texColor + colorOffset; |
1851 texColor.rgb *= texColor.a; | 1871 texColor.rgb *= texColor.a; |
1852 texColor = clamp(texColor, 0.0, 1.0); | 1872 texColor = clamp(texColor, 0.0, 1.0); |
1853 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1873 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1854 vec2 d2 = min(d4.xz, d4.yw); | 1874 vec2 d2 = min(d4.xz, d4.yw); |
1855 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1875 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1856 gl_FragColor = ApplyBlendMode(texColor * alpha * aa); | 1876 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); |
1857 } | 1877 } |
1858 }); | 1878 }); |
1859 } | 1879 } |
1860 | 1880 |
1861 void FragmentShaderRGBATexAlphaColorMatrixAA::FillLocations( | 1881 void FragmentShaderRGBATexAlphaColorMatrixAA::FillLocations( |
1862 ShaderLocations* locations) const { | 1882 ShaderLocations* locations) const { |
1863 locations->sampler = sampler_location(); | 1883 locations->sampler = sampler_location(); |
1864 locations->alpha = alpha_location(); | 1884 locations->alpha = alpha_location(); |
1865 locations->color_matrix = color_matrix_location(); | 1885 locations->color_matrix = color_matrix_location(); |
1866 locations->color_offset = color_offset_location(); | 1886 locations->color_offset = color_offset_location(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1933 vec4 texColor = texture2D(s_texture, v_texCoord); | 1953 vec4 texColor = texture2D(s_texture, v_texCoord); |
1934 float nonZeroAlpha = max(texColor.a, 0.00001); | 1954 float nonZeroAlpha = max(texColor.a, 0.00001); |
1935 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1955 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1936 texColor = colorMatrix * texColor + colorOffset; | 1956 texColor = colorMatrix * texColor + colorOffset; |
1937 texColor.rgb *= texColor.a; | 1957 texColor.rgb *= texColor.a; |
1938 texColor = clamp(texColor, 0.0, 1.0); | 1958 texColor = clamp(texColor, 0.0, 1.0); |
1939 TexCoordPrecision vec2 maskTexCoord = | 1959 TexCoordPrecision vec2 maskTexCoord = |
1940 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1960 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1941 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1961 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1942 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1962 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1943 gl_FragColor = ApplyBlendMode(texColor * alpha * maskColor.w); | 1963 gl_FragColor = ApplyBlendMode( |
1964 texColor * alpha * maskColor.w, maskColor.w); | |
1944 } | 1965 } |
1945 }); | 1966 }); |
1946 } | 1967 } |
1947 | 1968 |
1948 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations( | 1969 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations( |
1949 ShaderLocations* locations) const { | 1970 ShaderLocations* locations) const { |
1950 locations->sampler = sampler_location(); | 1971 locations->sampler = sampler_location(); |
1951 locations->mask_sampler = mask_sampler_location(); | 1972 locations->mask_sampler = mask_sampler_location(); |
1952 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); | 1973 locations->mask_tex_coord_scale = mask_tex_coord_scale_location(); |
1953 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); | 1974 locations->mask_tex_coord_offset = mask_tex_coord_offset_location(); |
1954 locations->alpha = alpha_location(); | 1975 locations->alpha = alpha_location(); |
1955 locations->color_matrix = color_matrix_location(); | 1976 locations->color_matrix = color_matrix_location(); |
1956 locations->color_offset = color_offset_location(); | 1977 locations->color_offset = color_offset_location(); |
1957 locations->backdrop = backdrop_location(); | 1978 locations->backdrop = backdrop_location(); |
1958 locations->backdrop_rect = backdrop_rect_location(); | 1979 locations->backdrop_rect = backdrop_rect_location(); |
1980 if (mask_for_background()) | |
1981 locations->original_backdrop = original_backdrop_location(); | |
1959 } | 1982 } |
1960 | 1983 |
1961 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 1984 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
1962 : y_texture_location_(-1), | 1985 : y_texture_location_(-1), |
1963 u_texture_location_(-1), | 1986 u_texture_location_(-1), |
1964 v_texture_location_(-1), | 1987 v_texture_location_(-1), |
1965 alpha_location_(-1), | 1988 alpha_location_(-1), |
1966 yuv_matrix_location_(-1), | 1989 yuv_matrix_location_(-1), |
1967 yuv_adj_location_(-1), | 1990 yuv_adj_location_(-1), |
1968 clamp_rect_location_(-1) { | 1991 clamp_rect_location_(-1) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2243 vec2 texCoord = | 2266 vec2 texCoord = |
2244 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 2267 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
2245 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 2268 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
2246 float picker = abs(coord.x - coord.y); // NOLINT | 2269 float picker = abs(coord.x - coord.y); // NOLINT |
2247 gl_FragColor = mix(color1, color2, picker) * alpha; | 2270 gl_FragColor = mix(color1, color2, picker) * alpha; |
2248 } | 2271 } |
2249 }); | 2272 }); |
2250 } | 2273 } |
2251 | 2274 |
2252 } // namespace cc | 2275 } // namespace cc |
OLD | NEW |