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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3 D.h" |
10 | 10 |
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
906 float y_raw = texture2D(y_texture, v_texCoord).x; | 906 float y_raw = texture2D(y_texture, v_texCoord).x; |
907 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 907 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
908 float v_unsigned = texture2D(v_texture, v_texCoord).x; | 908 float v_unsigned = texture2D(v_texture, v_texCoord).x; |
909 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 909 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
910 vec3 rgb = yuv_matrix * yuv; | 910 vec3 rgb = yuv_matrix * yuv; |
911 gl_FragColor = vec4(rgb, float(1)) * alpha; | 911 gl_FragColor = vec4(rgb, float(1)) * alpha; |
912 } | 912 } |
913 ); | 913 ); |
914 } | 914 } |
915 | 915 |
916 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() | |
917 : y_texture_location_(-1), | |
918 u_texture_location_(-1), | |
919 v_texture_location_(-1), | |
920 a_texture_location_(-1), | |
921 alpha_location_(-1), | |
922 yuv_matrix_location_(-1), | |
923 yuv_adj_location_(-1) { | |
924 } | |
925 | |
926 void FragmentShaderYUVAVideo::Init(WebGraphicsContext3D* context, | |
927 unsigned program, | |
928 bool using_bind_uniform, | |
929 int* base_uniform_index) { | |
930 static const char* shader_uniforms[] = { | |
931 "y_texture", | |
932 "u_texture", | |
933 "v_texture", | |
934 "a_texture", | |
935 "alpha", | |
936 "cc_matrix", | |
937 "yuv_adj", | |
938 }; | |
939 int locations[7]; | |
940 | |
941 GetProgramUniformLocations(context, | |
942 program, | |
943 shader_uniforms, | |
944 arraysize(shader_uniforms), | |
945 arraysize(locations), | |
946 locations, | |
947 using_bind_uniform, | |
948 base_uniform_index); | |
949 | |
950 y_texture_location_ = locations[0]; | |
951 u_texture_location_ = locations[1]; | |
952 v_texture_location_ = locations[2]; | |
953 a_texture_location_ = locations[3]; | |
954 alpha_location_ = locations[4]; | |
955 yuv_matrix_location_ = locations[5]; | |
956 yuv_adj_location_ = locations[6]; | |
957 | |
958 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && | |
959 v_texture_location_ != -1 && a_texture_location_ != -1 && | |
960 alpha_location_ != -1 && yuv_matrix_location_ != -1 && | |
961 yuv_adj_location_ != -1); | |
962 } | |
963 | |
964 std::string FragmentShaderYUVAVideo::GetShaderString() const { | |
965 return SHADER( | |
966 precision mediump float; | |
967 precision mediump int; | |
968 varying vec2 y_texCoord; | |
969 varying vec2 uv_texCoord; | |
enne (OOO)
2013/04/05 23:06:53
I'm still a little confused about how this varying
vignesh
2013/04/09 20:48:03
You are right, the shader emits only one varying p
| |
970 uniform sampler2D y_texture; | |
971 uniform sampler2D u_texture; | |
972 uniform sampler2D v_texture; | |
973 uniform sampler2D a_texture; | |
974 uniform float alpha; | |
975 uniform vec3 yuv_adj; | |
976 uniform mat3 cc_matrix; | |
977 void main() { | |
978 float y_raw = texture2D(y_texture, y_texCoord).x; | |
979 float u_unsigned = texture2D(u_texture, uv_texCoord).x; | |
980 float v_unsigned = texture2D(v_texture, uv_texCoord).x; | |
981 float a_raw = texture2D(a_texture, y_texCoord).x; | |
982 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | |
983 vec3 rgb = cc_matrix * yuv; | |
984 gl_FragColor = vec4(rgb, float(1)) * (a_raw * alpha); | |
985 } | |
986 ); | |
987 } | |
988 | |
916 FragmentShaderColor::FragmentShaderColor() | 989 FragmentShaderColor::FragmentShaderColor() |
917 : color_location_(-1) {} | 990 : color_location_(-1) {} |
918 | 991 |
919 void FragmentShaderColor::Init(WebGraphicsContext3D* context, | 992 void FragmentShaderColor::Init(WebGraphicsContext3D* context, |
920 unsigned program, | 993 unsigned program, |
921 bool using_bind_uniform, | 994 bool using_bind_uniform, |
922 int* base_uniform_index) { | 995 int* base_uniform_index) { |
923 static const char* shader_uniforms[] = { | 996 static const char* shader_uniforms[] = { |
924 "color", | 997 "color", |
925 }; | 998 }; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1048 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + | 1121 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + |
1049 texTransform.xy; | 1122 texTransform.xy; |
1050 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1123 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1051 float picker = abs(coord.x - coord.y); | 1124 float picker = abs(coord.x - coord.y); |
1052 gl_FragColor = mix(color1, color2, picker) * alpha; | 1125 gl_FragColor = mix(color1, color2, picker) * alpha; |
1053 } | 1126 } |
1054 ); | 1127 ); |
1055 } | 1128 } |
1056 | 1129 |
1057 } // namespace cc | 1130 } // namespace cc |
OLD | NEW |