Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: src/effects/SkLightingImageFilter.cpp

Issue 23826002: Rename ShaderType enum to ShaderVisibility (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 1200
1201 void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder, 1201 void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
1202 const GrDrawEffect&, 1202 const GrDrawEffect&,
1203 EffectKey key, 1203 EffectKey key,
1204 const char* outputColor, 1204 const char* outputColor,
1205 const char* inputColor, 1205 const char* inputColor,
1206 const TextureSamplerArray& samplers) { 1206 const TextureSamplerArray& samplers) {
1207 SkString coords; 1207 SkString coords;
1208 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); 1208 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
1209 1209
1210 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader Type, 1210 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity,
1211 kVec2f_GrSLType, 1211 kVec2f_GrSLType,
1212 "ImageIncrement"); 1212 "ImageIncrement");
1213 fSurfaceScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderTy pe, 1213 fSurfaceScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty,
1214 kFloat_GrSLType, 1214 kFloat_GrSLType,
1215 "SurfaceScale"); 1215 "SurfaceScale");
1216 fLight->emitLightColorUniform(builder); 1216 fLight->emitLightColorUniform(builder);
1217 SkString lightFunc; 1217 SkString lightFunc;
1218 this->emitLightFunc(builder, &lightFunc); 1218 this->emitLightFunc(builder, &lightFunc);
1219 static const GrGLShaderVar gSobelArgs[] = { 1219 static const GrGLShaderVar gSobelArgs[] = {
1220 GrGLShaderVar("a", kFloat_GrSLType), 1220 GrGLShaderVar("a", kFloat_GrSLType),
1221 GrGLShaderVar("b", kFloat_GrSLType), 1221 GrGLShaderVar("b", kFloat_GrSLType),
1222 GrGLShaderVar("c", kFloat_GrSLType), 1222 GrGLShaderVar("c", kFloat_GrSLType),
1223 GrGLShaderVar("d", kFloat_GrSLType), 1223 GrGLShaderVar("d", kFloat_GrSLType),
1224 GrGLShaderVar("e", kFloat_GrSLType), 1224 GrGLShaderVar("e", kFloat_GrSLType),
1225 GrGLShaderVar("f", kFloat_GrSLType), 1225 GrGLShaderVar("f", kFloat_GrSLType),
1226 GrGLShaderVar("scale", kFloat_GrSLType), 1226 GrGLShaderVar("scale", kFloat_GrSLType),
1227 }; 1227 };
1228 SkString sobelFuncName; 1228 SkString sobelFuncName;
1229 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1229 builder->fsEmitFunction(kFloat_GrSLType,
1230 kFloat_GrSLType, 1230 "sobel",
1231 "sobel", 1231 SK_ARRAY_COUNT(gSobelArgs),
1232 SK_ARRAY_COUNT(gSobelArgs), 1232 gSobelArgs,
1233 gSobelArgs, 1233 "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scal e;\n",
1234 "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scale; \n", 1234 &sobelFuncName);
1235 &sobelFuncName);
1236 static const GrGLShaderVar gPointToNormalArgs[] = { 1235 static const GrGLShaderVar gPointToNormalArgs[] = {
1237 GrGLShaderVar("x", kFloat_GrSLType), 1236 GrGLShaderVar("x", kFloat_GrSLType),
1238 GrGLShaderVar("y", kFloat_GrSLType), 1237 GrGLShaderVar("y", kFloat_GrSLType),
1239 GrGLShaderVar("scale", kFloat_GrSLType), 1238 GrGLShaderVar("scale", kFloat_GrSLType),
1240 }; 1239 };
1241 SkString pointToNormalName; 1240 SkString pointToNormalName;
1242 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1241 builder->fsEmitFunction(kVec3f_GrSLType,
1243 kVec3f_GrSLType, 1242 "pointToNormal",
1244 "pointToNormal", 1243 SK_ARRAY_COUNT(gPointToNormalArgs),
1245 SK_ARRAY_COUNT(gPointToNormalArgs), 1244 gPointToNormalArgs,
1246 gPointToNormalArgs, 1245 "\treturn normalize(vec3(-x * scale, y * scale, 1)); \n",
1247 "\treturn normalize(vec3(-x * scale, y * scale, 1));\n ", 1246 &pointToNormalName);
1248 &pointToNormalName);
1249 1247
1250 static const GrGLShaderVar gInteriorNormalArgs[] = { 1248 static const GrGLShaderVar gInteriorNormalArgs[] = {
1251 GrGLShaderVar("m", kFloat_GrSLType, 9), 1249 GrGLShaderVar("m", kFloat_GrSLType, 9),
1252 GrGLShaderVar("surfaceScale", kFloat_GrSLType), 1250 GrGLShaderVar("surfaceScale", kFloat_GrSLType),
1253 }; 1251 };
1254 SkString interiorNormalBody; 1252 SkString interiorNormalBody;
1255 interiorNormalBody.appendf("\treturn %s(%s(m[0], m[2], m[3], m[5], m[6], m[8 ], 0.25),\n" 1253 interiorNormalBody.appendf("\treturn %s(%s(m[0], m[2], m[3], m[5], m[6], m[8 ], 0.25),\n"
1256 "\t %s(m[0], m[6], m[1], m[7], m[2], m[8], 0.25),\n" 1254 "\t %s(m[0], m[6], m[1], m[7], m[2], m[8], 0.25),\n"
1257 "\t surfaceScale);\n", 1255 "\t surfaceScale);\n",
1258 pointToNormalName.c_str(), 1256 pointToNormalName.c_str(),
1259 sobelFuncName.c_str(), 1257 sobelFuncName.c_str(),
1260 sobelFuncName.c_str()); 1258 sobelFuncName.c_str());
1261 SkString interiorNormalName; 1259 SkString interiorNormalName;
1262 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1260 builder->fsEmitFunction(kVec3f_GrSLType,
1263 kVec3f_GrSLType, 1261 "interiorNormal",
1264 "interiorNormal", 1262 SK_ARRAY_COUNT(gInteriorNormalArgs),
1265 SK_ARRAY_COUNT(gInteriorNormalArgs), 1263 gInteriorNormalArgs,
1266 gInteriorNormalArgs, 1264 interiorNormalBody.c_str(),
1267 interiorNormalBody.c_str(), 1265 &interiorNormalName);
1268 &interiorNormalName);
1269 1266
1270 builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str()); 1267 builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str());
1271 builder->fsCodeAppend("\t\tfloat m[9];\n"); 1268 builder->fsCodeAppend("\t\tfloat m[9];\n");
1272 1269
1273 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); 1270 const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
1274 const char* surfScale = builder->getUniformCStr(fSurfaceScaleUni); 1271 const char* surfScale = builder->getUniformCStr(fSurfaceScaleUni);
1275 1272
1276 int index = 0; 1273 int index = 0;
1277 for (int dy = -1; dy <= 1; dy++) { 1274 for (int dy = -1; dy <= 1; dy++) {
1278 for (int dx = -1; dx <= 1; dx++) { 1275 for (int dx = -1; dx <= 1; dx++) {
1279 SkString texCoords; 1276 SkString texCoords;
1280 texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc); 1277 texCoords.appendf("coord + vec2(%d, %d) * %s", dx, dy, imgInc);
1281 builder->fsCodeAppendf("\t\tm[%d] = ", index++); 1278 builder->fsCodeAppendf("\t\tm[%d] = ", index++);
1282 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType , 1279 builder->fsAppendTextureLookup(samplers[0], texCoords.c_str());
1283 samplers[0],
1284 texCoords.c_str());
1285 builder->fsCodeAppend(".a;\n"); 1280 builder->fsCodeAppend(".a;\n");
1286 } 1281 }
1287 } 1282 }
1288 builder->fsCodeAppend("\t\tvec3 surfaceToLight = "); 1283 builder->fsCodeAppend("\t\tvec3 surfaceToLight = ");
1289 SkString arg; 1284 SkString arg;
1290 arg.appendf("%s * m[4]", surfScale); 1285 arg.appendf("%s * m[4]", surfScale);
1291 fLight->emitSurfaceToLight(builder, arg.c_str()); 1286 fLight->emitSurfaceToLight(builder, arg.c_str());
1292 builder->fsCodeAppend(";\n"); 1287 builder->fsCodeAppend(";\n");
1293 builder->fsCodeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ", 1288 builder->fsCodeAppendf("\t\t%s = %s(%s(m, %s), surfaceToLight, ",
1294 outputColor, lightFunc.c_str(), interiorNormalName.c_ str(), surfScale); 1289 outputColor, lightFunc.c_str(), interiorNormalName.c_ str(), surfScale);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 1325
1331 /////////////////////////////////////////////////////////////////////////////// 1326 ///////////////////////////////////////////////////////////////////////////////
1332 1327
1333 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactor y& factory, 1328 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactor y& factory,
1334 const GrDrawEffect& drawEff ect) 1329 const GrDrawEffect& drawEff ect)
1335 : INHERITED(factory, drawEffect) { 1330 : INHERITED(factory, drawEffect) {
1336 } 1331 }
1337 1332
1338 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStri ng* funcName) { 1333 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStri ng* funcName) {
1339 const char* kd; 1334 const char* kd;
1340 fKDUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 1335 fKDUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1341 kFloat_GrSLType, 1336 kFloat_GrSLType,
1342 "KD", 1337 "KD",
1343 &kd); 1338 &kd);
1344 1339
1345 static const GrGLShaderVar gLightArgs[] = { 1340 static const GrGLShaderVar gLightArgs[] = {
1346 GrGLShaderVar("normal", kVec3f_GrSLType), 1341 GrGLShaderVar("normal", kVec3f_GrSLType),
1347 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType), 1342 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType),
1348 GrGLShaderVar("lightColor", kVec3f_GrSLType) 1343 GrGLShaderVar("lightColor", kVec3f_GrSLType)
1349 }; 1344 };
1350 SkString lightBody; 1345 SkString lightBody;
1351 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n" , kd); 1346 lightBody.appendf("\tfloat colorScale = %s * dot(normal, surfaceToLight);\n" , kd);
1352 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1 .0);\n"); 1347 lightBody.appendf("\treturn vec4(lightColor * clamp(colorScale, 0.0, 1.0), 1 .0);\n");
1353 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1348 builder->fsEmitFunction(kVec4f_GrSLType,
1354 kVec4f_GrSLType, 1349 "light",
1355 "light", 1350 SK_ARRAY_COUNT(gLightArgs),
1356 SK_ARRAY_COUNT(gLightArgs), 1351 gLightArgs,
1357 gLightArgs, 1352 lightBody.c_str(),
1358 lightBody.c_str(), 1353 funcName);
1359 funcName);
1360 } 1354 }
1361 1355
1362 void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman, 1356 void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman,
1363 const GrDrawEffect& drawEffect) { 1357 const GrDrawEffect& drawEffect) {
1364 INHERITED::setData(uman, drawEffect); 1358 INHERITED::setData(uman, drawEffect);
1365 const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLigh tingEffect>(); 1359 const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLigh tingEffect>();
1366 uman.set1f(fKDUni, diffuse.kd()); 1360 uman.set1f(fKDUni, diffuse.kd());
1367 } 1361 }
1368 1362
1369 /////////////////////////////////////////////////////////////////////////////// 1363 ///////////////////////////////////////////////////////////////////////////////
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 1406
1413 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFact ory& factory, 1407 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFact ory& factory,
1414 const GrDrawEffect& drawE ffect) 1408 const GrDrawEffect& drawE ffect)
1415 : INHERITED(factory, drawEffect) { 1409 : INHERITED(factory, drawEffect) {
1416 } 1410 }
1417 1411
1418 void GrGLSpecularLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStr ing* funcName) { 1412 void GrGLSpecularLightingEffect::emitLightFunc(GrGLShaderBuilder* builder, SkStr ing* funcName) {
1419 const char* ks; 1413 const char* ks;
1420 const char* shininess; 1414 const char* shininess;
1421 1415
1422 fKSUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 1416 fKSUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1423 kFloat_GrSLType, "KS", &ks); 1417 kFloat_GrSLType, "KS", &ks);
1424 fShininessUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 1418 fShininessUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1425 kFloat_GrSLType, "Shininess", &shininess ); 1419 kFloat_GrSLType, "Shininess", &shininess );
1426 1420
1427 static const GrGLShaderVar gLightArgs[] = { 1421 static const GrGLShaderVar gLightArgs[] = {
1428 GrGLShaderVar("normal", kVec3f_GrSLType), 1422 GrGLShaderVar("normal", kVec3f_GrSLType),
1429 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType), 1423 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType),
1430 GrGLShaderVar("lightColor", kVec3f_GrSLType) 1424 GrGLShaderVar("lightColor", kVec3f_GrSLType)
1431 }; 1425 };
1432 SkString lightBody; 1426 SkString lightBody;
1433 lightBody.appendf("\tvec3 halfDir = vec3(normalize(surfaceToLight + vec3(0, 0, 1)));\n"); 1427 lightBody.appendf("\tvec3 halfDir = vec3(normalize(surfaceToLight + vec3(0, 0, 1)));\n");
1434 lightBody.appendf("\tfloat colorScale = %s * pow(dot(normal, halfDir), %s);\ n", ks, shininess); 1428 lightBody.appendf("\tfloat colorScale = %s * pow(dot(normal, halfDir), %s);\ n", ks, shininess);
1435 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\ n"); 1429 lightBody.appendf("\tvec3 color = lightColor * clamp(colorScale, 0.0, 1.0);\ n");
1436 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b)) ;\n"); 1430 lightBody.appendf("\treturn vec4(color, max(max(color.r, color.g), color.b)) ;\n");
1437 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1431 builder->fsEmitFunction(kVec4f_GrSLType,
1438 kVec4f_GrSLType, 1432 "light",
1439 "light", 1433 SK_ARRAY_COUNT(gLightArgs),
1440 SK_ARRAY_COUNT(gLightArgs), 1434 gLightArgs,
1441 gLightArgs, 1435 lightBody.c_str(),
1442 lightBody.c_str(), 1436 funcName);
1443 funcName);
1444 } 1437 }
1445 1438
1446 void GrGLSpecularLightingEffect::setData(const GrGLUniformManager& uman, 1439 void GrGLSpecularLightingEffect::setData(const GrGLUniformManager& uman,
1447 const GrDrawEffect& drawEffect) { 1440 const GrDrawEffect& drawEffect) {
1448 INHERITED::setData(uman, drawEffect); 1441 INHERITED::setData(uman, drawEffect);
1449 const GrSpecularLightingEffect& spec = drawEffect.castEffect<GrSpecularLight ingEffect>(); 1442 const GrSpecularLightingEffect& spec = drawEffect.castEffect<GrSpecularLight ingEffect>();
1450 uman.set1f(fKSUni, spec.ks()); 1443 uman.set1f(fKSUni, spec.ks());
1451 uman.set1f(fShininessUni, spec.shininess()); 1444 uman.set1f(fShininessUni, spec.shininess());
1452 } 1445 }
1453 1446
1454 /////////////////////////////////////////////////////////////////////////////// 1447 ///////////////////////////////////////////////////////////////////////////////
1455 void GrGLLight::emitLightColorUniform(GrGLShaderBuilder* builder) { 1448 void GrGLLight::emitLightColorUniform(GrGLShaderBuilder* builder) {
1456 fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 1449 fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1457 kVec3f_GrSLType, "LightColor"); 1450 kVec3f_GrSLType, "LightColor");
1458 } 1451 }
1459 1452
1460 void GrGLLight::emitLightColor(GrGLShaderBuilder* builder, 1453 void GrGLLight::emitLightColor(GrGLShaderBuilder* builder,
1461 const char *surfaceToLight) { 1454 const char *surfaceToLight) {
1462 builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni())); 1455 builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni()));
1463 } 1456 }
1464 1457
1465 void GrGLLight::setData(const GrGLUniformManager& uman, 1458 void GrGLLight::setData(const GrGLUniformManager& uman,
1466 const SkLight* light) const { 1459 const SkLight* light) const {
1467 setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToSca lar(255))); 1460 setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToSca lar(255)));
1468 } 1461 }
1469 1462
1470 /////////////////////////////////////////////////////////////////////////////// 1463 ///////////////////////////////////////////////////////////////////////////////
1471 1464
1472 void GrGLDistantLight::setData(const GrGLUniformManager& uman, 1465 void GrGLDistantLight::setData(const GrGLUniformManager& uman,
1473 const SkLight* light) const { 1466 const SkLight* light) const {
1474 INHERITED::setData(uman, light); 1467 INHERITED::setData(uman, light);
1475 SkASSERT(light->type() == SkLight::kDistant_LightType); 1468 SkASSERT(light->type() == SkLight::kDistant_LightType);
1476 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh t); 1469 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh t);
1477 setUniformNormal3(uman, fDirectionUni, distantLight->direction()); 1470 setUniformNormal3(uman, fDirectionUni, distantLight->direction());
1478 } 1471 }
1479 1472
1480 void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char * z) { 1473 void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char * z) {
1481 const char* dir; 1474 const char* dir;
1482 fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType, 1475 fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec3f_GrSLType,
1483 "LightDirection", &dir); 1476 "LightDirection", &dir);
1484 builder->fsCodeAppend(dir); 1477 builder->fsCodeAppend(dir);
1485 } 1478 }
1486 1479
1487 /////////////////////////////////////////////////////////////////////////////// 1480 ///////////////////////////////////////////////////////////////////////////////
1488 1481
1489 void GrGLPointLight::setData(const GrGLUniformManager& uman, 1482 void GrGLPointLight::setData(const GrGLUniformManager& uman,
1490 const SkLight* light) const { 1483 const SkLight* light) const {
1491 INHERITED::setData(uman, light); 1484 INHERITED::setData(uman, light);
1492 SkASSERT(light->type() == SkLight::kPoint_LightType); 1485 SkASSERT(light->type() == SkLight::kPoint_LightType);
1493 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); 1486 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light);
1494 setUniformPoint3(uman, fLocationUni, pointLight->location()); 1487 setUniformPoint3(uman, fLocationUni, pointLight->location());
1495 } 1488 }
1496 1489
1497 void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z) { 1490 void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z) {
1498 const char* loc; 1491 const char* loc;
1499 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLType, 1492 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec3f_GrSLType,
1500 "LightLocation", &loc); 1493 "LightLocation", &loc);
1501 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->frag mentPosition(), z); 1494 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->frag mentPosition(), z);
1502 } 1495 }
1503 1496
1504 /////////////////////////////////////////////////////////////////////////////// 1497 ///////////////////////////////////////////////////////////////////////////////
1505 1498
1506 void GrGLSpotLight::setData(const GrGLUniformManager& uman, 1499 void GrGLSpotLight::setData(const GrGLUniformManager& uman,
1507 const SkLight* light) const { 1500 const SkLight* light) const {
1508 INHERITED::setData(uman, light); 1501 INHERITED::setData(uman, light);
1509 SkASSERT(light->type() == SkLight::kSpot_LightType); 1502 SkASSERT(light->type() == SkLight::kSpot_LightType);
1510 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); 1503 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light);
1511 setUniformPoint3(uman, fLocationUni, spotLight->location()); 1504 setUniformPoint3(uman, fLocationUni, spotLight->location());
1512 uman.set1f(fExponentUni, spotLight->specularExponent()); 1505 uman.set1f(fExponentUni, spotLight->specularExponent());
1513 uman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); 1506 uman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle());
1514 uman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); 1507 uman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle());
1515 uman.set1f(fConeScaleUni, spotLight->coneScale()); 1508 uman.set1f(fConeScaleUni, spotLight->coneScale());
1516 setUniformNormal3(uman, fSUni, spotLight->s()); 1509 setUniformNormal3(uman, fSUni, spotLight->s());
1517 } 1510 }
1518 1511
1519 void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z ) { 1512 void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z ) {
1520 const char* location; 1513 const char* location;
1521 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 1514 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1522 kVec3f_GrSLType, "LightLocation", &locati on); 1515 kVec3f_GrSLType, "LightLocation", &locati on);
1523 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", 1516 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))",
1524 location, builder->fragmentPosition(), z); 1517 location, builder->fragmentPosition(), z);
1525 } 1518 }
1526 1519
1527 void GrGLSpotLight::emitLightColor(GrGLShaderBuilder* builder, 1520 void GrGLSpotLight::emitLightColor(GrGLShaderBuilder* builder,
1528 const char *surfaceToLight) { 1521 const char *surfaceToLight) {
1529 1522
1530 const char* color = builder->getUniformCStr(this->lightColorUni()); // creat ed by parent class. 1523 const char* color = builder->getUniformCStr(this->lightColorUni()); // creat ed by parent class.
1531 1524
1532 const char* exponent; 1525 const char* exponent;
1533 const char* cosInner; 1526 const char* cosInner;
1534 const char* cosOuter; 1527 const char* cosOuter;
1535 const char* coneScale; 1528 const char* coneScale;
1536 const char* s; 1529 const char* s;
1537 fExponentUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 1530 fExponentUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1538 kFloat_GrSLType, "Exponent", &exponent); 1531 kFloat_GrSLType, "Exponent", &exponent);
1539 fCosInnerConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Sha derType, 1532 fCosInnerConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Vis ibility,
1540 kFloat_GrSLType, "CosInnerConeAn gle", &cosInner); 1533 kFloat_GrSLType, "CosInnerConeAn gle", &cosInner);
1541 fCosOuterConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Sha derType, 1534 fCosOuterConeAngleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Vis ibility,
1542 kFloat_GrSLType, "CosOuterConeAn gle", &cosOuter); 1535 kFloat_GrSLType, "CosOuterConeAn gle", &cosOuter);
1543 fConeScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 1536 fConeScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1544 kFloat_GrSLType, "ConeScale", &coneScale ); 1537 kFloat_GrSLType, "ConeScale", &coneScale );
1545 fSUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 1538 fSUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
1546 kVec3f_GrSLType, "S", &s); 1539 kVec3f_GrSLType, "S", &s);
1547 1540
1548 static const GrGLShaderVar gLightColorArgs[] = { 1541 static const GrGLShaderVar gLightColorArgs[] = {
1549 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType) 1542 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType)
1550 }; 1543 };
1551 SkString lightColorBody; 1544 SkString lightColorBody;
1552 lightColorBody.appendf("\tfloat cosAngle = -dot(surfaceToLight, %s);\n", s); 1545 lightColorBody.appendf("\tfloat cosAngle = -dot(surfaceToLight, %s);\n", s);
1553 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosOuter); 1546 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosOuter);
1554 lightColorBody.appendf("\t\treturn vec3(0);\n"); 1547 lightColorBody.appendf("\t\treturn vec3(0);\n");
1555 lightColorBody.appendf("\t}\n"); 1548 lightColorBody.appendf("\t}\n");
1556 lightColorBody.appendf("\tfloat scale = pow(cosAngle, %s);\n", exponent); 1549 lightColorBody.appendf("\tfloat scale = pow(cosAngle, %s);\n", exponent);
1557 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosInner); 1550 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosInner);
1558 lightColorBody.appendf("\t\treturn %s * scale * (cosAngle - %s) * %s;\n", 1551 lightColorBody.appendf("\t\treturn %s * scale * (cosAngle - %s) * %s;\n",
1559 color, cosOuter, coneScale); 1552 color, cosOuter, coneScale);
1560 lightColorBody.appendf("\t}\n"); 1553 lightColorBody.appendf("\t}\n");
1561 lightColorBody.appendf("\treturn %s;\n", color); 1554 lightColorBody.appendf("\treturn %s;\n", color);
1562 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1555 builder->fsEmitFunction(kVec3f_GrSLType,
1563 kVec3f_GrSLType, 1556 "lightColor",
1564 "lightColor", 1557 SK_ARRAY_COUNT(gLightColorArgs),
1565 SK_ARRAY_COUNT(gLightColorArgs), 1558 gLightColorArgs,
1566 gLightColorArgs, 1559 lightColorBody.c_str(),
1567 lightColorBody.c_str(), 1560 &fLightColorFunc);
1568 &fLightColorFunc);
1569 1561
1570 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 1562 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
1571 } 1563 }
1572 1564
1573 #endif 1565 #endif
1574 1566
1575 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 1567 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
1576 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 1568 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
1577 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 1569 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
1578 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) 1570 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight)
1579 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) 1571 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight)
1580 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) 1572 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight)
1581 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1573 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698