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/shader.h" | 5 #include "cc/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 <public/WebGraphicsContext3D.h> | 9 #include <public/WebGraphicsContext3D.h> |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 void main() | 129 void main() |
130 { | 130 { |
131 gl_Position = matrix * a_position; | 131 gl_Position = matrix * a_position; |
132 } | 132 } |
133 ); | 133 ); |
134 } | 134 } |
135 | 135 |
136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() | 136 VertexShaderPosTexTransform::VertexShaderPosTexTransform() |
137 : m_matrixLocation(-1) | 137 : m_matrixLocation(-1) |
138 , m_texTransformLocation(-1) | 138 , m_texTransformLocation(-1) |
139 , m_vertexOpacityLocation(-1) | |
139 { | 140 { |
140 } | 141 } |
141 | 142 |
142 void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p rogram, bool usingBindUniform, int* baseUniformIndex) | 143 void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p rogram, bool usingBindUniform, int* baseUniformIndex) |
143 { | 144 { |
144 static const char* shaderUniforms[] = { | 145 static const char* shaderUniforms[] = { |
145 "matrix", | 146 "matrix", |
146 "texTransform", | 147 "texTransform", |
148 "opacity", | |
147 }; | 149 }; |
148 int locations[2]; | 150 int locations[3]; |
149 | 151 |
150 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 152 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
151 | 153 |
152 m_matrixLocation = locations[0]; | 154 m_matrixLocation = locations[0]; |
153 m_texTransformLocation = locations[1]; | 155 m_texTransformLocation = locations[1]; |
154 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1); | 156 m_vertexOpacityLocation = locations[2]; |
157 DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpa cityLocation != -1); | |
155 } | 158 } |
156 | 159 |
157 std::string VertexShaderPosTexTransform::getShaderString() const | 160 std::string VertexShaderPosTexTransform::getShaderString() const |
158 { | 161 { |
159 return SHADER( | 162 return SHADER( |
160 attribute vec4 a_position; | 163 attribute vec4 a_position; |
161 attribute vec2 a_texCoord; | 164 attribute vec2 a_texCoord; |
162 attribute float a_index; | 165 attribute float a_index; |
163 uniform mat4 matrix[8]; | 166 uniform mat4 matrix[8]; |
164 uniform vec4 texTransform[8]; | 167 uniform vec4 texTransform[8]; |
168 uniform float opacity[32]; | |
165 varying vec2 v_texCoord; | 169 varying vec2 v_texCoord; |
170 varying float v_alpha; | |
166 void main() | 171 void main() |
167 { | 172 { |
168 gl_Position = matrix[int(a_index)] * a_position; | 173 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
whunt
2012/12/15 00:55:00
Did you try (int(a_index) >> 2)
That should be fas
| |
169 v_texCoord = a_texCoord * texTransform[int(a_index)].zw + texTransfo rm[int(a_index)].xy; | 174 vec4 texTrans = texTransform[int(a_index * 0.25)]; |
175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | |
176 v_alpha = opacity[int(a_index)]; | |
170 } | 177 } |
171 ); | 178 ); |
172 } | 179 } |
173 | 180 |
174 VertexShaderQuad::VertexShaderQuad() | 181 VertexShaderQuad::VertexShaderQuad() |
175 : m_matrixLocation(-1) | 182 : m_matrixLocation(-1) |
176 , m_pointLocation(-1) | 183 , m_pointLocation(-1) |
177 { | 184 { |
178 } | 185 } |
179 | 186 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 "s_texture", | 350 "s_texture", |
344 }; | 351 }; |
345 int locations[1]; | 352 int locations[1]; |
346 | 353 |
347 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; | 354 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex) ; |
348 | 355 |
349 m_samplerLocation = locations[0]; | 356 m_samplerLocation = locations[0]; |
350 DCHECK(m_samplerLocation != -1); | 357 DCHECK(m_samplerLocation != -1); |
351 } | 358 } |
352 | 359 |
353 std::string FragmentShaderRGBATexFlipAlpha::getShaderString() const | 360 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const |
354 { | 361 { |
355 return SHADER( | 362 return SHADER( |
356 precision mediump float; | 363 precision mediump float; |
357 varying vec2 v_texCoord; | 364 varying vec2 v_texCoord; |
365 varying float v_alpha; | |
358 uniform sampler2D s_texture; | 366 uniform sampler2D s_texture; |
359 uniform float alpha; | |
360 void main() | 367 void main() |
361 { | 368 { |
362 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC oord.y)); | 369 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC oord.y)); |
363 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha; | 370 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * v_alpha; |
364 } | 371 } |
365 ); | 372 ); |
366 } | 373 } |
367 | 374 |
368 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex) | 375 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne d program, bool usingBindUniform, int* baseUniformIndex) |
369 { | 376 { |
370 static const char* shaderUniforms[] = { | 377 static const char* shaderUniforms[] = { |
371 "s_texture", | 378 "s_texture", |
372 }; | 379 }; |
373 int locations[1]; | 380 int locations[1]; |
(...skipping 26 matching lines...) Expand all Loading... | |
400 uniform sampler2D s_texture; | 407 uniform sampler2D s_texture; |
401 uniform float alpha; | 408 uniform float alpha; |
402 void main() | 409 void main() |
403 { | 410 { |
404 vec4 texColor = texture2D(s_texture, v_texCoord); | 411 vec4 texColor = texture2D(s_texture, v_texCoord); |
405 gl_FragColor = texColor * alpha; | 412 gl_FragColor = texColor * alpha; |
406 } | 413 } |
407 ); | 414 ); |
408 } | 415 } |
409 | 416 |
410 std::string FragmentShaderRGBATexRectFlipAlpha::getShaderString() const | 417 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const |
418 { | |
419 return SHADER( | |
420 precision mediump float; | |
421 varying vec2 v_texCoord; | |
422 varying float v_alpha; | |
423 uniform sampler2D s_texture; | |
424 void main() | |
425 { | |
426 vec4 texColor = texture2D(s_texture, v_texCoord); | |
427 gl_FragColor = texColor * v_alpha; | |
428 } | |
429 ); | |
430 } | |
431 | |
432 std::string FragmentShaderRGBATexRectFlipVaryingAlpha::getShaderString() const | |
411 { | 433 { |
412 // This must be paired with VertexShaderPosTexTransform to pick up the texTr ansform uniform. | 434 // This must be paired with VertexShaderPosTexTransform to pick up the texTr ansform uniform. |
413 // The necessary #extension preprocessing directive breaks the SHADER and SH ADER0 macros. | 435 // The necessary #extension preprocessing directive breaks the SHADER and SH ADER0 macros. |
414 return "#extension GL_ARB_texture_rectangle : require\n" | 436 return "#extension GL_ARB_texture_rectangle : require\n" |
415 "precision mediump float;\n" | 437 "precision mediump float;\n" |
416 "varying vec2 v_texCoord;\n" | 438 "varying vec2 v_texCoord;\n" |
439 "varying float v_alpha;\n" | |
417 "uniform vec4 texTransform;\n" | 440 "uniform vec4 texTransform;\n" |
418 "uniform sampler2DRect s_texture;\n" | 441 "uniform sampler2DRect s_texture;\n" |
419 "uniform float alpha;\n" | |
420 "void main()\n" | 442 "void main()\n" |
421 "{\n" | 443 "{\n" |
422 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex Transform.w - v_texCoord.y));\n" | 444 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex Transform.w - v_texCoord.y));\n" |
423 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo r.w) * alpha;\n" | 445 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo r.w) * v_alpha;\n" |
424 "}\n"; | 446 "}\n"; |
425 } | 447 } |
426 | 448 |
427 std::string FragmentShaderRGBATexRectAlpha::getShaderString() const | 449 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const |
428 { | 450 { |
429 return "#extension GL_ARB_texture_rectangle : require\n" | 451 return "#extension GL_ARB_texture_rectangle : require\n" |
430 "precision mediump float;\n" | 452 "precision mediump float;\n" |
431 "varying vec2 v_texCoord;\n" | 453 "varying vec2 v_texCoord;\n" |
454 "varying float v_alpha;\n" | |
432 "uniform sampler2DRect s_texture;\n" | 455 "uniform sampler2DRect s_texture;\n" |
433 "uniform float alpha;\n" | |
434 "void main()\n" | 456 "void main()\n" |
435 "{\n" | 457 "{\n" |
436 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 458 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
437 " gl_FragColor = texColor * alpha;\n" | 459 " gl_FragColor = texColor * v_alpha;\n" |
438 "}\n"; | 460 "}\n"; |
439 } | 461 } |
440 | 462 |
441 std::string FragmentShaderRGBATexOpaque::getShaderString() const | 463 std::string FragmentShaderRGBATexOpaque::getShaderString() const |
442 { | 464 { |
443 return SHADER( | 465 return SHADER( |
444 precision mediump float; | 466 precision mediump float; |
445 varying vec2 v_texCoord; | 467 varying vec2 v_texCoord; |
446 uniform sampler2D s_texture; | 468 uniform sampler2D s_texture; |
447 void main() | 469 void main() |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 vec4 color2 = color; | 890 vec4 color2 = color; |
869 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; | 891 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT ransform.xy; |
870 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 892 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
871 float picker = abs(coord.x - coord.y); | 893 float picker = abs(coord.x - coord.y); |
872 gl_FragColor = mix(color1, color2, picker) * alpha; | 894 gl_FragColor = mix(color1, color2, picker) * alpha; |
873 } | 895 } |
874 ); | 896 ); |
875 } | 897 } |
876 | 898 |
877 } // namespace cc | 899 } // namespace cc |
OLD | NEW |