| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
| 10 #include "SkShadowShader.h" | 10 #include "SkShadowShader.h" |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 SkString povCoord("povCoord"); | 283 SkString povCoord("povCoord"); |
| 284 povCoord.appendf("%d", i); | 284 povCoord.appendf("%d", i); |
| 285 | 285 |
| 286 SkString offset("offset"); | 286 SkString offset("offset"); |
| 287 offset.appendf("%d", i); | 287 offset.appendf("%d", i); |
| 288 fragBuilder->codeAppendf("vec2 %s;", offset.c_str()); | 288 fragBuilder->codeAppendf("vec2 %s;", offset.c_str()); |
| 289 | 289 |
| 290 if (shadowFP.fIsPointLight[i]) { | 290 if (shadowFP.fIsPointLight[i]) { |
| 291 fragBuilder->codeAppendf("vec3 fragToLight%d = %s - worldCor
;", | 291 fragBuilder->codeAppendf("vec3 fragToLight%d = %s - worldCor
;", |
| 292 i, lightDirOrPosUniName[i]); | 292 i, lightDirOrPosUniName[i]); |
| 293 fragBuilder->codeAppendf("float distsq%d = dot(fragToLight%d
, " | 293 fragBuilder->codeAppendf("float dist%d = length(fragToLight%
d);", |
| 294 "fragToLight%d);", | 294 i, i); |
| 295 i, i, i); | |
| 296 fragBuilder->codeAppendf("%s = vec2(-fragToLight%d) * povDep
th.b;", | 295 fragBuilder->codeAppendf("%s = vec2(-fragToLight%d) * povDep
th.b;", |
| 297 offset.c_str(), i); | 296 offset.c_str(), i); |
| 298 fragBuilder->codeAppendf("fragToLight%d = normalize(fragToLi
ght%d);", | 297 fragBuilder->codeAppendf("fragToLight%d = normalize(fragToLi
ght%d);", |
| 299 i, i); | 298 i, i); |
| 300 } | 299 } |
| 301 | 300 |
| 302 if (shadowFP.fIsRadialLight[i]) { | 301 if (shadowFP.fIsRadialLight[i]) { |
| 303 fragBuilder->codeAppendf("vec2 %s = vec2(vMatrixCoord_0_1_St
age0.x, " | 302 fragBuilder->codeAppendf("vec2 %s = vec2(vMatrixCoord_0_1_St
age0.x, " |
| 304 "1 - vMatrixCoord_0_
1_Stage0.y);\n", | 303 "1 - vMatrixCoord_0_
1_Stage0.y);\n", |
| 305 povCoord.c_str()); | 304 povCoord.c_str()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 375 |
| 377 if (shadowFP.fIsRadialLight[i]) { | 376 if (shadowFP.fIsRadialLight[i]) { |
| 378 fragBuilder->codeAppend("totalLightColor = vec3(0);"); | 377 fragBuilder->codeAppend("totalLightColor = vec3(0);"); |
| 379 | 378 |
| 380 fragBuilder->codeAppend("vec2 tc = vec2(povCoord0.x, 0.0);")
; | 379 fragBuilder->codeAppend("vec2 tc = vec2(povCoord0.x, 0.0);")
; |
| 381 fragBuilder->codeAppend("float depth = texture(uTextureSampl
er0_Stage1," | 380 fragBuilder->codeAppend("float depth = texture(uTextureSampl
er0_Stage1," |
| 382 "povCoord0).b
* 2.0;"); | 381 "povCoord0).b
* 2.0;"); |
| 383 | 382 |
| 384 fragBuilder->codeAppendf("lightProbability = step(r, depth);
"); | 383 fragBuilder->codeAppendf("lightProbability = step(r, depth);
"); |
| 385 | 384 |
| 386 fragBuilder->codeAppendf("if (%s.b != 0 || depth == 0) {" | 385 // 2 is the maximum depth. If this is reached, probably we h
ave |
| 386 // not intersected anything. So values after this should be
unshadowed. |
| 387 fragBuilder->codeAppendf("if (%s.b != 0 || depth == 2) {" |
| 387 "lightProbability = 1.0; }"
, | 388 "lightProbability = 1.0; }"
, |
| 388 povDepth.c_str()); | 389 povDepth.c_str()); |
| 389 } else { | 390 } else { |
| 390 // 1/512 == .00195... is less than half a pixel; imperceptib
le | 391 // 1/512 == .00195... is less than half a pixel; imperceptib
le |
| 391 fragBuilder->codeAppendf("if (%s.b <= %s.b + .001953125) {", | 392 fragBuilder->codeAppendf("if (%s.b <= %s.b + .001953125) {", |
| 392 povDepth.c_str(), depthMaps[i].c_st
r()); | 393 povDepth.c_str(), depthMaps[i].c_st
r()); |
| 393 if (blurAlgorithm == SkShadowParams::kVariance_ShadowType) { | 394 if (blurAlgorithm == SkShadowParams::kVariance_ShadowType) { |
| 394 // We mess with depth and depth^2 in their given scales. | 395 // We mess with depth and depth^2 in their given scales. |
| 395 // (i.e. between 0 and 1) | 396 // (i.e. between 0 and 1) |
| 396 fragBuilder->codeAppendf("vec2 moments%d = vec2(%s.b, %s
.g);", | 397 fragBuilder->codeAppendf("vec2 moments%d = vec2(%s.b, %s
.g);", |
| (...skipping 27 matching lines...) Expand all Loading... |
| 424 fragBuilder->codeAppendf("} else { lightProbability = 0;
}"); | 425 fragBuilder->codeAppendf("} else { lightProbability = 0;
}"); |
| 425 } | 426 } |
| 426 | 427 |
| 427 // VSM: The curved shadows near plane edges are artifacts fr
om blurring | 428 // VSM: The curved shadows near plane edges are artifacts fr
om blurring |
| 428 // lightDir.z is equal to the lightDir dot the surface norma
l. | 429 // lightDir.z is equal to the lightDir dot the surface norma
l. |
| 429 fragBuilder->codeAppendf("}"); | 430 fragBuilder->codeAppendf("}"); |
| 430 } | 431 } |
| 431 | 432 |
| 432 if (shadowFP.isPointLight(i)) { | 433 if (shadowFP.isPointLight(i)) { |
| 433 fragBuilder->codeAppendf("totalLightColor += max(fragToLight
%d.z, 0) * %s /" | 434 fragBuilder->codeAppendf("totalLightColor += max(fragToLight
%d.z, 0) * %s /" |
| 434 "(1 + distsq%d) * lightProb
ability;", | 435 "(1 + dist%d) * lightProbab
ility;", |
| 435 i, lightColorUniName[i], i); | 436 i, lightColorUniName[i], i); |
| 436 } else { | 437 } else { |
| 437 fragBuilder->codeAppendf("totalLightColor += %s.z * %s * lig
htProbability;", | 438 fragBuilder->codeAppendf("totalLightColor += %s.z * %s * lig
htProbability;", |
| 438 lightDirOrPosUniName[i], | 439 lightDirOrPosUniName[i], |
| 439 lightColorUniName[i]); | 440 lightColorUniName[i]); |
| 440 } | 441 } |
| 441 | 442 |
| 442 fragBuilder->codeAppendf("totalLightColor += %s;", ambientColorU
niName); | 443 fragBuilder->codeAppendf("totalLightColor += %s;", ambientColorU
niName); |
| 443 fragBuilder->codeAppendf("%s = resultDiffuseColor * vec4(totalLi
ghtColor, 1);", | 444 fragBuilder->codeAppendf("%s = resultDiffuseColor * vec4(totalLi
ghtColor, 1);", |
| 444 args.fOutputColor); | 445 args.fOutputColor); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 | 812 |
| 812 int height = lightShader.fDiffuseHeight; | 813 int height = lightShader.fDiffuseHeight; |
| 813 | 814 |
| 814 SkVector3 fragToLight = SkVector3::Make(light.pos().fX - x -
i, | 815 SkVector3 fragToLight = SkVector3::Make(light.pos().fX - x -
i, |
| 815 light.pos().fY - (he
ight - y), | 816 light.pos().fY - (he
ight - y), |
| 816 light.pos().fZ - pvD
epth); | 817 light.pos().fZ - pvD
epth); |
| 817 | 818 |
| 818 SkScalar dist = fragToLight.length(); | 819 SkScalar dist = fragToLight.length(); |
| 819 SkScalar normalizedZ = fragToLight.fZ / dist; | 820 SkScalar normalizedZ = fragToLight.fZ / dist; |
| 820 | 821 |
| 821 SkScalar distAttenuation = light.intensity() / (1.0f + dist
* dist); | 822 SkScalar distAttenuation = light.intensity() / (1.0f + dist)
; |
| 822 | 823 |
| 823 // assume object normals are pointing straight up | 824 // assume object normals are pointing straight up |
| 824 totalLight.fX += normalizedZ * light.color().fX * distAttenu
ation; | 825 totalLight.fX += normalizedZ * light.color().fX * distAttenu
ation; |
| 825 totalLight.fY += normalizedZ * light.color().fY * distAttenu
ation; | 826 totalLight.fY += normalizedZ * light.color().fY * distAttenu
ation; |
| 826 totalLight.fZ += normalizedZ * light.color().fZ * distAttenu
ation; | 827 totalLight.fZ += normalizedZ * light.color().fZ * distAttenu
ation; |
| 827 } | 828 } |
| 828 } | 829 } |
| 829 | 830 |
| 830 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota
lLight.fX, | 831 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota
lLight.fX, |
| 831 SkColorGetG(diffColor) * tota
lLight.fY, | 832 SkColorGetG(diffColor) * tota
lLight.fY, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 | 948 |
| 948 /////////////////////////////////////////////////////////////////////////////// | 949 /////////////////////////////////////////////////////////////////////////////// |
| 949 | 950 |
| 950 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) | 951 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) |
| 951 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) | 952 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) |
| 952 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 953 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 953 | 954 |
| 954 /////////////////////////////////////////////////////////////////////////////// | 955 /////////////////////////////////////////////////////////////////////////////// |
| 955 | 956 |
| 956 #endif | 957 #endif |
| OLD | NEW |