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; |
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 std::string VertexShaderPosTexIdentity::getShaderString() const | 181 std::string VertexShaderPosTexIdentity::getShaderString() const |
175 { | 182 { |
176 return SHADER( | 183 return SHADER( |
177 attribute vec4 a_position; | 184 attribute vec4 a_position; |
178 varying vec2 v_texCoord; | 185 varying vec2 v_texCoord; |
179 void main() | 186 void main() |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 "s_texture", | 356 "s_texture", |
350 }; | 357 }; |
351 int locations[1]; | 358 int locations[1]; |
352 | 359 |
353 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | 360 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; |
354 | 361 |
355 m_samplerLocation = locations[0]; | 362 m_samplerLocation = locations[0]; |
356 DCHECK(m_samplerLocation != -1); | 363 DCHECK(m_samplerLocation != -1); |
357 } | 364 } |
358 | 365 |
359 std::string FragmentShaderRGBATexFlipAlpha::getShaderString() const | 366 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const |
360 { | 367 { |
361 return SHADER( | 368 return SHADER( |
362 precision mediump float; | 369 precision mediump float; |
363 varying vec2 v_texCoord; | 370 varying vec2 v_texCoord; |
| 371 varying float v_alpha; |
364 uniform sampler2D s_texture; | 372 uniform sampler2D s_texture; |
365 uniform float alpha; | |
366 void main() | 373 void main() |
367 { | 374 { |
368 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); | 375 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); |
369 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* alpha; | 376 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* v_alpha; |
370 } | 377 } |
371 ); | 378 ); |
372 } | 379 } |
373 | 380 |
374 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | 381 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) |
375 { | 382 { |
376 static const char* shaderUniforms[] = { | 383 static const char* shaderUniforms[] = { |
377 "s_texture", | 384 "s_texture", |
378 }; | 385 }; |
379 int locations[1]; | 386 int locations[1]; |
(...skipping 26 matching lines...) Expand all Loading... |
406 uniform sampler2D s_texture; | 413 uniform sampler2D s_texture; |
407 uniform float alpha; | 414 uniform float alpha; |
408 void main() | 415 void main() |
409 { | 416 { |
410 vec4 texColor = texture2D(s_texture, v_texCoord); | 417 vec4 texColor = texture2D(s_texture, v_texCoord); |
411 gl_FragColor = texColor * alpha; | 418 gl_FragColor = texColor * alpha; |
412 } | 419 } |
413 ); | 420 ); |
414 } | 421 } |
415 | 422 |
416 std::string FragmentShaderRGBATexRectFlipAlpha::getShaderString() const | 423 std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const |
| 424 { |
| 425 return SHADER( |
| 426 precision mediump float; |
| 427 varying vec2 v_texCoord; |
| 428 varying float v_alpha; |
| 429 uniform sampler2D s_texture; |
| 430 void main() |
| 431 { |
| 432 vec4 texColor = texture2D(s_texture, v_texCoord); |
| 433 gl_FragColor = texColor * v_alpha; |
| 434 } |
| 435 ); |
| 436 } |
| 437 |
| 438 std::string FragmentShaderRGBATexRectFlipVaryingAlpha::getShaderString() const |
417 { | 439 { |
418 // This must be paired with VertexShaderPosTexTransform to pick up the texTr
ansform uniform. | 440 // This must be paired with VertexShaderPosTexTransform to pick up the texTr
ansform uniform. |
419 // The necessary #extension preprocessing directive breaks the SHADER and SH
ADER0 macros. | 441 // The necessary #extension preprocessing directive breaks the SHADER and SH
ADER0 macros. |
420 return "#extension GL_ARB_texture_rectangle : require\n" | 442 return "#extension GL_ARB_texture_rectangle : require\n" |
421 "precision mediump float;\n" | 443 "precision mediump float;\n" |
422 "varying vec2 v_texCoord;\n" | 444 "varying vec2 v_texCoord;\n" |
| 445 "varying float v_alpha;\n" |
423 "uniform vec4 texTransform;\n" | 446 "uniform vec4 texTransform;\n" |
424 "uniform sampler2DRect s_texture;\n" | 447 "uniform sampler2DRect s_texture;\n" |
425 "uniform float alpha;\n" | |
426 "void main()\n" | 448 "void main()\n" |
427 "{\n" | 449 "{\n" |
428 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex
Transform.w - v_texCoord.y));\n" | 450 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex
Transform.w - v_texCoord.y));\n" |
429 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo
r.w) * alpha;\n" | 451 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo
r.w) * v_alpha;\n" |
430 "}\n"; | 452 "}\n"; |
431 } | 453 } |
432 | 454 |
433 std::string FragmentShaderRGBATexRectAlpha::getShaderString() const | 455 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const |
434 { | 456 { |
435 return "#extension GL_ARB_texture_rectangle : require\n" | 457 return "#extension GL_ARB_texture_rectangle : require\n" |
436 "precision mediump float;\n" | 458 "precision mediump float;\n" |
437 "varying vec2 v_texCoord;\n" | 459 "varying vec2 v_texCoord;\n" |
| 460 "varying float v_alpha;\n" |
438 "uniform sampler2DRect s_texture;\n" | 461 "uniform sampler2DRect s_texture;\n" |
439 "uniform float alpha;\n" | |
440 "void main()\n" | 462 "void main()\n" |
441 "{\n" | 463 "{\n" |
442 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 464 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
443 " gl_FragColor = texColor * alpha;\n" | 465 " gl_FragColor = texColor * v_alpha;\n" |
444 "}\n"; | 466 "}\n"; |
445 } | 467 } |
446 | 468 |
447 std::string FragmentShaderRGBATexOpaque::getShaderString() const | 469 std::string FragmentShaderRGBATexOpaque::getShaderString() const |
448 { | 470 { |
449 return SHADER( | 471 return SHADER( |
450 precision mediump float; | 472 precision mediump float; |
451 varying vec2 v_texCoord; | 473 varying vec2 v_texCoord; |
452 uniform sampler2D s_texture; | 474 uniform sampler2D s_texture; |
453 void main() | 475 void main() |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 vec4 color2 = color; | 896 vec4 color2 = color; |
875 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; | 897 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; |
876 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 898 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
877 float picker = abs(coord.x - coord.y); | 899 float picker = abs(coord.x - coord.y); |
878 gl_FragColor = mix(color1, color2, picker) * alpha; | 900 gl_FragColor = mix(color1, color2, picker) * alpha; |
879 } | 901 } |
880 ); | 902 ); |
881 } | 903 } |
882 | 904 |
883 } // namespace cc | 905 } // namespace cc |
OLD | NEW |