OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
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 "SkLightingImageFilter.h" | 8 #include "SkLightingImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
14 #include "SkWriteBuffer.h" | 14 #include "SkWriteBuffer.h" |
15 #include "SkTypes.h" | 15 #include "SkTypes.h" |
16 | 16 |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
18 #include "effects/GrSingleTextureEffect.h" | 18 #include "effects/GrSingleTextureEffect.h" |
19 #include "gl/GrGLEffect.h" | 19 #include "gl/GrGLEffect.h" |
20 #include "gl/GrGLShaderBuilder.h" | 20 #include "gl/GrGLShaderBuilder.h" |
21 #include "GrEffect.h" | 21 #include "GrEffect.h" |
22 #include "GrTBackendEffectFactory.h" | 22 #include "GrTBackendEffectFactory.h" |
23 | 23 |
24 class GrGLDiffuseLightingEffect; | 24 class GrGLDiffuseLightingEffect; |
25 class GrGLSpecularLightingEffect; | 25 class GrGLSpecularLightingEffect; |
26 | 26 |
27 // For brevity | 27 // For brevity |
28 typedef GrGLUniformManager::UniformHandle UniformHandle; | 28 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
29 #endif | 29 #endif |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 const SkScalar gOneThird = SkScalarInvert(SkIntToScalar(3)); | 33 const SkScalar gOneThird = SkScalarInvert(SkIntToScalar(3)); |
34 const SkScalar gTwoThirds = SkScalarDiv(SkIntToScalar(2), SkIntToScalar(3)); | 34 const SkScalar gTwoThirds = SkScalarDiv(SkIntToScalar(2), SkIntToScalar(3)); |
35 const SkScalar gOneHalf = 0.5f; | 35 const SkScalar gOneHalf = 0.5f; |
36 const SkScalar gOneQuarter = 0.25f; | 36 const SkScalar gOneQuarter = 0.25f; |
37 | 37 |
38 #if SK_SUPPORT_GPU | 38 #if SK_SUPPORT_GPU |
39 void setUniformPoint3(const GrGLUniformManager& uman, UniformHandle uni, const S
kPoint3& point) { | 39 void setUniformPoint3(const GrGLProgramDataManager& pdman, UniformHandle uni, co
nst SkPoint3& point) { |
40 GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat)); | 40 GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat)); |
41 uman.set3fv(uni, 1, &point.fX); | 41 pdman.set3fv(uni, 1, &point.fX); |
42 } | 42 } |
43 | 43 |
44 void setUniformNormal3(const GrGLUniformManager& uman, UniformHandle uni, const
SkPoint3& point) { | 44 void setUniformNormal3(const GrGLProgramDataManager& pdman, UniformHandle uni, c
onst SkPoint3& point) { |
45 setUniformPoint3(uman, uni, SkPoint3(point.fX, point.fY, point.fZ)); | 45 setUniformPoint3(pdman, uni, SkPoint3(point.fX, point.fY, point.fZ)); |
46 } | 46 } |
47 #endif | 47 #endif |
48 | 48 |
49 // Shift matrix components to the left, as we advance pixels to the right. | 49 // Shift matrix components to the left, as we advance pixels to the right. |
50 inline void shiftMatrixLeft(int m[9]) { | 50 inline void shiftMatrixLeft(int m[9]) { |
51 m[0] = m[1]; | 51 m[0] = m[1]; |
52 m[3] = m[4]; | 52 m[3] = m[4]; |
53 m[6] = m[7]; | 53 m[6] = m[7]; |
54 m[1] = m[2]; | 54 m[1] = m[2]; |
55 m[4] = m[5]; | 55 m[4] = m[5]; |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 * the light. The expression will be used in the FS. emitLightColor writes a
n expression into | 427 * the light. The expression will be used in the FS. emitLightColor writes a
n expression into |
428 * the FS that is the color of the light. Either function may add functions
and/or uniforms to | 428 * the FS that is the color of the light. Either function may add functions
and/or uniforms to |
429 * the FS. The default of emitLightColor appends the name of the constant li
ght color uniform | 429 * the FS. The default of emitLightColor appends the name of the constant li
ght color uniform |
430 * and so this function only needs to be overridden if the light color varie
s spatially. | 430 * and so this function only needs to be overridden if the light color varie
s spatially. |
431 */ | 431 */ |
432 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) = 0; | 432 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) = 0; |
433 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight); | 433 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight); |
434 | 434 |
435 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
ht must call | 435 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
ht must call |
436 // INHERITED::setData(). | 436 // INHERITED::setData(). |
437 virtual void setData(const GrGLUniformManager&, | 437 virtual void setData(const GrGLProgramDataManager&, |
438 const SkLight* light) const; | 438 const SkLight* light) const; |
439 | 439 |
440 protected: | 440 protected: |
441 /** | 441 /** |
442 * Gets the constant light color uniform. Subclasses can use this in their e
mitLightColor | 442 * Gets the constant light color uniform. Subclasses can use this in their e
mitLightColor |
443 * function. | 443 * function. |
444 */ | 444 */ |
445 UniformHandle lightColorUni() const { return fColorUni; } | 445 UniformHandle lightColorUni() const { return fColorUni; } |
446 | 446 |
447 private: | 447 private: |
448 UniformHandle fColorUni; | 448 UniformHandle fColorUni; |
449 | 449 |
450 typedef SkRefCnt INHERITED; | 450 typedef SkRefCnt INHERITED; |
451 }; | 451 }; |
452 | 452 |
453 /////////////////////////////////////////////////////////////////////////////// | 453 /////////////////////////////////////////////////////////////////////////////// |
454 | 454 |
455 class GrGLDistantLight : public GrGLLight { | 455 class GrGLDistantLight : public GrGLLight { |
456 public: | 456 public: |
457 virtual ~GrGLDistantLight() {} | 457 virtual ~GrGLDistantLight() {} |
458 virtual void setData(const GrGLUniformManager&, | 458 virtual void setData(const GrGLProgramDataManager&, |
459 const SkLight* light) const SK_OVERRIDE; | 459 const SkLight* light) const SK_OVERRIDE; |
460 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 460 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
461 | 461 |
462 private: | 462 private: |
463 typedef GrGLLight INHERITED; | 463 typedef GrGLLight INHERITED; |
464 UniformHandle fDirectionUni; | 464 UniformHandle fDirectionUni; |
465 }; | 465 }; |
466 | 466 |
467 /////////////////////////////////////////////////////////////////////////////// | 467 /////////////////////////////////////////////////////////////////////////////// |
468 | 468 |
469 class GrGLPointLight : public GrGLLight { | 469 class GrGLPointLight : public GrGLLight { |
470 public: | 470 public: |
471 virtual ~GrGLPointLight() {} | 471 virtual ~GrGLPointLight() {} |
472 virtual void setData(const GrGLUniformManager&, | 472 virtual void setData(const GrGLProgramDataManager&, |
473 const SkLight* light) const SK_OVERRIDE; | 473 const SkLight* light) const SK_OVERRIDE; |
474 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 474 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
475 | 475 |
476 private: | 476 private: |
477 typedef GrGLLight INHERITED; | 477 typedef GrGLLight INHERITED; |
478 UniformHandle fLocationUni; | 478 UniformHandle fLocationUni; |
479 }; | 479 }; |
480 | 480 |
481 /////////////////////////////////////////////////////////////////////////////// | 481 /////////////////////////////////////////////////////////////////////////////// |
482 | 482 |
483 class GrGLSpotLight : public GrGLLight { | 483 class GrGLSpotLight : public GrGLLight { |
484 public: | 484 public: |
485 virtual ~GrGLSpotLight() {} | 485 virtual ~GrGLSpotLight() {} |
486 virtual void setData(const GrGLUniformManager&, | 486 virtual void setData(const GrGLProgramDataManager&, |
487 const SkLight* light) const SK_OVERRIDE; | 487 const SkLight* light) const SK_OVERRIDE; |
488 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 488 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
489 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight)
SK_OVERRIDE; | 489 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight)
SK_OVERRIDE; |
490 | 490 |
491 private: | 491 private: |
492 typedef GrGLLight INHERITED; | 492 typedef GrGLLight INHERITED; |
493 | 493 |
494 SkString fLightColorFunc; | 494 SkString fLightColorFunc; |
495 UniformHandle fLocationUni; | 495 UniformHandle fLocationUni; |
496 UniformHandle fExponentUni; | 496 UniformHandle fExponentUni; |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 const char* outputColor, | 1135 const char* outputColor, |
1136 const char* inputColor, | 1136 const char* inputColor, |
1137 const TransformedCoordsArray&, | 1137 const TransformedCoordsArray&, |
1138 const TextureSamplerArray&) SK_OVERRIDE; | 1138 const TextureSamplerArray&) SK_OVERRIDE; |
1139 | 1139 |
1140 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder* b); | 1140 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder* b); |
1141 | 1141 |
1142 /** | 1142 /** |
1143 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); | 1143 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); |
1144 */ | 1144 */ |
1145 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 1145 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
1146 | 1146 |
1147 protected: | 1147 protected: |
1148 virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) = 0; | 1148 virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) = 0; |
1149 | 1149 |
1150 private: | 1150 private: |
1151 typedef GrGLEffect INHERITED; | 1151 typedef GrGLEffect INHERITED; |
1152 | 1152 |
1153 UniformHandle fImageIncrementUni; | 1153 UniformHandle fImageIncrementUni; |
1154 UniformHandle fSurfaceScaleUni; | 1154 UniformHandle fSurfaceScaleUni; |
1155 GrGLLight* fLight; | 1155 GrGLLight* fLight; |
1156 }; | 1156 }; |
1157 | 1157 |
1158 /////////////////////////////////////////////////////////////////////////////// | 1158 /////////////////////////////////////////////////////////////////////////////// |
1159 | 1159 |
1160 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { | 1160 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { |
1161 public: | 1161 public: |
1162 GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory, | 1162 GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory, |
1163 const GrDrawEffect& drawEffect); | 1163 const GrDrawEffect& drawEffect); |
1164 virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRI
DE; | 1164 virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRI
DE; |
1165 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 1165 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
1166 | 1166 |
1167 private: | 1167 private: |
1168 typedef GrGLLightingEffect INHERITED; | 1168 typedef GrGLLightingEffect INHERITED; |
1169 | 1169 |
1170 UniformHandle fKDUni; | 1170 UniformHandle fKDUni; |
1171 }; | 1171 }; |
1172 | 1172 |
1173 /////////////////////////////////////////////////////////////////////////////// | 1173 /////////////////////////////////////////////////////////////////////////////// |
1174 | 1174 |
1175 class GrGLSpecularLightingEffect : public GrGLLightingEffect { | 1175 class GrGLSpecularLightingEffect : public GrGLLightingEffect { |
1176 public: | 1176 public: |
1177 GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory, | 1177 GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory, |
1178 const GrDrawEffect& effect); | 1178 const GrDrawEffect& effect); |
1179 virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRI
DE; | 1179 virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRI
DE; |
1180 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 1180 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
1181 | 1181 |
1182 private: | 1182 private: |
1183 typedef GrGLLightingEffect INHERITED; | 1183 typedef GrGLLightingEffect INHERITED; |
1184 | 1184 |
1185 UniformHandle fKSUni; | 1185 UniformHandle fKSUni; |
1186 UniformHandle fShininessUni; | 1186 UniformHandle fShininessUni; |
1187 }; | 1187 }; |
1188 | 1188 |
1189 /////////////////////////////////////////////////////////////////////////////// | 1189 /////////////////////////////////////////////////////////////////////////////// |
1190 | 1190 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 SkString modulate; | 1358 SkString modulate; |
1359 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 1359 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
1360 builder->fsCodeAppend(modulate.c_str()); | 1360 builder->fsCodeAppend(modulate.c_str()); |
1361 } | 1361 } |
1362 | 1362 |
1363 void GrGLLightingEffect::GenKey(const GrDrawEffect& drawEffect, | 1363 void GrGLLightingEffect::GenKey(const GrDrawEffect& drawEffect, |
1364 const GrGLCaps& caps, GrEffectKeyBuilder* b) { | 1364 const GrGLCaps& caps, GrEffectKeyBuilder* b) { |
1365 b->add32(drawEffect.castEffect<GrLightingEffect>().light()->type()); | 1365 b->add32(drawEffect.castEffect<GrLightingEffect>().light()->type()); |
1366 } | 1366 } |
1367 | 1367 |
1368 void GrGLLightingEffect::setData(const GrGLUniformManager& uman, | 1368 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman, |
1369 const GrDrawEffect& drawEffect) { | 1369 const GrDrawEffect& drawEffect) { |
1370 const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>()
; | 1370 const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>()
; |
1371 GrTexture* texture = lighting.texture(0); | 1371 GrTexture* texture = lighting.texture(0); |
1372 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; | 1372 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; |
1373 uman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->hei
ght()); | 1373 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he
ight()); |
1374 uman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); | 1374 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); |
1375 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting.
filterMatrix())); | 1375 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting.
filterMatrix())); |
1376 fLight->setData(uman, transformedLight); | 1376 fLight->setData(pdman, transformedLight); |
1377 } | 1377 } |
1378 | 1378 |
1379 /////////////////////////////////////////////////////////////////////////////// | 1379 /////////////////////////////////////////////////////////////////////////////// |
1380 | 1380 |
1381 /////////////////////////////////////////////////////////////////////////////// | 1381 /////////////////////////////////////////////////////////////////////////////// |
1382 | 1382 |
1383 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactor
y& factory, | 1383 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactor
y& factory, |
1384 const GrDrawEffect& drawEff
ect) | 1384 const GrDrawEffect& drawEff
ect) |
1385 : INHERITED(factory, drawEffect) { | 1385 : INHERITED(factory, drawEffect) { |
1386 } | 1386 } |
(...skipping 14 matching lines...) Expand all Loading... |
1401 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n"
, kd); | 1401 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n"
, kd); |
1402 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1
.0);\n"); | 1402 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1
.0);\n"); |
1403 builder->fsEmitFunction(kVec4f_GrSLType, | 1403 builder->fsEmitFunction(kVec4f_GrSLType, |
1404 "light", | 1404 "light", |
1405 SK_ARRAY_COUNT(gLightArgs), | 1405 SK_ARRAY_COUNT(gLightArgs), |
1406 gLightArgs, | 1406 gLightArgs, |
1407 lightBody.c_str(), | 1407 lightBody.c_str(), |
1408 funcName); | 1408 funcName); |
1409 } | 1409 } |
1410 | 1410 |
1411 void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman, | 1411 void GrGLDiffuseLightingEffect::setData(const GrGLProgramDataManager& pdman, |
1412 const GrDrawEffect& drawEffect) { | 1412 const GrDrawEffect& drawEffect) { |
1413 INHERITED::setData(uman, drawEffect); | 1413 INHERITED::setData(pdman, drawEffect); |
1414 const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLigh
tingEffect>(); | 1414 const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLigh
tingEffect>(); |
1415 uman.set1f(fKDUni, diffuse.kd()); | 1415 pdman.set1f(fKDUni, diffuse.kd()); |
1416 } | 1416 } |
1417 | 1417 |
1418 /////////////////////////////////////////////////////////////////////////////// | 1418 /////////////////////////////////////////////////////////////////////////////// |
1419 | 1419 |
1420 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, | 1420 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, |
1421 const SkLight* light, | 1421 const SkLight* light, |
1422 SkScalar surfaceScale, | 1422 SkScalar surfaceScale, |
1423 const SkMatrix& matrix, | 1423 const SkMatrix& matrix, |
1424 SkScalar ks, | 1424 SkScalar ks, |
1425 SkScalar shininess) | 1425 SkScalar shininess) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1484 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\
n"); | 1484 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\
n"); |
1485 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b))
;\n"); | 1485 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b))
;\n"); |
1486 builder->fsEmitFunction(kVec4f_GrSLType, | 1486 builder->fsEmitFunction(kVec4f_GrSLType, |
1487 "light", | 1487 "light", |
1488 SK_ARRAY_COUNT(gLightArgs), | 1488 SK_ARRAY_COUNT(gLightArgs), |
1489 gLightArgs, | 1489 gLightArgs, |
1490 lightBody.c_str(), | 1490 lightBody.c_str(), |
1491 funcName); | 1491 funcName); |
1492 } | 1492 } |
1493 | 1493 |
1494 void GrGLSpecularLightingEffect::setData(const GrGLUniformManager& uman, | 1494 void GrGLSpecularLightingEffect::setData(const GrGLProgramDataManager& pdman, |
1495 const GrDrawEffect& drawEffect) { | 1495 const GrDrawEffect& drawEffect) { |
1496 INHERITED::setData(uman, drawEffect); | 1496 INHERITED::setData(pdman, drawEffect); |
1497 const GrSpecularLightingEffect& spec = drawEffect.castEffect<GrSpecularLight
ingEffect>(); | 1497 const GrSpecularLightingEffect& spec = drawEffect.castEffect<GrSpecularLight
ingEffect>(); |
1498 uman.set1f(fKSUni, spec.ks()); | 1498 pdman.set1f(fKSUni, spec.ks()); |
1499 uman.set1f(fShininessUni, spec.shininess()); | 1499 pdman.set1f(fShininessUni, spec.shininess()); |
1500 } | 1500 } |
1501 | 1501 |
1502 /////////////////////////////////////////////////////////////////////////////// | 1502 /////////////////////////////////////////////////////////////////////////////// |
1503 void GrGLLight::emitLightColorUniform(GrGLShaderBuilder* builder) { | 1503 void GrGLLight::emitLightColorUniform(GrGLShaderBuilder* builder) { |
1504 fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 1504 fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
1505 kVec3f_GrSLType, "LightColor"); | 1505 kVec3f_GrSLType, "LightColor"); |
1506 } | 1506 } |
1507 | 1507 |
1508 void GrGLLight::emitLightColor(GrGLShaderBuilder* builder, | 1508 void GrGLLight::emitLightColor(GrGLShaderBuilder* builder, |
1509 const char *surfaceToLight) { | 1509 const char *surfaceToLight) { |
1510 builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni())); | 1510 builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni())); |
1511 } | 1511 } |
1512 | 1512 |
1513 void GrGLLight::setData(const GrGLUniformManager& uman, | 1513 void GrGLLight::setData(const GrGLProgramDataManager& pdman, |
1514 const SkLight* light) const { | 1514 const SkLight* light) const { |
1515 setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToSca
lar(255))); | 1515 setUniformPoint3(pdman, fColorUni, light->color() * SkScalarInvert(SkIntToSc
alar(255))); |
1516 } | 1516 } |
1517 | 1517 |
1518 /////////////////////////////////////////////////////////////////////////////// | 1518 /////////////////////////////////////////////////////////////////////////////// |
1519 | 1519 |
1520 void GrGLDistantLight::setData(const GrGLUniformManager& uman, | 1520 void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman, |
1521 const SkLight* light) const { | 1521 const SkLight* light) const { |
1522 INHERITED::setData(uman, light); | 1522 INHERITED::setData(pdman, light); |
1523 SkASSERT(light->type() == SkLight::kDistant_LightType); | 1523 SkASSERT(light->type() == SkLight::kDistant_LightType); |
1524 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); | 1524 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); |
1525 setUniformNormal3(uman, fDirectionUni, distantLight->direction()); | 1525 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); |
1526 } | 1526 } |
1527 | 1527 |
1528 void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char
* z) { | 1528 void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char
* z) { |
1529 const char* dir; | 1529 const char* dir; |
1530 fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec3f_GrSLType, | 1530 fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec3f_GrSLType, |
1531 "LightDirection", &dir); | 1531 "LightDirection", &dir); |
1532 builder->fsCodeAppend(dir); | 1532 builder->fsCodeAppend(dir); |
1533 } | 1533 } |
1534 | 1534 |
1535 /////////////////////////////////////////////////////////////////////////////// | 1535 /////////////////////////////////////////////////////////////////////////////// |
1536 | 1536 |
1537 void GrGLPointLight::setData(const GrGLUniformManager& uman, | 1537 void GrGLPointLight::setData(const GrGLProgramDataManager& pdman, |
1538 const SkLight* light) const { | 1538 const SkLight* light) const { |
1539 INHERITED::setData(uman, light); | 1539 INHERITED::setData(pdman, light); |
1540 SkASSERT(light->type() == SkLight::kPoint_LightType); | 1540 SkASSERT(light->type() == SkLight::kPoint_LightType); |
1541 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); | 1541 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); |
1542 setUniformPoint3(uman, fLocationUni, pointLight->location()); | 1542 setUniformPoint3(pdman, fLocationUni, pointLight->location()); |
1543 } | 1543 } |
1544 | 1544 |
1545 void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char*
z) { | 1545 void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char*
z) { |
1546 const char* loc; | 1546 const char* loc; |
1547 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec3f_GrSLType, | 1547 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec3f_GrSLType, |
1548 "LightLocation", &loc); | 1548 "LightLocation", &loc); |
1549 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->frag
mentPosition(), z); | 1549 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->frag
mentPosition(), z); |
1550 } | 1550 } |
1551 | 1551 |
1552 /////////////////////////////////////////////////////////////////////////////// | 1552 /////////////////////////////////////////////////////////////////////////////// |
1553 | 1553 |
1554 void GrGLSpotLight::setData(const GrGLUniformManager& uman, | 1554 void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman, |
1555 const SkLight* light) const { | 1555 const SkLight* light) const { |
1556 INHERITED::setData(uman, light); | 1556 INHERITED::setData(pdman, light); |
1557 SkASSERT(light->type() == SkLight::kSpot_LightType); | 1557 SkASSERT(light->type() == SkLight::kSpot_LightType); |
1558 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); | 1558 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); |
1559 setUniformPoint3(uman, fLocationUni, spotLight->location()); | 1559 setUniformPoint3(pdman, fLocationUni, spotLight->location()); |
1560 uman.set1f(fExponentUni, spotLight->specularExponent()); | 1560 pdman.set1f(fExponentUni, spotLight->specularExponent()); |
1561 uman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); | 1561 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); |
1562 uman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); | 1562 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); |
1563 uman.set1f(fConeScaleUni, spotLight->coneScale()); | 1563 pdman.set1f(fConeScaleUni, spotLight->coneScale()); |
1564 setUniformNormal3(uman, fSUni, spotLight->s()); | 1564 setUniformNormal3(pdman, fSUni, spotLight->s()); |
1565 } | 1565 } |
1566 | 1566 |
1567 void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z
) { | 1567 void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z
) { |
1568 const char* location; | 1568 const char* location; |
1569 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 1569 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
1570 kVec3f_GrSLType, "LightLocation", &locati
on); | 1570 kVec3f_GrSLType, "LightLocation", &locati
on); |
1571 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", | 1571 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", |
1572 location, builder->fragmentPosition(), z); | 1572 location, builder->fragmentPosition(), z); |
1573 } | 1573 } |
1574 | 1574 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 | 1616 |
1617 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1617 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1618 } | 1618 } |
1619 | 1619 |
1620 #endif | 1620 #endif |
1621 | 1621 |
1622 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1622 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1623 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1623 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1624 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1624 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1625 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1625 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |