OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkColorCubeFilter.h" | 8 #include "SkColorCubeFilter.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkOnce.h" | 10 #include "SkOnce.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 257 |
258 const char* nonZeroAlpha = "nonZeroAlpha"; | 258 const char* nonZeroAlpha = "nonZeroAlpha"; |
259 const char* unPMColor = "unPMColor"; | 259 const char* unPMColor = "unPMColor"; |
260 const char* cubeIdx = "cubeIdx"; | 260 const char* cubeIdx = "cubeIdx"; |
261 const char* cCoords1 = "cCoords1"; | 261 const char* cCoords1 = "cCoords1"; |
262 const char* cCoords2 = "cCoords2"; | 262 const char* cCoords2 = "cCoords2"; |
263 | 263 |
264 // Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.
0, | 264 // Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.
0, |
265 // the shader might need "#extension GL_OES_texture_3D : enable". | 265 // the shader might need "#extension GL_OES_texture_3D : enable". |
266 | 266 |
267 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; | 267 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
268 | 268 |
269 // Unpremultiply color | 269 // Unpremultiply color |
270 fsBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, a
rgs.fInputColor); | 270 fragBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha,
args.fInputColor); |
271 fsBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n", | 271 fragBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n", |
272 unPMColor, args.fInputColor, nonZeroAlpha, nonZeroAlp
ha); | 272 unPMColor, args.fInputColor, nonZeroAlpha, nonZeroA
lpha); |
273 | 273 |
274 // Fit input color into the cube. | 274 // Fit input color into the cube. |
275 fsBuilder->codeAppendf( | 275 fragBuilder->codeAppendf( |
276 "vec3 %s = vec3(%s.rg * vec2((%s - 1.0) * %s) + vec2(0.5 * %s), %s.b * (
%s - 1.0));\n", | 276 "vec3 %s = vec3(%s.rg * vec2((%s - 1.0) * %s) + vec2(0.5 * %s), %s.b * (
%s - 1.0));\n", |
277 cubeIdx, unPMColor, colorCubeSizeUni, colorCubeInvSizeUni, colorCubeInvS
izeUni, | 277 cubeIdx, unPMColor, colorCubeSizeUni, colorCubeInvSizeUni, colorCubeInvS
izeUni, |
278 unPMColor, colorCubeSizeUni); | 278 unPMColor, colorCubeSizeUni); |
279 | 279 |
280 // Compute y coord for for texture fetches. | 280 // Compute y coord for for texture fetches. |
281 fsBuilder->codeAppendf("vec2 %s = vec2(%s.r, (floor(%s.b) + %s.g) * %s);\n", | 281 fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (floor(%s.b) + %s.g) * %s);\n
", |
282 cCoords1, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSize
Uni); | 282 cCoords1, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSi
zeUni); |
283 fsBuilder->codeAppendf("vec2 %s = vec2(%s.r, (ceil(%s.b) + %s.g) * %s);\n", | 283 fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (ceil(%s.b) + %s.g) * %s);\n"
, |
284 cCoords2, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSize
Uni); | 284 cCoords2, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSi
zeUni); |
285 | 285 |
286 // Apply the cube. | 286 // Apply the cube. |
287 fsBuilder->codeAppendf("%s = vec4(mix(", args.fOutputColor); | 287 fragBuilder->codeAppendf("%s = vec4(mix(", args.fOutputColor); |
288 fsBuilder->appendTextureLookup(args.fSamplers[0], cCoords1); | 288 fragBuilder->appendTextureLookup(args.fSamplers[0], cCoords1); |
289 fsBuilder->codeAppend(".rgb, "); | 289 fragBuilder->codeAppend(".rgb, "); |
290 fsBuilder->appendTextureLookup(args.fSamplers[0], cCoords2); | 290 fragBuilder->appendTextureLookup(args.fSamplers[0], cCoords2); |
291 | 291 |
292 // Premultiply color by alpha. Note that the input alpha is not modified by
this shader. | 292 // Premultiply color by alpha. Note that the input alpha is not modified by
this shader. |
293 fsBuilder->codeAppendf(".rgb, fract(%s.b)) * vec3(%s), %s.a);\n", | 293 fragBuilder->codeAppendf(".rgb, fract(%s.b)) * vec3(%s), %s.a);\n", |
294 cubeIdx, nonZeroAlpha, args.fInputColor); | 294 cubeIdx, nonZeroAlpha, args.fInputColor); |
295 } | 295 } |
296 | 296 |
297 void GrColorCubeEffect::GLSLProcessor::onSetData(const GrGLSLProgramDataManager&
pdman, | 297 void GrColorCubeEffect::GLSLProcessor::onSetData(const GrGLSLProgramDataManager&
pdman, |
298 const GrProcessor& proc) { | 298 const GrProcessor& proc) { |
299 const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); | 299 const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); |
300 SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); | 300 SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); |
301 pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); | 301 pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); |
302 pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); | 302 pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); |
303 } | 303 } |
304 | 304 |
(...skipping 22 matching lines...) Expand all Loading... |
327 if (textureCube) { | 327 if (textureCube) { |
328 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); | 328 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); |
329 } else { | 329 } else { |
330 return nullptr; | 330 return nullptr; |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 return GrColorCubeEffect::Create(textureCube); | 334 return GrColorCubeEffect::Create(textureCube); |
335 } | 335 } |
336 #endif | 336 #endif |
OLD | NEW |