| 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 uniform vec4 texTransform[8]; | 164 uniform vec4 texTransform[8]; |
| 165 varying vec2 v_texCoord; | 165 varying vec2 v_texCoord; |
| 166 void main() | 166 void main() |
| 167 { | 167 { |
| 168 gl_Position = matrix[int(a_index)] * a_position; | 168 gl_Position = matrix[int(a_index)] * a_position; |
| 169 v_texCoord = a_texCoord * texTransform[int(a_index)].zw + texTransfo
rm[int(a_index)].xy; | 169 v_texCoord = a_texCoord * texTransform[int(a_index)].zw + texTransfo
rm[int(a_index)].xy; |
| 170 } | 170 } |
| 171 ); | 171 ); |
| 172 } | 172 } |
| 173 | 173 |
| 174 VertexShaderQuad::VertexShaderQuad() | |
| 175 : m_matrixLocation(-1) | |
| 176 , m_pointLocation(-1) | |
| 177 { | |
| 178 } | |
| 179 | |
| 180 std::string VertexShaderPosTexIdentity::getShaderString() const | 174 std::string VertexShaderPosTexIdentity::getShaderString() const |
| 181 { | 175 { |
| 182 return SHADER( | 176 return SHADER( |
| 183 attribute vec4 a_position; | 177 attribute vec4 a_position; |
| 184 varying vec2 v_texCoord; | 178 varying vec2 v_texCoord; |
| 185 void main() | 179 void main() |
| 186 { | 180 { |
| 187 gl_Position = a_position; | 181 gl_Position = a_position; |
| 188 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; | 182 v_texCoord = (a_position.xy + vec2(1.0)) * 0.5; |
| 189 } | 183 } |
| 190 ); | 184 ); |
| 191 } | 185 } |
| 192 | 186 |
| 187 VertexShaderQuad::VertexShaderQuad() |
| 188 : m_matrixLocation(-1) |
| 189 , m_pointLocation(-1) |
| 190 , m_texScaleLocation(-1) |
| 191 { |
| 192 } |
| 193 |
| 193 void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program, boo
l usingBindUniform, int* baseUniformIndex) | 194 void VertexShaderQuad::init(WebGraphicsContext3D* context, unsigned program, boo
l usingBindUniform, int* baseUniformIndex) |
| 194 { | 195 { |
| 195 static const char* shaderUniforms[] = { | 196 static const char* shaderUniforms[] = { |
| 196 "matrix", | 197 "matrix", |
| 197 "point", | 198 "point", |
| 199 "texScale", |
| 198 }; | 200 }; |
| 199 int locations[2]; | 201 int locations[3]; |
| 200 | 202 |
| 201 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; | 203 getProgramUniformLocations(context, program, shaderUniforms, arraysize(shade
rUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex)
; |
| 202 | 204 |
| 203 m_matrixLocation = locations[0]; | 205 m_matrixLocation = locations[0]; |
| 204 m_pointLocation = locations[1]; | 206 m_pointLocation = locations[1]; |
| 205 DCHECK(m_matrixLocation != -1 && m_pointLocation != -1); | 207 m_texScaleLocation = locations[2]; |
| 208 DCHECK_NE(m_matrixLocation, -1); |
| 209 DCHECK_NE(m_pointLocation, -1); |
| 210 DCHECK_NE(m_texScaleLocation, -1); |
| 206 } | 211 } |
| 207 | 212 |
| 208 std::string VertexShaderQuad::getShaderString() const | 213 std::string VertexShaderQuad::getShaderString() const |
| 209 { | 214 { |
| 210 return SHADER( | 215 return SHADER( |
| 211 attribute vec4 a_position; | 216 attribute vec4 a_position; |
| 212 attribute vec2 a_texCoord; | 217 attribute vec2 a_texCoord; |
| 213 uniform mat4 matrix; | 218 uniform mat4 matrix; |
| 214 uniform vec2 point[4]; | 219 uniform vec2 point[4]; |
| 220 uniform vec2 texScale; |
| 215 varying vec2 v_texCoord; | 221 varying vec2 v_texCoord; |
| 216 void main() | 222 void main() |
| 217 { | 223 { |
| 218 vec2 complement = abs(a_texCoord - 1.0); | 224 vec2 complement = abs(a_texCoord - 1.0); |
| 219 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); | 225 vec4 pos = vec4(0.0, 0.0, a_position.z, a_position.w); |
| 220 pos.xy += (complement.x * complement.y) * point[0]; | 226 pos.xy += (complement.x * complement.y) * point[0]; |
| 221 pos.xy += (a_texCoord.x * complement.y) * point[1]; | 227 pos.xy += (a_texCoord.x * complement.y) * point[1]; |
| 222 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; | 228 pos.xy += (a_texCoord.x * a_texCoord.y) * point[2]; |
| 223 pos.xy += (complement.x * a_texCoord.y) * point[3]; | 229 pos.xy += (complement.x * a_texCoord.y) * point[3]; |
| 224 gl_Position = matrix * pos; | 230 gl_Position = matrix * pos; |
| 225 v_texCoord = pos.xy + vec2(0.5); | 231 v_texCoord = (pos.xy + vec2(0.5)) * texScale; |
| 226 } | 232 } |
| 227 ); | 233 ); |
| 228 } | 234 } |
| 229 | 235 |
| 230 VertexShaderTile::VertexShaderTile() | 236 VertexShaderTile::VertexShaderTile() |
| 231 : m_matrixLocation(-1) | 237 : m_matrixLocation(-1) |
| 232 , m_pointLocation(-1) | 238 , m_pointLocation(-1) |
| 233 , m_vertexTexTransformLocation(-1) | 239 , m_vertexTexTransformLocation(-1) |
| 234 { | 240 { |
| 235 } | 241 } |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 vec4 color2 = color; | 874 vec4 color2 = color; |
| 869 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texT
ransform.xy; | 875 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); | 876 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 871 float picker = abs(coord.x - coord.y); | 877 float picker = abs(coord.x - coord.y); |
| 872 gl_FragColor = mix(color1, color2, picker) * alpha; | 878 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 873 } | 879 } |
| 874 ); | 880 ); |
| 875 } | 881 } |
| 876 | 882 |
| 877 } // namespace cc | 883 } // namespace cc |
| OLD | NEW |