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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/shader.h" | 7 #include "cc/shader.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 void main() | 62 void main() |
63 { | 63 { |
64 gl_Position = matrix * a_position; | 64 gl_Position = matrix * a_position; |
65 v_texCoord = a_texCoord; | 65 v_texCoord = a_texCoord; |
66 } | 66 } |
67 ); | 67 ); |
68 } | 68 } |
69 | 69 |
70 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() | 70 VertexShaderPosTexYUVStretch::VertexShaderPosTexYUVStretch() |
71 : m_matrixLocation(-1) | 71 : m_matrixLocation(-1) |
72 , m_yWidthScaleFactorLocation(-1) | 72 , m_texScaleLocation(-1) |
73 , m_uvWidthScaleFactorLocation(-1) | |
74 { | 73 { |
75 } | 74 } |
76 | 75 |
77 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned
program, bool usingBindUniform, int* baseUniformIndex) | 76 void VertexShaderPosTexYUVStretch::init(WebGraphicsContext3D* context, unsigned
program, bool usingBindUniform, int* baseUniformIndex) |
78 { | 77 { |
79 static const char* shaderUniforms[] = { | 78 static const char* shaderUniforms[] = { |
80 "matrix", | 79 "matrix", |
81 "y_widthScaleFactor", | 80 "texScale", |
82 "uv_widthScaleFactor", | |
83 }; | 81 }; |
84 int locations[3]; | 82 int locations[2]; |
85 | 83 |
86 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | 84 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; |
87 | 85 |
88 m_matrixLocation = locations[0]; | 86 m_matrixLocation = locations[0]; |
89 m_yWidthScaleFactorLocation = locations[1]; | 87 m_texScaleLocation = locations[1]; |
90 m_uvWidthScaleFactorLocation = locations[2]; | 88 DCHECK(m_matrixLocation != -1 && m_texScaleLocation != -1); |
91 DCHECK(m_matrixLocation != -1 && m_yWidthScaleFactorLocation != -1 && m_uvWi
dthScaleFactorLocation != -1); | |
92 } | 89 } |
93 | 90 |
94 std::string VertexShaderPosTexYUVStretch::getShaderString() const | 91 std::string VertexShaderPosTexYUVStretch::getShaderString() const |
95 { | 92 { |
96 return SHADER( | 93 return SHADER( |
97 precision mediump float; | 94 precision mediump float; |
98 attribute vec4 a_position; | 95 attribute vec4 a_position; |
99 attribute vec2 a_texCoord; | 96 attribute vec2 a_texCoord; |
100 uniform mat4 matrix; | 97 uniform mat4 matrix; |
101 varying vec2 y_texCoord; | 98 varying vec2 v_texCoord; |
102 varying vec2 uv_texCoord; | 99 uniform vec2 texScale; |
103 uniform float y_widthScaleFactor; | |
104 uniform float uv_widthScaleFactor; | |
105 void main() | 100 void main() |
106 { | 101 { |
107 gl_Position = matrix * a_position; | 102 gl_Position = matrix * a_position; |
108 y_texCoord = vec2(y_widthScaleFactor * a_texCoord.x, a_texCoord.y); | 103 v_texCoord = a_texCoord * texScale; |
109 uv_texCoord = vec2(uv_widthScaleFactor * a_texCoord.x, a_texCoord.y)
; | |
110 } | 104 } |
111 ); | 105 ); |
112 } | 106 } |
113 | 107 |
114 VertexShaderPos::VertexShaderPos() | 108 VertexShaderPos::VertexShaderPos() |
115 : m_matrixLocation(-1) | 109 : m_matrixLocation(-1) |
116 { | 110 { |
117 } | 111 } |
118 | 112 |
119 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool
usingBindUniform, int* baseUniformIndex) | 113 void VertexShaderPos::init(WebGraphicsContext3D* context, unsigned program, bool
usingBindUniform, int* baseUniformIndex) |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 | 769 |
776 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc
ation != -1 | 770 DCHECK(m_yTextureLocation != -1 && m_uTextureLocation != -1 && m_vTextureLoc
ation != -1 |
777 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca
tion != -1); | 771 && m_alphaLocation != -1 && m_yuvMatrixLocation != -1 && m_yuvAdjLoca
tion != -1); |
778 } | 772 } |
779 | 773 |
780 std::string FragmentShaderYUVVideo::getShaderString() const | 774 std::string FragmentShaderYUVVideo::getShaderString() const |
781 { | 775 { |
782 return SHADER( | 776 return SHADER( |
783 precision mediump float; | 777 precision mediump float; |
784 precision mediump int; | 778 precision mediump int; |
785 varying vec2 y_texCoord; | 779 varying vec2 v_texCoord; |
786 varying vec2 uv_texCoord; | |
787 uniform sampler2D y_texture; | 780 uniform sampler2D y_texture; |
788 uniform sampler2D u_texture; | 781 uniform sampler2D u_texture; |
789 uniform sampler2D v_texture; | 782 uniform sampler2D v_texture; |
790 uniform float alpha; | 783 uniform float alpha; |
791 uniform vec3 yuv_adj; | 784 uniform vec3 yuv_adj; |
792 uniform mat3 yuv_matrix; | 785 uniform mat3 yuv_matrix; |
793 void main() | 786 void main() |
794 { | 787 { |
795 float y_raw = texture2D(y_texture, y_texCoord).x; | 788 float y_raw = texture2D(y_texture, v_texCoord).x; |
796 float u_unsigned = texture2D(u_texture, uv_texCoord).x; | 789 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
797 float v_unsigned = texture2D(v_texture, uv_texCoord).x; | 790 float v_unsigned = texture2D(v_texture, v_texCoord).x; |
798 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 791 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
799 vec3 rgb = yuv_matrix * yuv; | 792 vec3 rgb = yuv_matrix * yuv; |
800 gl_FragColor = vec4(rgb, float(1)) * alpha; | 793 gl_FragColor = vec4(rgb, float(1)) * alpha; |
801 } | 794 } |
802 ); | 795 ); |
803 } | 796 } |
804 | 797 |
805 FragmentShaderColor::FragmentShaderColor() | 798 FragmentShaderColor::FragmentShaderColor() |
806 : m_colorLocation(-1) | 799 : m_colorLocation(-1) |
807 { | 800 { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 vec4 color2 = color; | 869 vec4 color2 = color; |
877 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; | 870 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; |
878 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 871 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
879 float picker = abs(coord.x - coord.y); | 872 float picker = abs(coord.x - coord.y); |
880 gl_FragColor = mix(color1, color2, picker) * alpha; | 873 gl_FragColor = mix(color1, color2, picker) * alpha; |
881 } | 874 } |
882 ); | 875 ); |
883 } | 876 } |
884 | 877 |
885 } // namespace cc | 878 } // namespace cc |
OLD | NEW |