| 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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 for (int i = 0; i < n; ++i) { | 712 for (int i = 0; i < n; ++i) { |
| 713 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]); | 713 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]); |
| 714 SkColor povDepthColor = povDepth[i]; | 714 SkColor povDepthColor = povDepth[i]; |
| 715 | 715 |
| 716 SkColor3f totalLight = lightShader.fLights->ambientLightColor(); | 716 SkColor3f totalLight = lightShader.fLights->ambientLightColor(); |
| 717 // This is all done in linear unpremul color space (each component 0
..255.0f though) | 717 // This is all done in linear unpremul color space (each component 0
..255.0f though) |
| 718 | 718 |
| 719 for (int l = 0; l < lightShader.fLights->numLights(); ++l) { | 719 for (int l = 0; l < lightShader.fLights->numLights(); ++l) { |
| 720 const SkLights::Light& light = lightShader.fLights->light(l); | 720 const SkLights::Light& light = lightShader.fLights->light(l); |
| 721 | 721 |
| 722 int pvDepth = SkColorGetB(povDepthColor); // depth stored in blu
e channel |
| 723 |
| 722 if (light.type() == SkLights::Light::kDirectional_LightType) { | 724 if (light.type() == SkLights::Light::kDirectional_LightType) { |
| 723 int pvDepth = SkColorGetB(povDepthColor); // depth stored in
blue channel | |
| 724 | 725 |
| 725 int xOffset = SkScalarRoundToInt(light.dir().fX * pvDepth); | 726 int xOffset = SkScalarRoundToInt(light.dir().fX * pvDepth); |
| 726 int yOffset = SkScalarRoundToInt(light.dir().fY * pvDepth); | 727 int yOffset = SkScalarRoundToInt(light.dir().fY * pvDepth); |
| 727 | 728 |
| 728 int shX = SkClampMax(x + i + xOffset, light.getShadowMap()->
width() - 1); | 729 int shX = SkClampMax(x + i + xOffset, light.getShadowMap()->
width() - 1); |
| 729 int shY = SkClampMax(y + yOffset, light.getShadowMap()->heig
ht() - 1); | 730 int shY = SkClampMax(y + yOffset, light.getShadowMap()->heig
ht() - 1); |
| 730 | 731 |
| 731 int shDepth = 0; | 732 int shDepth = 0; |
| 732 int shDepthsq = 0; | 733 int shDepthsq = 0; |
| 733 | 734 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 758 lightProb = SkMaxScalar((lightProb - bias) / (1.0f -
bias), 0.0f); | 759 lightProb = SkMaxScalar((lightProb - bias) / (1.0f -
bias), 0.0f); |
| 759 } else { | 760 } else { |
| 760 lightProb = 0.0f; | 761 lightProb = 0.0f; |
| 761 } | 762 } |
| 762 } | 763 } |
| 763 | 764 |
| 764 // assume object normals are pointing straight up | 765 // assume object normals are pointing straight up |
| 765 totalLight.fX += light.dir().fZ * light.color().fX * lightPr
ob; | 766 totalLight.fX += light.dir().fZ * light.color().fX * lightPr
ob; |
| 766 totalLight.fY += light.dir().fZ * light.color().fY * lightPr
ob; | 767 totalLight.fY += light.dir().fZ * light.color().fY * lightPr
ob; |
| 767 totalLight.fZ += light.dir().fZ * light.color().fZ * lightPr
ob; | 768 totalLight.fZ += light.dir().fZ * light.color().fZ * lightPr
ob; |
| 769 |
| 768 } else { | 770 } else { |
| 769 totalLight += light.color(); | 771 // right now we only expect directional and point light type
s. |
| 772 SkASSERT(light.type() == SkLights::Light::kPoint_LightType); |
| 773 |
| 774 int height = lightShader.fDiffuseHeight; |
| 775 |
| 776 SkVector3 fragToLight = SkVector3::Make(light.pos().fX - x -
i, |
| 777 light.pos().fY - (he
ight - y), |
| 778 light.pos().fZ - pvD
epth); |
| 779 |
| 780 SkScalar dist = fragToLight.length(); |
| 781 SkScalar normalizedZ = fragToLight.fZ / dist; |
| 782 |
| 783 SkScalar distAttenuation = light.intensity() / (1.0f + dist
* dist); |
| 784 |
| 785 // assume object normals are pointing straight up |
| 786 totalLight.fX += normalizedZ * light.color().fX * distAttenu
ation; |
| 787 totalLight.fY += normalizedZ * light.color().fY * distAttenu
ation; |
| 788 totalLight.fZ += normalizedZ * light.color().fZ * distAttenu
ation; |
| 770 } | 789 } |
| 771 } | 790 } |
| 772 | 791 |
| 773 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota
lLight.fX, | 792 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota
lLight.fX, |
| 774 SkColorGetG(diffColor) * tota
lLight.fY, | 793 SkColorGetG(diffColor) * tota
lLight.fY, |
| 775 SkColorGetB(diffColor) * tota
lLight.fZ); | 794 SkColorGetB(diffColor) * tota
lLight.fZ); |
| 776 | 795 |
| 777 result[i] = convert(totalColor, SkColorGetA(diffColor)); | 796 result[i] = convert(totalColor, SkColorGetA(diffColor)); |
| 778 } | 797 } |
| 779 | 798 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 | 909 |
| 891 /////////////////////////////////////////////////////////////////////////////// | 910 /////////////////////////////////////////////////////////////////////////////// |
| 892 | 911 |
| 893 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) | 912 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) |
| 894 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) | 913 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) |
| 895 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 914 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 896 | 915 |
| 897 /////////////////////////////////////////////////////////////////////////////// | 916 /////////////////////////////////////////////////////////////////////////////// |
| 898 | 917 |
| 899 #endif | 918 #endif |
| OLD | NEW |