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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 "String passed to StripLambda must be at least 8 characters"); | 22 "String passed to StripLambda must be at least 8 characters"); |
23 DCHECK_EQ(strncmp("[]() {", shader, 6), 0); | 23 DCHECK_EQ(strncmp("[]() {", shader, 6), 0); |
24 DCHECK_EQ(shader[size - 2], '}'); | 24 DCHECK_EQ(shader[size - 2], '}'); |
25 return std::string(shader + 6, shader + size - 2); | 25 return std::string(shader + 6, shader + size - 2); |
26 } | 26 } |
27 | 27 |
28 // Shaders are passed in with lambda syntax, which tricks clang-format into | 28 // Shaders are passed in with lambda syntax, which tricks clang-format into |
29 // handling them correctly. StipLambda removes this. | 29 // handling them correctly. StipLambda removes this. |
30 #define SHADER0(Src) StripLambda(#Src) | 30 #define SHADER0(Src) StripLambda(#Src) |
31 #define VERTEX_SHADER(Head, Body) SetVertexShaderDefines(Head + Body) | 31 #define VERTEX_SHADER(Head, Body) SetVertexShaderDefines(Head + Body) |
32 #define FRAGMENT_SHADER(Head, Body) \ | |
33 SetFragmentTexCoordPrecision( \ | |
34 precision, \ | |
35 SetFragmentSamplerType(sampler, SetBlendModeFunctions(Head + Body))) | |
36 | 32 |
37 using gpu::gles2::GLES2Interface; | 33 using gpu::gles2::GLES2Interface; |
38 | 34 |
39 namespace cc { | 35 namespace cc { |
40 | 36 |
41 namespace { | 37 namespace { |
42 | 38 |
43 static void GetProgramUniformLocations(GLES2Interface* context, | 39 static void GetProgramUniformLocations(GLES2Interface* context, |
44 unsigned program, | 40 unsigned program, |
45 size_t count, | 41 size_t count, |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 "backdropRect" | 758 "backdropRect" |
763 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 3 : 0) | 759 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 3 : 0) |
764 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ | 760 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ |
765 if (has_blend_mode()) { \ | 761 if (has_blend_mode()) { \ |
766 DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \ | 762 DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \ |
767 backdrop_location_ = locations[POS]; \ | 763 backdrop_location_ = locations[POS]; \ |
768 original_backdrop_location_ = locations[POS + 1]; \ | 764 original_backdrop_location_ = locations[POS + 1]; \ |
769 backdrop_rect_location_ = locations[POS + 2]; \ | 765 backdrop_rect_location_ = locations[POS + 2]; \ |
770 } | 766 } |
771 | 767 |
772 FragmentTexBlendMode::FragmentTexBlendMode() | 768 FragmentShaderBase::FragmentShaderBase() |
773 : backdrop_location_(-1), | 769 : backdrop_location_(-1), |
774 original_backdrop_location_(-1), | 770 original_backdrop_location_(-1), |
775 backdrop_rect_location_(-1), | 771 backdrop_rect_location_(-1), |
776 blend_mode_(BLEND_MODE_NONE), | 772 blend_mode_(BLEND_MODE_NONE), |
777 mask_for_background_(false) { | 773 mask_for_background_(false) {} |
| 774 |
| 775 std::string FragmentShaderBase::GetShaderString(TexCoordPrecision precision, |
| 776 SamplerType sampler) const { |
| 777 return SetFragmentTexCoordPrecision( |
| 778 precision, SetFragmentSamplerType( |
| 779 sampler, SetBlendModeFunctions(GetShaderSource()))); |
778 } | 780 } |
779 | 781 |
780 std::string FragmentTexBlendMode::SetBlendModeFunctions( | 782 std::string FragmentShaderBase::SetBlendModeFunctions( |
781 const std::string& shader_string) const { | 783 const std::string& shader_string) const { |
782 if (shader_string.find("ApplyBlendMode") == std::string::npos) | 784 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
783 return shader_string; | 785 return shader_string; |
784 | 786 |
785 if (!has_blend_mode()) { | 787 if (!has_blend_mode()) { |
786 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; | 788 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; |
787 } | 789 } |
788 | 790 |
789 static const std::string kUniforms = SHADER0([]() { | 791 static const std::string kUniforms = SHADER0([]() { |
790 uniform sampler2D s_backdropTexture; | 792 uniform sampler2D s_backdropTexture; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 vec4 dst = GetBackdropColor(mask); | 824 vec4 dst = GetBackdropColor(mask); |
823 return Blend(src, dst); | 825 return Blend(src, dst); |
824 } | 826 } |
825 }); | 827 }); |
826 | 828 |
827 return "precision mediump float;" + GetHelperFunctions() + | 829 return "precision mediump float;" + GetHelperFunctions() + |
828 GetBlendFunction() + kUniforms + mixFunction + | 830 GetBlendFunction() + kUniforms + mixFunction + |
829 kFunctionApplyBlendMode + shader_string; | 831 kFunctionApplyBlendMode + shader_string; |
830 } | 832 } |
831 | 833 |
832 std::string FragmentTexBlendMode::GetHelperFunctions() const { | 834 std::string FragmentShaderBase::GetHelperFunctions() const { |
833 static const std::string kFunctionHardLight = SHADER0([]() { | 835 static const std::string kFunctionHardLight = SHADER0([]() { |
834 vec3 hardLight(vec4 src, vec4 dst) { | 836 vec3 hardLight(vec4 src, vec4 dst) { |
835 vec3 result; | 837 vec3 result; |
836 result.r = | 838 result.r = |
837 (2.0 * src.r <= src.a) | 839 (2.0 * src.r <= src.a) |
838 ? (2.0 * src.r * dst.r) | 840 ? (2.0 * src.r * dst.r) |
839 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); | 841 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); |
840 result.g = | 842 result.g = |
841 (2.0 * src.g <= src.a) | 843 (2.0 * src.g <= src.a) |
842 ? (2.0 * src.g * dst.g) | 844 ? (2.0 * src.g * dst.g) |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 case BLEND_MODE_SATURATION: | 985 case BLEND_MODE_SATURATION: |
984 return kFunctionLum + kFunctionSat; | 986 return kFunctionLum + kFunctionSat; |
985 case BLEND_MODE_COLOR: | 987 case BLEND_MODE_COLOR: |
986 case BLEND_MODE_LUMINOSITY: | 988 case BLEND_MODE_LUMINOSITY: |
987 return kFunctionLum; | 989 return kFunctionLum; |
988 default: | 990 default: |
989 return std::string(); | 991 return std::string(); |
990 } | 992 } |
991 } | 993 } |
992 | 994 |
993 std::string FragmentTexBlendMode::GetBlendFunction() const { | 995 std::string FragmentShaderBase::GetBlendFunction() const { |
994 return "vec4 Blend(vec4 src, vec4 dst) {" | 996 return "vec4 Blend(vec4 src, vec4 dst) {" |
995 " vec4 result;" | 997 " vec4 result;" |
996 " result.a = src.a + (1.0 - src.a) * dst.a;" + | 998 " result.a = src.a + (1.0 - src.a) * dst.a;" + |
997 GetBlendFunctionBodyForRGB() + | 999 GetBlendFunctionBodyForRGB() + |
998 " return result;" | 1000 " return result;" |
999 "}"; | 1001 "}"; |
1000 } | 1002 } |
1001 | 1003 |
1002 std::string FragmentTexBlendMode::GetBlendFunctionBodyForRGB() const { | 1004 std::string FragmentShaderBase::GetBlendFunctionBodyForRGB() const { |
1003 switch (blend_mode_) { | 1005 switch (blend_mode_) { |
1004 case BLEND_MODE_NORMAL: | 1006 case BLEND_MODE_NORMAL: |
1005 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);"; | 1007 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);"; |
1006 case BLEND_MODE_SCREEN: | 1008 case BLEND_MODE_SCREEN: |
1007 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;"; | 1009 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;"; |
1008 case BLEND_MODE_LIGHTEN: | 1010 case BLEND_MODE_LIGHTEN: |
1009 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," | 1011 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," |
1010 " (1.0 - dst.a) * src.rgb + dst.rgb);"; | 1012 " (1.0 - dst.a) * src.rgb + dst.rgb);"; |
1011 case BLEND_MODE_OVERLAY: | 1013 case BLEND_MODE_OVERLAY: |
1012 return "result.rgb = hardLight(dst, src);"; | 1014 return "result.rgb = hardLight(dst, src);"; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 | 1138 |
1137 GetProgramUniformLocations(context, | 1139 GetProgramUniformLocations(context, |
1138 program, | 1140 program, |
1139 arraysize(uniforms), | 1141 arraysize(uniforms), |
1140 uniforms, | 1142 uniforms, |
1141 locations, | 1143 locations, |
1142 base_uniform_index); | 1144 base_uniform_index); |
1143 sampler_location_ = locations[0]; | 1145 sampler_location_ = locations[0]; |
1144 } | 1146 } |
1145 | 1147 |
1146 std::string FragmentShaderRGBATexAlpha::GetShaderString( | 1148 std::string FragmentShaderRGBATexAlpha::GetShaderSource() const { |
1147 TexCoordPrecision precision, | |
1148 SamplerType sampler) const { | |
1149 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1150 } | |
1151 | |
1152 std::string FragmentShaderRGBATexAlpha::GetShaderHead() { | |
1153 return SHADER0([]() { | 1149 return SHADER0([]() { |
1154 precision mediump float; | 1150 precision mediump float; |
1155 varying TexCoordPrecision vec2 v_texCoord; | 1151 varying TexCoordPrecision vec2 v_texCoord; |
1156 uniform SamplerType s_texture; | 1152 uniform SamplerType s_texture; |
1157 uniform float alpha; | 1153 uniform float alpha; |
1158 }); | |
1159 } | |
1160 | |
1161 std::string FragmentShaderRGBATexAlpha::GetShaderBody() { | |
1162 return SHADER0([]() { | |
1163 void main() { | 1154 void main() { |
1164 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1155 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1165 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); | 1156 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); |
1166 } | 1157 } |
1167 }); | 1158 }); |
1168 } | 1159 } |
1169 | 1160 |
1170 void FragmentShaderRGBATexAlpha::FillLocations( | 1161 void FragmentShaderRGBATexAlpha::FillLocations( |
1171 ShaderLocations* locations) const { | 1162 ShaderLocations* locations) const { |
1172 locations->sampler = sampler_location(); | 1163 locations->sampler = sampler_location(); |
1173 locations->alpha = alpha_location(); | 1164 locations->alpha = alpha_location(); |
1174 locations->backdrop = backdrop_location(); | 1165 locations->backdrop = backdrop_location(); |
1175 locations->backdrop_rect = backdrop_rect_location(); | 1166 locations->backdrop_rect = backdrop_rect_location(); |
1176 } | 1167 } |
1177 | 1168 |
1178 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderString( | 1169 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderSource() const { |
1179 TexCoordPrecision precision, | |
1180 SamplerType sampler) const { | |
1181 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1182 } | |
1183 | |
1184 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderHead() { | |
1185 return SHADER0([]() { | 1170 return SHADER0([]() { |
1186 precision mediump float; | 1171 precision mediump float; |
1187 varying TexCoordPrecision vec2 v_texCoord; | 1172 varying TexCoordPrecision vec2 v_texCoord; |
1188 uniform SamplerType s_texture; | 1173 uniform SamplerType s_texture; |
1189 uniform float alpha; | 1174 uniform float alpha; |
1190 uniform mat4 colorMatrix; | 1175 uniform mat4 colorMatrix; |
1191 uniform vec4 colorOffset; | 1176 uniform vec4 colorOffset; |
1192 }); | |
1193 } | |
1194 | |
1195 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderBody() { | |
1196 return SHADER0([]() { | |
1197 void main() { | 1177 void main() { |
1198 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1178 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1199 float nonZeroAlpha = max(texColor.a, 0.00001); | 1179 float nonZeroAlpha = max(texColor.a, 0.00001); |
1200 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1180 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1201 texColor = colorMatrix * texColor + colorOffset; | 1181 texColor = colorMatrix * texColor + colorOffset; |
1202 texColor.rgb *= texColor.a; | 1182 texColor.rgb *= texColor.a; |
1203 texColor = clamp(texColor, 0.0, 1.0); | 1183 texColor = clamp(texColor, 0.0, 1.0); |
1204 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); | 1184 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); |
1205 } | 1185 } |
1206 }); | 1186 }); |
1207 } | 1187 } |
1208 | 1188 |
1209 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( | 1189 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations( |
1210 ShaderLocations* locations) const { | 1190 ShaderLocations* locations) const { |
1211 locations->sampler = sampler_location(); | 1191 locations->sampler = sampler_location(); |
1212 locations->alpha = alpha_location(); | 1192 locations->alpha = alpha_location(); |
1213 locations->color_matrix = color_matrix_location(); | 1193 locations->color_matrix = color_matrix_location(); |
1214 locations->color_offset = color_offset_location(); | 1194 locations->color_offset = color_offset_location(); |
1215 locations->backdrop = backdrop_location(); | 1195 locations->backdrop = backdrop_location(); |
1216 locations->backdrop_rect = backdrop_rect_location(); | 1196 locations->backdrop_rect = backdrop_rect_location(); |
1217 } | 1197 } |
1218 | 1198 |
1219 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderString( | 1199 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderSource() const { |
1220 TexCoordPrecision precision, | |
1221 SamplerType sampler) const { | |
1222 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1223 } | |
1224 | |
1225 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderHead() { | |
1226 return SHADER0([]() { | 1200 return SHADER0([]() { |
1227 precision mediump float; | 1201 precision mediump float; |
1228 varying TexCoordPrecision vec2 v_texCoord; | 1202 varying TexCoordPrecision vec2 v_texCoord; |
1229 varying float v_alpha; | 1203 varying float v_alpha; |
1230 uniform SamplerType s_texture; | 1204 uniform SamplerType s_texture; |
1231 }); | |
1232 } | |
1233 | |
1234 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderBody() { | |
1235 return SHADER0([]() { | |
1236 void main() { | 1205 void main() { |
1237 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1206 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1238 gl_FragColor = texColor * v_alpha; | 1207 gl_FragColor = texColor * v_alpha; |
1239 } | 1208 } |
1240 }); | 1209 }); |
1241 } | 1210 } |
1242 | 1211 |
1243 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderString( | 1212 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderSource() const { |
1244 TexCoordPrecision precision, | |
1245 SamplerType sampler) const { | |
1246 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1247 } | |
1248 | |
1249 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderHead() { | |
1250 return SHADER0([]() { | 1213 return SHADER0([]() { |
1251 precision mediump float; | 1214 precision mediump float; |
1252 varying TexCoordPrecision vec2 v_texCoord; | 1215 varying TexCoordPrecision vec2 v_texCoord; |
1253 varying float v_alpha; | 1216 varying float v_alpha; |
1254 uniform SamplerType s_texture; | 1217 uniform SamplerType s_texture; |
1255 }); | |
1256 } | |
1257 | |
1258 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderBody() { | |
1259 return SHADER0([]() { | |
1260 void main() { | 1218 void main() { |
1261 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1219 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1262 texColor.rgb *= texColor.a; | 1220 texColor.rgb *= texColor.a; |
1263 gl_FragColor = texColor * v_alpha; | 1221 gl_FragColor = texColor * v_alpha; |
1264 } | 1222 } |
1265 }); | 1223 }); |
1266 } | 1224 } |
1267 | 1225 |
1268 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() | 1226 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding() |
1269 : background_color_location_(-1), sampler_location_(-1) { | 1227 : background_color_location_(-1), sampler_location_(-1) { |
(...skipping 14 matching lines...) Expand all Loading... |
1284 locations, | 1242 locations, |
1285 base_uniform_index); | 1243 base_uniform_index); |
1286 | 1244 |
1287 sampler_location_ = locations[0]; | 1245 sampler_location_ = locations[0]; |
1288 DCHECK_NE(sampler_location_, -1); | 1246 DCHECK_NE(sampler_location_, -1); |
1289 | 1247 |
1290 background_color_location_ = locations[1]; | 1248 background_color_location_ = locations[1]; |
1291 DCHECK_NE(background_color_location_, -1); | 1249 DCHECK_NE(background_color_location_, -1); |
1292 } | 1250 } |
1293 | 1251 |
1294 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderString( | 1252 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderSource() const { |
1295 TexCoordPrecision precision, | |
1296 SamplerType sampler) const { | |
1297 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1298 } | |
1299 | |
1300 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderHead() { | |
1301 return SHADER0([]() { | 1253 return SHADER0([]() { |
1302 precision mediump float; | 1254 precision mediump float; |
1303 varying TexCoordPrecision vec2 v_texCoord; | 1255 varying TexCoordPrecision vec2 v_texCoord; |
1304 varying float v_alpha; | 1256 varying float v_alpha; |
1305 uniform vec4 background_color; | 1257 uniform vec4 background_color; |
1306 uniform SamplerType s_texture; | 1258 uniform SamplerType s_texture; |
1307 }); | |
1308 } | |
1309 | |
1310 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderBody() { | |
1311 return SHADER0([]() { | |
1312 void main() { | 1259 void main() { |
1313 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1260 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1314 texColor += background_color * (1.0 - texColor.a); | 1261 texColor += background_color * (1.0 - texColor.a); |
1315 gl_FragColor = texColor * v_alpha; | 1262 gl_FragColor = texColor * v_alpha; |
1316 } | 1263 } |
1317 }); | 1264 }); |
1318 } | 1265 } |
1319 | 1266 |
1320 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderString( | 1267 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderSource() |
1321 TexCoordPrecision precision, | 1268 const { |
1322 SamplerType sampler) const { | |
1323 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1324 } | |
1325 | |
1326 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderHead() { | |
1327 return SHADER0([]() { | 1269 return SHADER0([]() { |
1328 precision mediump float; | 1270 precision mediump float; |
1329 varying TexCoordPrecision vec2 v_texCoord; | 1271 varying TexCoordPrecision vec2 v_texCoord; |
1330 varying float v_alpha; | 1272 varying float v_alpha; |
1331 uniform vec4 background_color; | 1273 uniform vec4 background_color; |
1332 uniform SamplerType s_texture; | 1274 uniform SamplerType s_texture; |
1333 }); | |
1334 } | |
1335 | |
1336 std::string FragmentShaderTexBackgroundPremultiplyAlpha::GetShaderBody() { | |
1337 return SHADER0([]() { | |
1338 void main() { | 1275 void main() { |
1339 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1276 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1340 texColor.rgb *= texColor.a; | 1277 texColor.rgb *= texColor.a; |
1341 texColor += background_color * (1.0 - texColor.a); | 1278 texColor += background_color * (1.0 - texColor.a); |
1342 gl_FragColor = texColor * v_alpha; | 1279 gl_FragColor = texColor * v_alpha; |
1343 } | 1280 } |
1344 }); | 1281 }); |
1345 } | 1282 } |
1346 | 1283 |
1347 std::string FragmentShaderRGBATexOpaque::GetShaderString( | 1284 std::string FragmentShaderRGBATexOpaque::GetShaderSource() const { |
1348 TexCoordPrecision precision, | |
1349 SamplerType sampler) const { | |
1350 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1351 } | |
1352 | |
1353 std::string FragmentShaderRGBATexOpaque::GetShaderHead() { | |
1354 return SHADER0([]() { | 1285 return SHADER0([]() { |
1355 precision mediump float; | 1286 precision mediump float; |
1356 varying TexCoordPrecision vec2 v_texCoord; | 1287 varying TexCoordPrecision vec2 v_texCoord; |
1357 uniform SamplerType s_texture; | 1288 uniform SamplerType s_texture; |
1358 }); | |
1359 } | |
1360 | |
1361 std::string FragmentShaderRGBATexOpaque::GetShaderBody() { | |
1362 return SHADER0([]() { | |
1363 void main() { | 1289 void main() { |
1364 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1290 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1365 gl_FragColor = vec4(texColor.rgb, 1.0); | 1291 gl_FragColor = vec4(texColor.rgb, 1.0); |
1366 } | 1292 } |
1367 }); | 1293 }); |
1368 } | 1294 } |
1369 | 1295 |
1370 std::string FragmentShaderRGBATex::GetShaderString(TexCoordPrecision precision, | 1296 std::string FragmentShaderRGBATex::GetShaderSource() const { |
1371 SamplerType sampler) const { | |
1372 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1373 } | |
1374 | |
1375 std::string FragmentShaderRGBATex::GetShaderHead() { | |
1376 return SHADER0([]() { | 1297 return SHADER0([]() { |
1377 precision mediump float; | 1298 precision mediump float; |
1378 varying TexCoordPrecision vec2 v_texCoord; | 1299 varying TexCoordPrecision vec2 v_texCoord; |
1379 uniform SamplerType s_texture; | 1300 uniform SamplerType s_texture; |
1380 }); | |
1381 } | |
1382 | |
1383 std::string FragmentShaderRGBATex::GetShaderBody() { | |
1384 return SHADER0([]() { | |
1385 void main() { gl_FragColor = TextureLookup(s_texture, v_texCoord); } | 1301 void main() { gl_FragColor = TextureLookup(s_texture, v_texCoord); } |
1386 }); | 1302 }); |
1387 } | 1303 } |
1388 | 1304 |
1389 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderString( | 1305 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderSource() const { |
1390 TexCoordPrecision precision, | |
1391 SamplerType sampler) const { | |
1392 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1393 } | |
1394 | |
1395 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderHead() { | |
1396 return SHADER0([]() { | 1306 return SHADER0([]() { |
1397 precision mediump float; | 1307 precision mediump float; |
1398 varying TexCoordPrecision vec2 v_texCoord; | 1308 varying TexCoordPrecision vec2 v_texCoord; |
1399 uniform SamplerType s_texture; | 1309 uniform SamplerType s_texture; |
1400 uniform float alpha; | 1310 uniform float alpha; |
1401 }); | |
1402 } | |
1403 | |
1404 std::string FragmentShaderRGBATexSwizzleAlpha::GetShaderBody() { | |
1405 return SHADER0([]() { | |
1406 void main() { | 1311 void main() { |
1407 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1312 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1408 gl_FragColor = | 1313 gl_FragColor = |
1409 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; | 1314 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha; |
1410 } | 1315 } |
1411 }); | 1316 }); |
1412 } | 1317 } |
1413 | 1318 |
1414 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderString( | 1319 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderSource() const { |
1415 TexCoordPrecision precision, | |
1416 SamplerType sampler) const { | |
1417 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1418 } | |
1419 | |
1420 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderHead() { | |
1421 return SHADER0([]() { | 1320 return SHADER0([]() { |
1422 precision mediump float; | 1321 precision mediump float; |
1423 varying TexCoordPrecision vec2 v_texCoord; | 1322 varying TexCoordPrecision vec2 v_texCoord; |
1424 uniform SamplerType s_texture; | 1323 uniform SamplerType s_texture; |
1425 }); | |
1426 } | |
1427 | |
1428 std::string FragmentShaderRGBATexSwizzleOpaque::GetShaderBody() { | |
1429 return SHADER0([]() { | |
1430 void main() { | 1324 void main() { |
1431 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1325 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1432 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); | 1326 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); |
1433 } | 1327 } |
1434 }); | 1328 }); |
1435 } | 1329 } |
1436 | 1330 |
1437 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() | 1331 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA() |
1438 : sampler_location_(-1), alpha_location_(-1) { | 1332 : sampler_location_(-1), alpha_location_(-1) { |
1439 } | 1333 } |
(...skipping 10 matching lines...) Expand all Loading... |
1450 program, | 1344 program, |
1451 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, | 1345 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS, |
1452 uniforms, | 1346 uniforms, |
1453 locations, | 1347 locations, |
1454 base_uniform_index); | 1348 base_uniform_index); |
1455 sampler_location_ = locations[0]; | 1349 sampler_location_ = locations[0]; |
1456 alpha_location_ = locations[1]; | 1350 alpha_location_ = locations[1]; |
1457 BLEND_MODE_SET_LOCATIONS(locations, 2); | 1351 BLEND_MODE_SET_LOCATIONS(locations, 2); |
1458 } | 1352 } |
1459 | 1353 |
1460 std::string FragmentShaderRGBATexAlphaAA::GetShaderString( | 1354 std::string FragmentShaderRGBATexAlphaAA::GetShaderSource() const { |
1461 TexCoordPrecision precision, | |
1462 SamplerType sampler) const { | |
1463 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1464 } | |
1465 | |
1466 std::string FragmentShaderRGBATexAlphaAA::GetShaderHead() { | |
1467 return SHADER0([]() { | 1355 return SHADER0([]() { |
1468 precision mediump float; | 1356 precision mediump float; |
1469 uniform SamplerType s_texture; | 1357 uniform SamplerType s_texture; |
1470 uniform float alpha; | 1358 uniform float alpha; |
1471 varying TexCoordPrecision vec2 v_texCoord; | 1359 varying TexCoordPrecision vec2 v_texCoord; |
1472 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1360 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1473 }); | |
1474 } | |
1475 | |
1476 std::string FragmentShaderRGBATexAlphaAA::GetShaderBody() { | |
1477 return SHADER0([]() { | |
1478 void main() { | 1361 void main() { |
1479 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1362 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1480 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1363 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1481 vec2 d2 = min(d4.xz, d4.yw); | 1364 vec2 d2 = min(d4.xz, d4.yw); |
1482 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1365 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1483 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); | 1366 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); |
1484 } | 1367 } |
1485 }); | 1368 }); |
1486 } | 1369 } |
1487 | 1370 |
(...skipping 23 matching lines...) Expand all Loading... |
1511 program, | 1394 program, |
1512 arraysize(uniforms), | 1395 arraysize(uniforms), |
1513 uniforms, | 1396 uniforms, |
1514 locations, | 1397 locations, |
1515 base_uniform_index); | 1398 base_uniform_index); |
1516 sampler_location_ = locations[0]; | 1399 sampler_location_ = locations[0]; |
1517 alpha_location_ = locations[1]; | 1400 alpha_location_ = locations[1]; |
1518 fragment_tex_transform_location_ = locations[2]; | 1401 fragment_tex_transform_location_ = locations[2]; |
1519 } | 1402 } |
1520 | 1403 |
1521 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderString( | 1404 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderSource() const { |
1522 TexCoordPrecision precision, | |
1523 SamplerType sampler) const { | |
1524 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1525 } | |
1526 | |
1527 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderHead() { | |
1528 return SHADER0([]() { | 1405 return SHADER0([]() { |
1529 precision mediump float; | 1406 precision mediump float; |
1530 uniform SamplerType s_texture; | 1407 uniform SamplerType s_texture; |
1531 uniform float alpha; | 1408 uniform float alpha; |
1532 uniform TexCoordPrecision vec4 fragmentTexTransform; | 1409 uniform TexCoordPrecision vec4 fragmentTexTransform; |
1533 varying TexCoordPrecision vec2 v_texCoord; | 1410 varying TexCoordPrecision vec2 v_texCoord; |
1534 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1411 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1535 }); | |
1536 } | |
1537 | |
1538 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderBody() { | |
1539 return SHADER0([]() { | |
1540 void main() { | 1412 void main() { |
1541 TexCoordPrecision vec2 texCoord = | 1413 TexCoordPrecision vec2 texCoord = |
1542 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 1414 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
1543 fragmentTexTransform.xy; | 1415 fragmentTexTransform.xy; |
1544 vec4 texColor = TextureLookup(s_texture, texCoord); | 1416 vec4 texColor = TextureLookup(s_texture, texCoord); |
1545 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1417 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1546 vec2 d2 = min(d4.xz, d4.yw); | 1418 vec2 d2 = min(d4.xz, d4.yw); |
1547 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1419 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1548 gl_FragColor = texColor * alpha * aa; | 1420 gl_FragColor = texColor * alpha * aa; |
1549 } | 1421 } |
1550 }); | 1422 }); |
1551 } | 1423 } |
1552 | 1424 |
1553 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderString( | 1425 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderSource() const { |
1554 TexCoordPrecision precision, | |
1555 SamplerType sampler) const { | |
1556 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1557 } | |
1558 | |
1559 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderHead() { | |
1560 return SHADER0([]() { | 1426 return SHADER0([]() { |
1561 precision mediump float; | 1427 precision mediump float; |
1562 uniform SamplerType s_texture; | 1428 uniform SamplerType s_texture; |
1563 uniform float alpha; | 1429 uniform float alpha; |
1564 uniform TexCoordPrecision vec4 fragmentTexTransform; | 1430 uniform TexCoordPrecision vec4 fragmentTexTransform; |
1565 varying TexCoordPrecision vec2 v_texCoord; | 1431 varying TexCoordPrecision vec2 v_texCoord; |
1566 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1432 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1567 }); | |
1568 } | |
1569 | |
1570 std::string FragmentShaderRGBATexClampSwizzleAlphaAA::GetShaderBody() { | |
1571 return SHADER0([]() { | |
1572 void main() { | 1433 void main() { |
1573 TexCoordPrecision vec2 texCoord = | 1434 TexCoordPrecision vec2 texCoord = |
1574 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + | 1435 clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw + |
1575 fragmentTexTransform.xy; | 1436 fragmentTexTransform.xy; |
1576 vec4 texColor = TextureLookup(s_texture, texCoord); | 1437 vec4 texColor = TextureLookup(s_texture, texCoord); |
1577 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1438 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1578 vec2 d2 = min(d4.xz, d4.yw); | 1439 vec2 d2 = min(d4.xz, d4.yw); |
1579 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1440 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1580 gl_FragColor = | 1441 gl_FragColor = |
1581 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * aa; | 1442 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * aa; |
(...skipping 28 matching lines...) Expand all Loading... |
1610 locations, | 1471 locations, |
1611 base_uniform_index); | 1472 base_uniform_index); |
1612 sampler_location_ = locations[0]; | 1473 sampler_location_ = locations[0]; |
1613 mask_sampler_location_ = locations[1]; | 1474 mask_sampler_location_ = locations[1]; |
1614 alpha_location_ = locations[2]; | 1475 alpha_location_ = locations[2]; |
1615 mask_tex_coord_scale_location_ = locations[3]; | 1476 mask_tex_coord_scale_location_ = locations[3]; |
1616 mask_tex_coord_offset_location_ = locations[4]; | 1477 mask_tex_coord_offset_location_ = locations[4]; |
1617 BLEND_MODE_SET_LOCATIONS(locations, 5); | 1478 BLEND_MODE_SET_LOCATIONS(locations, 5); |
1618 } | 1479 } |
1619 | 1480 |
1620 std::string FragmentShaderRGBATexAlphaMask::GetShaderString( | 1481 std::string FragmentShaderRGBATexAlphaMask::GetShaderSource() const { |
1621 TexCoordPrecision precision, | |
1622 SamplerType sampler) const { | |
1623 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1624 } | |
1625 | |
1626 std::string FragmentShaderRGBATexAlphaMask::GetShaderHead() { | |
1627 return SHADER0([]() { | 1482 return SHADER0([]() { |
1628 precision mediump float; | 1483 precision mediump float; |
1629 varying TexCoordPrecision vec2 v_texCoord; | 1484 varying TexCoordPrecision vec2 v_texCoord; |
1630 uniform sampler2D s_texture; | 1485 uniform sampler2D s_texture; |
1631 uniform SamplerType s_mask; | 1486 uniform SamplerType s_mask; |
1632 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1487 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1633 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1488 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1634 uniform float alpha; | 1489 uniform float alpha; |
1635 }); | |
1636 } | |
1637 | |
1638 std::string FragmentShaderRGBATexAlphaMask::GetShaderBody() { | |
1639 return SHADER0([]() { | |
1640 void main() { | 1490 void main() { |
1641 vec4 texColor = texture2D(s_texture, v_texCoord); | 1491 vec4 texColor = texture2D(s_texture, v_texCoord); |
1642 TexCoordPrecision vec2 maskTexCoord = | 1492 TexCoordPrecision vec2 maskTexCoord = |
1643 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1493 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1644 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1494 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1645 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1495 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1646 gl_FragColor = ApplyBlendMode( | 1496 gl_FragColor = ApplyBlendMode( |
1647 texColor * alpha * maskColor.w, maskColor.w); | 1497 texColor * alpha * maskColor.w, maskColor.w); |
1648 } | 1498 } |
1649 }); | 1499 }); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 locations, | 1540 locations, |
1691 base_uniform_index); | 1541 base_uniform_index); |
1692 sampler_location_ = locations[0]; | 1542 sampler_location_ = locations[0]; |
1693 mask_sampler_location_ = locations[1]; | 1543 mask_sampler_location_ = locations[1]; |
1694 alpha_location_ = locations[2]; | 1544 alpha_location_ = locations[2]; |
1695 mask_tex_coord_scale_location_ = locations[3]; | 1545 mask_tex_coord_scale_location_ = locations[3]; |
1696 mask_tex_coord_offset_location_ = locations[4]; | 1546 mask_tex_coord_offset_location_ = locations[4]; |
1697 BLEND_MODE_SET_LOCATIONS(locations, 5); | 1547 BLEND_MODE_SET_LOCATIONS(locations, 5); |
1698 } | 1548 } |
1699 | 1549 |
1700 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderString( | 1550 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderSource() const { |
1701 TexCoordPrecision precision, | |
1702 SamplerType sampler) const { | |
1703 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1704 } | |
1705 | |
1706 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderHead() { | |
1707 return SHADER0([]() { | 1551 return SHADER0([]() { |
1708 precision mediump float; | 1552 precision mediump float; |
1709 uniform sampler2D s_texture; | 1553 uniform sampler2D s_texture; |
1710 uniform SamplerType s_mask; | 1554 uniform SamplerType s_mask; |
1711 uniform TexCoordPrecision vec2 maskTexCoordScale; | 1555 uniform TexCoordPrecision vec2 maskTexCoordScale; |
1712 uniform TexCoordPrecision vec2 maskTexCoordOffset; | 1556 uniform TexCoordPrecision vec2 maskTexCoordOffset; |
1713 uniform float alpha; | 1557 uniform float alpha; |
1714 varying TexCoordPrecision vec2 v_texCoord; | 1558 varying TexCoordPrecision vec2 v_texCoord; |
1715 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1559 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1716 }); | |
1717 } | |
1718 | |
1719 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderBody() { | |
1720 return SHADER0([]() { | |
1721 void main() { | 1560 void main() { |
1722 vec4 texColor = texture2D(s_texture, v_texCoord); | 1561 vec4 texColor = texture2D(s_texture, v_texCoord); |
1723 TexCoordPrecision vec2 maskTexCoord = | 1562 TexCoordPrecision vec2 maskTexCoord = |
1724 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1563 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1725 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1564 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
1726 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); | 1565 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); |
1727 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1566 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1728 vec2 d2 = min(d4.xz, d4.yw); | 1567 vec2 d2 = min(d4.xz, d4.yw); |
1729 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1568 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
1730 gl_FragColor = ApplyBlendMode( | 1569 gl_FragColor = ApplyBlendMode( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1781 sampler_location_ = locations[0]; | 1620 sampler_location_ = locations[0]; |
1782 mask_sampler_location_ = locations[1]; | 1621 mask_sampler_location_ = locations[1]; |
1783 alpha_location_ = locations[2]; | 1622 alpha_location_ = locations[2]; |
1784 mask_tex_coord_scale_location_ = locations[3]; | 1623 mask_tex_coord_scale_location_ = locations[3]; |
1785 mask_tex_coord_offset_location_ = locations[4]; | 1624 mask_tex_coord_offset_location_ = locations[4]; |
1786 color_matrix_location_ = locations[5]; | 1625 color_matrix_location_ = locations[5]; |
1787 color_offset_location_ = locations[6]; | 1626 color_offset_location_ = locations[6]; |
1788 BLEND_MODE_SET_LOCATIONS(locations, 7); | 1627 BLEND_MODE_SET_LOCATIONS(locations, 7); |
1789 } | 1628 } |
1790 | 1629 |
1791 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderString( | 1630 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderSource() |
1792 TexCoordPrecision precision, | 1631 const { |
1793 SamplerType sampler) const { | |
1794 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1795 } | |
1796 | |
1797 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderHead() { | |
1798 return SHADER0([]() { | 1632 return SHADER0([]() { |
1799 precision mediump float; | 1633 precision mediump float; |
1800 uniform sampler2D s_texture; | 1634 uniform sampler2D s_texture; |
1801 uniform SamplerType s_mask; | 1635 uniform SamplerType s_mask; |
1802 uniform vec2 maskTexCoordScale; | 1636 uniform vec2 maskTexCoordScale; |
1803 uniform vec2 maskTexCoordOffset; | 1637 uniform vec2 maskTexCoordOffset; |
1804 uniform mat4 colorMatrix; | 1638 uniform mat4 colorMatrix; |
1805 uniform vec4 colorOffset; | 1639 uniform vec4 colorOffset; |
1806 uniform float alpha; | 1640 uniform float alpha; |
1807 varying TexCoordPrecision vec2 v_texCoord; | 1641 varying TexCoordPrecision vec2 v_texCoord; |
1808 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1642 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1809 }); | |
1810 } | |
1811 | |
1812 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderBody() { | |
1813 return SHADER0([]() { | |
1814 void main() { | 1643 void main() { |
1815 vec4 texColor = texture2D(s_texture, v_texCoord); | 1644 vec4 texColor = texture2D(s_texture, v_texCoord); |
1816 float nonZeroAlpha = max(texColor.a, 0.00001); | 1645 float nonZeroAlpha = max(texColor.a, 0.00001); |
1817 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1646 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1818 texColor = colorMatrix * texColor + colorOffset; | 1647 texColor = colorMatrix * texColor + colorOffset; |
1819 texColor.rgb *= texColor.a; | 1648 texColor.rgb *= texColor.a; |
1820 texColor = clamp(texColor, 0.0, 1.0); | 1649 texColor = clamp(texColor, 0.0, 1.0); |
1821 TexCoordPrecision vec2 maskTexCoord = | 1650 TexCoordPrecision vec2 maskTexCoord = |
1822 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1651 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1823 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1652 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1868 uniforms, | 1697 uniforms, |
1869 locations, | 1698 locations, |
1870 base_uniform_index); | 1699 base_uniform_index); |
1871 sampler_location_ = locations[0]; | 1700 sampler_location_ = locations[0]; |
1872 alpha_location_ = locations[1]; | 1701 alpha_location_ = locations[1]; |
1873 color_matrix_location_ = locations[2]; | 1702 color_matrix_location_ = locations[2]; |
1874 color_offset_location_ = locations[3]; | 1703 color_offset_location_ = locations[3]; |
1875 BLEND_MODE_SET_LOCATIONS(locations, 4); | 1704 BLEND_MODE_SET_LOCATIONS(locations, 4); |
1876 } | 1705 } |
1877 | 1706 |
1878 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderString( | 1707 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderSource() const { |
1879 TexCoordPrecision precision, | |
1880 SamplerType sampler) const { | |
1881 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1882 } | |
1883 | |
1884 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderHead() { | |
1885 return SHADER0([]() { | 1708 return SHADER0([]() { |
1886 precision mediump float; | 1709 precision mediump float; |
1887 uniform SamplerType s_texture; | 1710 uniform SamplerType s_texture; |
1888 uniform float alpha; | 1711 uniform float alpha; |
1889 uniform mat4 colorMatrix; | 1712 uniform mat4 colorMatrix; |
1890 uniform vec4 colorOffset; | 1713 uniform vec4 colorOffset; |
1891 varying TexCoordPrecision vec2 v_texCoord; | 1714 varying TexCoordPrecision vec2 v_texCoord; |
1892 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. | 1715 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. |
1893 }); | |
1894 } | |
1895 | |
1896 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderBody() { | |
1897 return SHADER0([]() { | |
1898 void main() { | 1716 void main() { |
1899 vec4 texColor = TextureLookup(s_texture, v_texCoord); | 1717 vec4 texColor = TextureLookup(s_texture, v_texCoord); |
1900 float nonZeroAlpha = max(texColor.a, 0.00001); | 1718 float nonZeroAlpha = max(texColor.a, 0.00001); |
1901 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1719 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1902 texColor = colorMatrix * texColor + colorOffset; | 1720 texColor = colorMatrix * texColor + colorOffset; |
1903 texColor.rgb *= texColor.a; | 1721 texColor.rgb *= texColor.a; |
1904 texColor = clamp(texColor, 0.0, 1.0); | 1722 texColor = clamp(texColor, 0.0, 1.0); |
1905 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 1723 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
1906 vec2 d2 = min(d4.xz, d4.yw); | 1724 vec2 d2 = min(d4.xz, d4.yw); |
1907 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 1725 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1952 sampler_location_ = locations[0]; | 1770 sampler_location_ = locations[0]; |
1953 mask_sampler_location_ = locations[1]; | 1771 mask_sampler_location_ = locations[1]; |
1954 alpha_location_ = locations[2]; | 1772 alpha_location_ = locations[2]; |
1955 mask_tex_coord_scale_location_ = locations[3]; | 1773 mask_tex_coord_scale_location_ = locations[3]; |
1956 mask_tex_coord_offset_location_ = locations[4]; | 1774 mask_tex_coord_offset_location_ = locations[4]; |
1957 color_matrix_location_ = locations[5]; | 1775 color_matrix_location_ = locations[5]; |
1958 color_offset_location_ = locations[6]; | 1776 color_offset_location_ = locations[6]; |
1959 BLEND_MODE_SET_LOCATIONS(locations, 7); | 1777 BLEND_MODE_SET_LOCATIONS(locations, 7); |
1960 } | 1778 } |
1961 | 1779 |
1962 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderString( | 1780 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderSource() const { |
1963 TexCoordPrecision precision, | |
1964 SamplerType sampler) const { | |
1965 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
1966 } | |
1967 | |
1968 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderHead() { | |
1969 return SHADER0([]() { | 1781 return SHADER0([]() { |
1970 precision mediump float; | 1782 precision mediump float; |
1971 varying TexCoordPrecision vec2 v_texCoord; | 1783 varying TexCoordPrecision vec2 v_texCoord; |
1972 uniform sampler2D s_texture; | 1784 uniform sampler2D s_texture; |
1973 uniform SamplerType s_mask; | 1785 uniform SamplerType s_mask; |
1974 uniform vec2 maskTexCoordScale; | 1786 uniform vec2 maskTexCoordScale; |
1975 uniform vec2 maskTexCoordOffset; | 1787 uniform vec2 maskTexCoordOffset; |
1976 uniform mat4 colorMatrix; | 1788 uniform mat4 colorMatrix; |
1977 uniform vec4 colorOffset; | 1789 uniform vec4 colorOffset; |
1978 uniform float alpha; | 1790 uniform float alpha; |
1979 }); | |
1980 } | |
1981 | |
1982 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderBody() { | |
1983 return SHADER0([]() { | |
1984 void main() { | 1791 void main() { |
1985 vec4 texColor = texture2D(s_texture, v_texCoord); | 1792 vec4 texColor = texture2D(s_texture, v_texCoord); |
1986 float nonZeroAlpha = max(texColor.a, 0.00001); | 1793 float nonZeroAlpha = max(texColor.a, 0.00001); |
1987 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); | 1794 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); |
1988 texColor = colorMatrix * texColor + colorOffset; | 1795 texColor = colorMatrix * texColor + colorOffset; |
1989 texColor.rgb *= texColor.a; | 1796 texColor.rgb *= texColor.a; |
1990 texColor = clamp(texColor, 0.0, 1.0); | 1797 texColor = clamp(texColor, 0.0, 1.0); |
1991 TexCoordPrecision vec2 maskTexCoord = | 1798 TexCoordPrecision vec2 maskTexCoord = |
1992 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, | 1799 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, |
1993 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); | 1800 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 resource_offset_location_ = locations[7]; | 1885 resource_offset_location_ = locations[7]; |
2079 } else { | 1886 } else { |
2080 yuv_matrix_location_ = locations[8]; | 1887 yuv_matrix_location_ = locations[8]; |
2081 yuv_adj_location_ = locations[9]; | 1888 yuv_adj_location_ = locations[9]; |
2082 } | 1889 } |
2083 alpha_location_ = locations[10]; | 1890 alpha_location_ = locations[10]; |
2084 ya_clamp_rect_location_ = locations[11]; | 1891 ya_clamp_rect_location_ = locations[11]; |
2085 uv_clamp_rect_location_ = locations[12]; | 1892 uv_clamp_rect_location_ = locations[12]; |
2086 } | 1893 } |
2087 | 1894 |
2088 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, | 1895 std::string FragmentShaderYUVVideo::GetShaderSource() const { |
2089 SamplerType sampler) const { | |
2090 std::string head = SHADER0([]() { | 1896 std::string head = SHADER0([]() { |
2091 precision mediump float; | 1897 precision mediump float; |
2092 precision mediump int; | 1898 precision mediump int; |
2093 varying TexCoordPrecision vec2 v_yaTexCoord; | 1899 varying TexCoordPrecision vec2 v_yaTexCoord; |
2094 varying TexCoordPrecision vec2 v_uvTexCoord; | 1900 varying TexCoordPrecision vec2 v_uvTexCoord; |
2095 uniform SamplerType y_texture; | 1901 uniform SamplerType y_texture; |
2096 uniform float alpha; | 1902 uniform float alpha; |
2097 uniform vec4 ya_clamp_rect; | 1903 uniform vec4 ya_clamp_rect; |
2098 uniform vec4 uv_clamp_rect; | 1904 uniform vec4 uv_clamp_rect; |
2099 }); | 1905 }); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2166 vec2 ya_clamped = | 1972 vec2 ya_clamped = |
2167 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord)); | 1973 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord)); |
2168 float y_raw = TextureLookup(y_texture, ya_clamped).x; | 1974 float y_raw = TextureLookup(y_texture, ya_clamped).x; |
2169 vec2 uv_clamped = | 1975 vec2 uv_clamped = |
2170 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); | 1976 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); |
2171 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); | 1977 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); |
2172 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); | 1978 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); |
2173 } | 1979 } |
2174 }); | 1980 }); |
2175 | 1981 |
2176 return FRAGMENT_SHADER(head, functions); | 1982 return head + functions; |
2177 } | 1983 } |
2178 | 1984 |
2179 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { | 1985 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { |
2180 } | 1986 } |
2181 | 1987 |
2182 void FragmentShaderColor::Init(GLES2Interface* context, | 1988 void FragmentShaderColor::Init(GLES2Interface* context, |
2183 unsigned program, | 1989 unsigned program, |
2184 int* base_uniform_index) { | 1990 int* base_uniform_index) { |
2185 static const char* uniforms[] = { | 1991 static const char* uniforms[] = { |
2186 "color", | 1992 "color", |
2187 }; | 1993 }; |
2188 int locations[arraysize(uniforms)]; | 1994 int locations[arraysize(uniforms)]; |
2189 | 1995 |
2190 GetProgramUniformLocations(context, | 1996 GetProgramUniformLocations(context, |
2191 program, | 1997 program, |
2192 arraysize(uniforms), | 1998 arraysize(uniforms), |
2193 uniforms, | 1999 uniforms, |
2194 locations, | 2000 locations, |
2195 base_uniform_index); | 2001 base_uniform_index); |
2196 color_location_ = locations[0]; | 2002 color_location_ = locations[0]; |
2197 } | 2003 } |
2198 | 2004 |
2199 std::string FragmentShaderColor::GetShaderString(TexCoordPrecision precision, | 2005 std::string FragmentShaderColor::GetShaderSource() const { |
2200 SamplerType sampler) const { | |
2201 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
2202 } | |
2203 | |
2204 std::string FragmentShaderColor::GetShaderHead() { | |
2205 return SHADER0([]() { | 2006 return SHADER0([]() { |
2206 precision mediump float; | 2007 precision mediump float; |
2207 uniform vec4 color; | 2008 uniform vec4 color; |
2208 }); | |
2209 } | |
2210 | |
2211 std::string FragmentShaderColor::GetShaderBody() { | |
2212 return SHADER0([]() { | |
2213 void main() { gl_FragColor = color; } | 2009 void main() { gl_FragColor = color; } |
2214 }); | 2010 }); |
2215 } | 2011 } |
2216 | 2012 |
2217 FragmentShaderColorAA::FragmentShaderColorAA() : color_location_(-1) { | 2013 FragmentShaderColorAA::FragmentShaderColorAA() : color_location_(-1) { |
2218 } | 2014 } |
2219 | 2015 |
2220 void FragmentShaderColorAA::Init(GLES2Interface* context, | 2016 void FragmentShaderColorAA::Init(GLES2Interface* context, |
2221 unsigned program, | 2017 unsigned program, |
2222 int* base_uniform_index) { | 2018 int* base_uniform_index) { |
2223 static const char* uniforms[] = { | 2019 static const char* uniforms[] = { |
2224 "color", | 2020 "color", |
2225 }; | 2021 }; |
2226 int locations[arraysize(uniforms)]; | 2022 int locations[arraysize(uniforms)]; |
2227 | 2023 |
2228 GetProgramUniformLocations(context, | 2024 GetProgramUniformLocations(context, |
2229 program, | 2025 program, |
2230 arraysize(uniforms), | 2026 arraysize(uniforms), |
2231 uniforms, | 2027 uniforms, |
2232 locations, | 2028 locations, |
2233 base_uniform_index); | 2029 base_uniform_index); |
2234 color_location_ = locations[0]; | 2030 color_location_ = locations[0]; |
2235 } | 2031 } |
2236 | 2032 |
2237 std::string FragmentShaderColorAA::GetShaderString(TexCoordPrecision precision, | 2033 std::string FragmentShaderColorAA::GetShaderSource() const { |
2238 SamplerType sampler) const { | |
2239 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | |
2240 } | |
2241 | |
2242 std::string FragmentShaderColorAA::GetShaderHead() { | |
2243 return SHADER0([]() { | 2034 return SHADER0([]() { |
2244 precision mediump float; | 2035 precision mediump float; |
2245 uniform vec4 color; | 2036 uniform vec4 color; |
2246 varying vec4 edge_dist[2]; // 8 edge distances. | 2037 varying vec4 edge_dist[2]; // 8 edge distances. |
2247 }); | |
2248 } | |
2249 | |
2250 std::string FragmentShaderColorAA::GetShaderBody() { | |
2251 return SHADER0([]() { | |
2252 void main() { | 2038 void main() { |
2253 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 2039 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
2254 vec2 d2 = min(d4.xz, d4.yw); | 2040 vec2 d2 = min(d4.xz, d4.yw); |
2255 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 2041 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
2256 gl_FragColor = color * aa; | 2042 gl_FragColor = color * aa; |
2257 } | 2043 } |
2258 }); | 2044 }); |
2259 } | 2045 } |
2260 | 2046 |
2261 } // namespace cc | 2047 } // namespace cc |
OLD | NEW |