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 "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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 void main() | 171 void main() |
172 { | 172 { |
173 gl_Position = matrix[int(a_index * 0.25)] * a_position; | 173 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
174 vec4 texTrans = texTransform[int(a_index * 0.25)]; | 174 vec4 texTrans = texTransform[int(a_index * 0.25)]; |
175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; | 175 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
176 v_alpha = opacity[int(a_index)]; | 176 v_alpha = opacity[int(a_index)]; |
177 } | 177 } |
178 ); | 178 ); |
179 } | 179 } |
180 | 180 |
| 181 std::string VertexShaderPosTexTransformFlip::getShaderString() const |
| 182 { |
| 183 return SHADER( |
| 184 attribute vec4 a_position; |
| 185 attribute vec2 a_texCoord; |
| 186 attribute float a_index; |
| 187 uniform mat4 matrix[8]; |
| 188 uniform vec4 texTransform[8]; |
| 189 uniform float opacity[32]; |
| 190 varying vec2 v_texCoord; |
| 191 varying float v_alpha; |
| 192 void main() |
| 193 { |
| 194 gl_Position = matrix[int(a_index * 0.25)] * a_position; |
| 195 vec4 texTrans = texTransform[int(a_index * 0.25)]; |
| 196 v_texCoord = a_texCoord * texTrans.zw + texTrans.xy; |
| 197 v_texCoord.y = 1.0 - v_texCoord.y; |
| 198 v_alpha = opacity[int(a_index)]; |
| 199 } |
| 200 ); |
| 201 } |
| 202 |
181 std::string VertexShaderPosTexIdentity::getShaderString() const | 203 std::string VertexShaderPosTexIdentity::getShaderString() const |
182 { | 204 { |
183 return SHADER( | 205 return SHADER( |
184 attribute vec4 a_position; | 206 attribute vec4 a_position; |
185 varying vec2 v_texCoord; | 207 varying vec2 v_texCoord; |
186 void main() | 208 void main() |
187 { | 209 { |
188 gl_Position = a_position; | 210 gl_Position = a_position; |
189 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 211 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
190 } | 212 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 "s_texture", | 378 "s_texture", |
357 }; | 379 }; |
358 int locations[1]; | 380 int locations[1]; |
359 | 381 |
360 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | 382 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; |
361 | 383 |
362 m_samplerLocation = locations[0]; | 384 m_samplerLocation = locations[0]; |
363 DCHECK(m_samplerLocation != -1); | 385 DCHECK(m_samplerLocation != -1); |
364 } | 386 } |
365 | 387 |
366 std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const | |
367 { | |
368 return SHADER( | |
369 precision mediump float; | |
370 varying vec2 v_texCoord; | |
371 varying float v_alpha; | |
372 uniform sampler2D s_texture; | |
373 void main() | |
374 { | |
375 vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texC
oord.y)); | |
376 gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w)
* v_alpha; | |
377 } | |
378 ); | |
379 } | |
380 | |
381 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) | 388 bool FragmentShaderOESImageExternal::init(WebGraphicsContext3D* context, unsigne
d program, bool usingBindUniform, int* baseUniformIndex) |
382 { | 389 { |
383 static const char* shaderUniforms[] = { | 390 static const char* shaderUniforms[] = { |
384 "s_texture", | 391 "s_texture", |
385 }; | 392 }; |
386 int locations[1]; | 393 int locations[1]; |
387 | 394 |
388 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | 395 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; |
389 | 396 |
390 m_samplerLocation = locations[0]; | 397 m_samplerLocation = locations[0]; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 varying float v_alpha; | 435 varying float v_alpha; |
429 uniform sampler2D s_texture; | 436 uniform sampler2D s_texture; |
430 void main() | 437 void main() |
431 { | 438 { |
432 vec4 texColor = texture2D(s_texture, v_texCoord); | 439 vec4 texColor = texture2D(s_texture, v_texCoord); |
433 gl_FragColor = texColor * v_alpha; | 440 gl_FragColor = texColor * v_alpha; |
434 } | 441 } |
435 ); | 442 ); |
436 } | 443 } |
437 | 444 |
438 std::string FragmentShaderRGBATexRectFlipVaryingAlpha::getShaderString() const | |
439 { | |
440 // This must be paired with VertexShaderPosTexTransform to pick up the texTr
ansform uniform. | |
441 // The necessary #extension preprocessing directive breaks the SHADER and SH
ADER0 macros. | |
442 return "#extension GL_ARB_texture_rectangle : require\n" | |
443 "precision mediump float;\n" | |
444 "varying vec2 v_texCoord;\n" | |
445 "varying float v_alpha;\n" | |
446 "uniform vec4 texTransform;\n" | |
447 "uniform sampler2DRect s_texture;\n" | |
448 "void main()\n" | |
449 "{\n" | |
450 " vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, tex
Transform.w - v_texCoord.y));\n" | |
451 " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColo
r.w) * v_alpha;\n" | |
452 "}\n"; | |
453 } | |
454 | |
455 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const | 445 std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const |
456 { | 446 { |
457 return "#extension GL_ARB_texture_rectangle : require\n" | 447 return "#extension GL_ARB_texture_rectangle : require\n" |
458 "precision mediump float;\n" | 448 "precision mediump float;\n" |
459 "varying vec2 v_texCoord;\n" | 449 "varying vec2 v_texCoord;\n" |
460 "varying float v_alpha;\n" | 450 "varying float v_alpha;\n" |
461 "uniform sampler2DRect s_texture;\n" | 451 "uniform sampler2DRect s_texture;\n" |
462 "void main()\n" | 452 "void main()\n" |
463 "{\n" | 453 "{\n" |
464 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" | 454 " vec4 texColor = texture2DRect(s_texture, v_texCoord);\n" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 vec4 color2 = color; | 886 vec4 color2 = color; |
897 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; | 887 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; |
898 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 888 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
899 float picker = abs(coord.x - coord.y); | 889 float picker = abs(coord.x - coord.y); |
900 gl_FragColor = mix(color1, color2, picker) * alpha; | 890 gl_FragColor = mix(color1, color2, picker) * alpha; |
901 } | 891 } |
902 ); | 892 ); |
903 } | 893 } |
904 | 894 |
905 } // namespace cc | 895 } // namespace cc |
OLD | NEW |