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" |
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 SkFAIL("Unexpected value."); | 1199 SkFAIL("Unexpected value."); |
1200 return NULL; | 1200 return NULL; |
1201 } | 1201 } |
1202 } | 1202 } |
1203 | 1203 |
1204 } | 1204 } |
1205 | 1205 |
1206 class GrGLLightingEffect : public GrGLEffect { | 1206 class GrGLLightingEffect : public GrGLEffect { |
1207 public: | 1207 public: |
1208 GrGLLightingEffect(const GrBackendEffectFactory& factory, | 1208 GrGLLightingEffect(const GrBackendEffectFactory& factory, |
1209 const GrDrawEffect& effect); | 1209 const GrEffect& effect); |
1210 virtual ~GrGLLightingEffect(); | 1210 virtual ~GrGLLightingEffect(); |
1211 | 1211 |
1212 virtual void emitCode(GrGLProgramBuilder*, | 1212 virtual void emitCode(GrGLProgramBuilder*, |
1213 const GrDrawEffect&, | 1213 const GrEffect&, |
1214 const GrEffectKey&, | 1214 const GrEffectKey&, |
1215 const char* outputColor, | 1215 const char* outputColor, |
1216 const char* inputColor, | 1216 const char* inputColor, |
1217 const TransformedCoordsArray&, | 1217 const TransformedCoordsArray&, |
1218 const TextureSamplerArray&) SK_OVERRIDE; | 1218 const TextureSamplerArray&) SK_OVERRIDE; |
1219 | 1219 |
1220 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder* b); | 1220 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild
er* b); |
1221 | 1221 |
1222 /** | 1222 /** |
1223 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); | 1223 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); |
1224 */ | 1224 */ |
1225 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 1225 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; |
1226 | 1226 |
1227 protected: | 1227 protected: |
1228 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) = 0; | 1228 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) = 0; |
1229 | 1229 |
1230 private: | 1230 private: |
1231 typedef GrGLEffect INHERITED; | 1231 typedef GrGLEffect INHERITED; |
1232 | 1232 |
1233 UniformHandle fImageIncrementUni; | 1233 UniformHandle fImageIncrementUni; |
1234 UniformHandle fSurfaceScaleUni; | 1234 UniformHandle fSurfaceScaleUni; |
1235 GrGLLight* fLight; | 1235 GrGLLight* fLight; |
1236 }; | 1236 }; |
1237 | 1237 |
1238 /////////////////////////////////////////////////////////////////////////////// | 1238 /////////////////////////////////////////////////////////////////////////////// |
1239 | 1239 |
1240 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { | 1240 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { |
1241 public: | 1241 public: |
1242 GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory, | 1242 GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory, |
1243 const GrDrawEffect& drawEffect); | 1243 const GrEffect& effect); |
1244 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) SK_OVERR
IDE; | 1244 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) SK_OVERR
IDE; |
1245 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 1245 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; |
1246 | 1246 |
1247 private: | 1247 private: |
1248 typedef GrGLLightingEffect INHERITED; | 1248 typedef GrGLLightingEffect INHERITED; |
1249 | 1249 |
1250 UniformHandle fKDUni; | 1250 UniformHandle fKDUni; |
1251 }; | 1251 }; |
1252 | 1252 |
1253 /////////////////////////////////////////////////////////////////////////////// | 1253 /////////////////////////////////////////////////////////////////////////////// |
1254 | 1254 |
1255 class GrGLSpecularLightingEffect : public GrGLLightingEffect { | 1255 class GrGLSpecularLightingEffect : public GrGLLightingEffect { |
1256 public: | 1256 public: |
1257 GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory, | 1257 GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory, |
1258 const GrDrawEffect& effect); | 1258 const GrEffect& effect); |
1259 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) SK_OVERR
IDE; | 1259 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) SK_OVERR
IDE; |
1260 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 1260 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; |
1261 | 1261 |
1262 private: | 1262 private: |
1263 typedef GrGLLightingEffect INHERITED; | 1263 typedef GrGLLightingEffect INHERITED; |
1264 | 1264 |
1265 UniformHandle fKSUni; | 1265 UniformHandle fKSUni; |
1266 UniformHandle fShininessUni; | 1266 UniformHandle fShininessUni; |
1267 }; | 1267 }; |
1268 | 1268 |
1269 /////////////////////////////////////////////////////////////////////////////// | 1269 /////////////////////////////////////////////////////////////////////////////// |
1270 | 1270 |
1271 GrLightingEffect::GrLightingEffect(GrTexture* texture, | 1271 GrLightingEffect::GrLightingEffect(GrTexture* texture, |
1272 const SkLight* light, | 1272 const SkLight* light, |
1273 SkScalar surfaceScale, | 1273 SkScalar surfaceScale, |
1274 const SkMatrix& matrix) | 1274 const SkMatrix& matrix) |
1275 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)) | 1275 : INHERITED(texture, GrCoordTransform::MakeDivByTextureWHMatrix(texture)) |
1276 , fLight(light) | 1276 , fLight(light) |
1277 , fSurfaceScale(surfaceScale) | 1277 , fSurfaceScale(surfaceScale) |
1278 , fFilterMatrix(matrix) { | 1278 , fFilterMatrix(matrix) { |
1279 fLight->ref(); | 1279 fLight->ref(); |
1280 if (light->requiresFragmentPosition()) { | 1280 if (light->requiresFragmentPosition()) { |
1281 this->setWillReadFragmentPosition(); | 1281 this->setWillReadFragmentPosition(); |
1282 } | 1282 } |
1283 } | 1283 } |
1284 | 1284 |
1285 GrLightingEffect::~GrLightingEffect() { | 1285 GrLightingEffect::~GrLightingEffect() { |
1286 fLight->unref(); | 1286 fLight->unref(); |
1287 } | 1287 } |
1288 | 1288 |
1289 bool GrLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1289 bool GrLightingEffect::onIsEqual(const GrEffect& sBase) const { |
1290 const GrLightingEffect& s = CastEffect<GrLightingEffect>(sBase); | 1290 const GrLightingEffect& s = GrEffect::CastEffect<GrLightingEffect>(sBase); |
1291 return this->texture(0) == s.texture(0) && | 1291 return this->texture(0) == s.texture(0) && |
1292 fLight->isEqual(*s.fLight) && | 1292 fLight->isEqual(*s.fLight) && |
1293 fSurfaceScale == s.fSurfaceScale; | 1293 fSurfaceScale == s.fSurfaceScale; |
1294 } | 1294 } |
1295 | 1295 |
1296 /////////////////////////////////////////////////////////////////////////////// | 1296 /////////////////////////////////////////////////////////////////////////////// |
1297 | 1297 |
1298 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, | 1298 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, |
1299 const SkLight* light, | 1299 const SkLight* light, |
1300 SkScalar surfaceScale, | 1300 SkScalar surfaceScale, |
1301 const SkMatrix& matrix, | 1301 const SkMatrix& matrix, |
1302 SkScalar kd) | 1302 SkScalar kd) |
1303 : INHERITED(texture, light, surfaceScale, matrix), fKD(kd) { | 1303 : INHERITED(texture, light, surfaceScale, matrix), fKD(kd) { |
1304 } | 1304 } |
1305 | 1305 |
1306 const GrBackendEffectFactory& GrDiffuseLightingEffect::getFactory() const { | 1306 const GrBackendEffectFactory& GrDiffuseLightingEffect::getFactory() const { |
1307 return GrTBackendEffectFactory<GrDiffuseLightingEffect>::getInstance(); | 1307 return GrTBackendEffectFactory<GrDiffuseLightingEffect>::getInstance(); |
1308 } | 1308 } |
1309 | 1309 |
1310 bool GrDiffuseLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1310 bool GrDiffuseLightingEffect::onIsEqual(const GrEffect& sBase) const { |
1311 const GrDiffuseLightingEffect& s = CastEffect<GrDiffuseLightingEffect>(sBase
); | 1311 const GrDiffuseLightingEffect& s = GrEffect::CastEffect<GrDiffuseLightingEff
ect>(sBase); |
1312 return INHERITED::onIsEqual(sBase) && | 1312 return INHERITED::onIsEqual(sBase) && |
1313 this->kd() == s.kd(); | 1313 this->kd() == s.kd(); |
1314 } | 1314 } |
1315 | 1315 |
1316 GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect); | 1316 GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect); |
1317 | 1317 |
1318 GrEffect* GrDiffuseLightingEffect::TestCreate(SkRandom* random, | 1318 GrEffect* GrDiffuseLightingEffect::TestCreate(SkRandom* random, |
1319 GrContext* context, | 1319 GrContext* context, |
1320 const GrDrawTargetCaps&, | 1320 const GrDrawTargetCaps&, |
1321 GrTexture* textures[]) { | 1321 GrTexture* textures[]) { |
1322 SkScalar surfaceScale = random->nextSScalar1(); | 1322 SkScalar surfaceScale = random->nextSScalar1(); |
1323 SkScalar kd = random->nextUScalar1(); | 1323 SkScalar kd = random->nextUScalar1(); |
1324 SkAutoTUnref<SkLight> light(create_random_light(random)); | 1324 SkAutoTUnref<SkLight> light(create_random_light(random)); |
1325 SkMatrix matrix; | 1325 SkMatrix matrix; |
1326 for (int i = 0; i < 9; i++) { | 1326 for (int i = 0; i < 9; i++) { |
1327 matrix[i] = random->nextUScalar1(); | 1327 matrix[i] = random->nextUScalar1(); |
1328 } | 1328 } |
1329 return GrDiffuseLightingEffect::Create(textures[GrEffectUnitTest::kAlphaText
ureIdx], | 1329 return GrDiffuseLightingEffect::Create(textures[GrEffectUnitTest::kAlphaText
ureIdx], |
1330 light, surfaceScale, matrix, kd); | 1330 light, surfaceScale, matrix, kd); |
1331 } | 1331 } |
1332 | 1332 |
1333 | 1333 |
1334 /////////////////////////////////////////////////////////////////////////////// | 1334 /////////////////////////////////////////////////////////////////////////////// |
1335 | 1335 |
1336 GrGLLightingEffect::GrGLLightingEffect(const GrBackendEffectFactory& factory, | 1336 GrGLLightingEffect::GrGLLightingEffect(const GrBackendEffectFactory& factory, |
1337 const GrDrawEffect& drawEffect) | 1337 const GrEffect& effect) |
1338 : INHERITED(factory) { | 1338 : INHERITED(factory) { |
1339 const GrLightingEffect& m = drawEffect.castEffect<GrLightingEffect>(); | 1339 const GrLightingEffect& m = GrEffect::CastEffect<GrLightingEffect>(effect); |
1340 fLight = m.light()->createGLLight(); | 1340 fLight = m.light()->createGLLight(); |
1341 } | 1341 } |
1342 | 1342 |
1343 GrGLLightingEffect::~GrGLLightingEffect() { | 1343 GrGLLightingEffect::~GrGLLightingEffect() { |
1344 delete fLight; | 1344 delete fLight; |
1345 } | 1345 } |
1346 | 1346 |
1347 void GrGLLightingEffect::emitCode(GrGLProgramBuilder* builder, | 1347 void GrGLLightingEffect::emitCode(GrGLProgramBuilder* builder, |
1348 const GrDrawEffect&, | 1348 const GrEffect&, |
1349 const GrEffectKey& key, | 1349 const GrEffectKey& key, |
1350 const char* outputColor, | 1350 const char* outputColor, |
1351 const char* inputColor, | 1351 const char* inputColor, |
1352 const TransformedCoordsArray& coords, | 1352 const TransformedCoordsArray& coords, |
1353 const TextureSamplerArray& samplers) { | 1353 const TextureSamplerArray& samplers) { |
1354 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 1354 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
1355 kVec2f_GrSLType, | 1355 kVec2f_GrSLType, |
1356 "ImageIncrement"); | 1356 "ImageIncrement"); |
1357 fSurfaceScaleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 1357 fSurfaceScaleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, |
1358 kFloat_GrSLType, | 1358 kFloat_GrSLType, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 fsBuilder->codeAppend(";\n"); | 1434 fsBuilder->codeAppend(";\n"); |
1435 fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", | 1435 fsBuilder->codeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", |
1436 outputColor, lightFunc.c_str(), interiorNormalName.c_
str(), surfScale); | 1436 outputColor, lightFunc.c_str(), interiorNormalName.c_
str(), surfScale); |
1437 fLight->emitLightColor(builder, "surfaceToLight"); | 1437 fLight->emitLightColor(builder, "surfaceToLight"); |
1438 fsBuilder->codeAppend(");\n"); | 1438 fsBuilder->codeAppend(");\n"); |
1439 SkString modulate; | 1439 SkString modulate; |
1440 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 1440 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
1441 fsBuilder->codeAppend(modulate.c_str()); | 1441 fsBuilder->codeAppend(modulate.c_str()); |
1442 } | 1442 } |
1443 | 1443 |
1444 void GrGLLightingEffect::GenKey(const GrDrawEffect& drawEffect, | 1444 void GrGLLightingEffect::GenKey(const GrEffect& effect, |
1445 const GrGLCaps& caps, GrEffectKeyBuilder* b) { | 1445 const GrGLCaps& caps, GrEffectKeyBuilder* b) { |
1446 b->add32(drawEffect.castEffect<GrLightingEffect>().light()->type()); | 1446 b->add32(GrEffect::CastEffect<GrLightingEffect>(effect).light()->type()); |
1447 } | 1447 } |
1448 | 1448 |
1449 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman, | 1449 void GrGLLightingEffect::setData(const GrGLProgramDataManager& pdman, |
1450 const GrDrawEffect& drawEffect) { | 1450 const GrEffect& effect) { |
1451 const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>()
; | 1451 const GrLightingEffect& lighting = GrEffect::CastEffect<GrLightingEffect>(ef
fect); |
1452 GrTexture* texture = lighting.texture(0); | 1452 GrTexture* texture = lighting.texture(0); |
1453 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; | 1453 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; |
1454 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he
ight()); | 1454 pdman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->he
ight()); |
1455 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); | 1455 pdman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); |
1456 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting.
filterMatrix())); | 1456 SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting.
filterMatrix())); |
1457 fLight->setData(pdman, transformedLight); | 1457 fLight->setData(pdman, transformedLight); |
1458 } | 1458 } |
1459 | 1459 |
1460 /////////////////////////////////////////////////////////////////////////////// | 1460 /////////////////////////////////////////////////////////////////////////////// |
1461 | 1461 |
1462 /////////////////////////////////////////////////////////////////////////////// | 1462 /////////////////////////////////////////////////////////////////////////////// |
1463 | 1463 |
1464 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactor
y& factory, | 1464 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactor
y& factory, |
1465 const GrDrawEffect& drawEff
ect) | 1465 const GrEffect& effect) |
1466 : INHERITED(factory, drawEffect) { | 1466 : INHERITED(factory, effect) { |
1467 } | 1467 } |
1468 | 1468 |
1469 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLProgramBuilder* builder, SkStr
ing* funcName) { | 1469 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLProgramBuilder* builder, SkStr
ing* funcName) { |
1470 const char* kd; | 1470 const char* kd; |
1471 fKDUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1471 fKDUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1472 kFloat_GrSLType, | 1472 kFloat_GrSLType, |
1473 "KD", | 1473 "KD", |
1474 &kd); | 1474 &kd); |
1475 | 1475 |
1476 static const GrGLShaderVar gLightArgs[] = { | 1476 static const GrGLShaderVar gLightArgs[] = { |
1477 GrGLShaderVar("normal", kVec3f_GrSLType), | 1477 GrGLShaderVar("normal", kVec3f_GrSLType), |
1478 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType), | 1478 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType), |
1479 GrGLShaderVar("lightColor", kVec3f_GrSLType) | 1479 GrGLShaderVar("lightColor", kVec3f_GrSLType) |
1480 }; | 1480 }; |
1481 SkString lightBody; | 1481 SkString lightBody; |
1482 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n"
, kd); | 1482 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n"
, kd); |
1483 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1
.0);\n"); | 1483 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1
.0);\n"); |
1484 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType, | 1484 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType, |
1485 "light", | 1485 "light", |
1486 SK_ARRAY_COUNT(gLightArgs)
, | 1486 SK_ARRAY_COUNT(gLightArgs)
, |
1487 gLightArgs, | 1487 gLightArgs, |
1488 lightBody.c_str(), | 1488 lightBody.c_str(), |
1489 funcName); | 1489 funcName); |
1490 } | 1490 } |
1491 | 1491 |
1492 void GrGLDiffuseLightingEffect::setData(const GrGLProgramDataManager& pdman, | 1492 void GrGLDiffuseLightingEffect::setData(const GrGLProgramDataManager& pdman, |
1493 const GrDrawEffect& drawEffect) { | 1493 const GrEffect& effect) { |
1494 INHERITED::setData(pdman, drawEffect); | 1494 INHERITED::setData(pdman, effect); |
1495 const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLigh
tingEffect>(); | 1495 const GrDiffuseLightingEffect& diffuse = GrEffect::CastEffect<GrDiffuseLight
ingEffect>(effect); |
1496 pdman.set1f(fKDUni, diffuse.kd()); | 1496 pdman.set1f(fKDUni, diffuse.kd()); |
1497 } | 1497 } |
1498 | 1498 |
1499 /////////////////////////////////////////////////////////////////////////////// | 1499 /////////////////////////////////////////////////////////////////////////////// |
1500 | 1500 |
1501 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, | 1501 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, |
1502 const SkLight* light, | 1502 const SkLight* light, |
1503 SkScalar surfaceScale, | 1503 SkScalar surfaceScale, |
1504 const SkMatrix& matrix, | 1504 const SkMatrix& matrix, |
1505 SkScalar ks, | 1505 SkScalar ks, |
1506 SkScalar shininess) | 1506 SkScalar shininess) |
1507 : INHERITED(texture, light, surfaceScale, matrix), | 1507 : INHERITED(texture, light, surfaceScale, matrix), |
1508 fKS(ks), | 1508 fKS(ks), |
1509 fShininess(shininess) { | 1509 fShininess(shininess) { |
1510 } | 1510 } |
1511 | 1511 |
1512 const GrBackendEffectFactory& GrSpecularLightingEffect::getFactory() const { | 1512 const GrBackendEffectFactory& GrSpecularLightingEffect::getFactory() const { |
1513 return GrTBackendEffectFactory<GrSpecularLightingEffect>::getInstance(); | 1513 return GrTBackendEffectFactory<GrSpecularLightingEffect>::getInstance(); |
1514 } | 1514 } |
1515 | 1515 |
1516 bool GrSpecularLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1516 bool GrSpecularLightingEffect::onIsEqual(const GrEffect& sBase) const { |
1517 const GrSpecularLightingEffect& s = CastEffect<GrSpecularLightingEffect>(sBa
se); | 1517 const GrSpecularLightingEffect& s = GrEffect::CastEffect<GrSpecularLightingE
ffect>(sBase); |
1518 return INHERITED::onIsEqual(sBase) && | 1518 return INHERITED::onIsEqual(sBase) && |
1519 this->ks() == s.ks() && | 1519 this->ks() == s.ks() && |
1520 this->shininess() == s.shininess(); | 1520 this->shininess() == s.shininess(); |
1521 } | 1521 } |
1522 | 1522 |
1523 GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect); | 1523 GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect); |
1524 | 1524 |
1525 GrEffect* GrSpecularLightingEffect::TestCreate(SkRandom* random, | 1525 GrEffect* GrSpecularLightingEffect::TestCreate(SkRandom* random, |
1526 GrContext* context, | 1526 GrContext* context, |
1527 const GrDrawTargetCaps&, | 1527 const GrDrawTargetCaps&, |
1528 GrTexture* textures[]) { | 1528 GrTexture* textures[]) { |
1529 SkScalar surfaceScale = random->nextSScalar1(); | 1529 SkScalar surfaceScale = random->nextSScalar1(); |
1530 SkScalar ks = random->nextUScalar1(); | 1530 SkScalar ks = random->nextUScalar1(); |
1531 SkScalar shininess = random->nextUScalar1(); | 1531 SkScalar shininess = random->nextUScalar1(); |
1532 SkAutoTUnref<SkLight> light(create_random_light(random)); | 1532 SkAutoTUnref<SkLight> light(create_random_light(random)); |
1533 SkMatrix matrix; | 1533 SkMatrix matrix; |
1534 for (int i = 0; i < 9; i++) { | 1534 for (int i = 0; i < 9; i++) { |
1535 matrix[i] = random->nextUScalar1(); | 1535 matrix[i] = random->nextUScalar1(); |
1536 } | 1536 } |
1537 return GrSpecularLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTex
tureIdx], | 1537 return GrSpecularLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTex
tureIdx], |
1538 light, surfaceScale, matrix, ks, shi
niness); | 1538 light, surfaceScale, matrix, ks, shi
niness); |
1539 } | 1539 } |
1540 | 1540 |
1541 /////////////////////////////////////////////////////////////////////////////// | 1541 /////////////////////////////////////////////////////////////////////////////// |
1542 | 1542 |
1543 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFact
ory& factory, | 1543 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFact
ory& factory, |
1544 const GrDrawEffect& drawE
ffect) | 1544 const GrEffect& effect) |
1545 : INHERITED(factory, drawEffect) { | 1545 : INHERITED(factory, effect) { |
1546 } | 1546 } |
1547 | 1547 |
1548 void GrGLSpecularLightingEffect::emitLightFunc(GrGLProgramBuilder* builder, SkSt
ring* funcName) { | 1548 void GrGLSpecularLightingEffect::emitLightFunc(GrGLProgramBuilder* builder, SkSt
ring* funcName) { |
1549 const char* ks; | 1549 const char* ks; |
1550 const char* shininess; | 1550 const char* shininess; |
1551 | 1551 |
1552 fKSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1552 fKSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1553 kFloat_GrSLType, "KS", &ks); | 1553 kFloat_GrSLType, "KS", &ks); |
1554 fShininessUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, | 1554 fShininessUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, |
1555 kFloat_GrSLType, "Shininess", &shininess
); | 1555 kFloat_GrSLType, "Shininess", &shininess
); |
(...skipping 10 matching lines...) Expand all Loading... |
1566 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b))
;\n"); | 1566 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b))
;\n"); |
1567 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType, | 1567 builder->getFragmentShaderBuilder()->emitFunction(kVec4f_GrSLType, |
1568 "light", | 1568 "light", |
1569 SK_ARRAY_COUNT(gLightArgs)
, | 1569 SK_ARRAY_COUNT(gLightArgs)
, |
1570 gLightArgs, | 1570 gLightArgs, |
1571 lightBody.c_str(), | 1571 lightBody.c_str(), |
1572 funcName); | 1572 funcName); |
1573 } | 1573 } |
1574 | 1574 |
1575 void GrGLSpecularLightingEffect::setData(const GrGLProgramDataManager& pdman, | 1575 void GrGLSpecularLightingEffect::setData(const GrGLProgramDataManager& pdman, |
1576 const GrDrawEffect& drawEffect) { | 1576 const GrEffect& effect) { |
1577 INHERITED::setData(pdman, drawEffect); | 1577 INHERITED::setData(pdman, effect); |
1578 const GrSpecularLightingEffect& spec = drawEffect.castEffect<GrSpecularLight
ingEffect>(); | 1578 const GrSpecularLightingEffect& spec = GrEffect::CastEffect<GrSpecularLighti
ngEffect>(effect); |
1579 pdman.set1f(fKSUni, spec.ks()); | 1579 pdman.set1f(fKSUni, spec.ks()); |
1580 pdman.set1f(fShininessUni, spec.shininess()); | 1580 pdman.set1f(fShininessUni, spec.shininess()); |
1581 } | 1581 } |
1582 | 1582 |
1583 /////////////////////////////////////////////////////////////////////////////// | 1583 /////////////////////////////////////////////////////////////////////////////// |
1584 void GrGLLight::emitLightColorUniform(GrGLProgramBuilder* builder) { | 1584 void GrGLLight::emitLightColorUniform(GrGLProgramBuilder* builder) { |
1585 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1585 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1586 kVec3f_GrSLType, "LightColor"); | 1586 kVec3f_GrSLType, "LightColor"); |
1587 } | 1587 } |
1588 | 1588 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 | 1703 |
1704 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1704 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1705 } | 1705 } |
1706 | 1706 |
1707 #endif | 1707 #endif |
1708 | 1708 |
1709 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1709 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1710 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1710 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1711 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1711 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1712 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1712 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |