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 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 lightProb = SkMaxScalar((lightProb - bias) / (1.0f - bias), 0.0f); | 758 lightProb = SkMaxScalar((lightProb - bias) / (1.0f - bias), 0.0f); |
759 } else { | 759 } else { |
760 lightProb = 0.0f; | 760 lightProb = 0.0f; |
761 } | 761 } |
762 } | 762 } |
763 | 763 |
764 // assume object normals are pointing straight up | 764 // assume object normals are pointing straight up |
765 totalLight.fX += light.dir().fZ * light.color().fX * lightPr ob; | 765 totalLight.fX += light.dir().fZ * light.color().fX * lightPr ob; |
766 totalLight.fY += light.dir().fZ * light.color().fY * lightPr ob; | 766 totalLight.fY += light.dir().fZ * light.color().fY * lightPr ob; |
767 totalLight.fZ += light.dir().fZ * light.color().fZ * lightPr ob; | 767 totalLight.fZ += light.dir().fZ * light.color().fZ * lightPr ob; |
768 } else { | 768 |
robertphillips
2016/08/31 13:44:27
Maybe:
} else {
SkASSERT(light.type() == SkLig
vjiaoblack
2016/08/31 13:53:27
Done.
| |
769 totalLight += light.color(); | 769 } else if (light.type() == SkLights::Light::kPoint_LightType) { |
robertphillips
2016/08/31 13:44:27
Move this line out of the if-then block and share
vjiaoblack
2016/08/31 13:53:27
Done.
| |
770 int pvDepth = SkColorGetB(povDepthColor); | |
771 | |
772 SkVector3 fragToLight = SkVector3::Make(light.pos().fX - (x + i), | |
robertphillips
2016/08/31 13:44:27
where's this 400 coming from?
vjiaoblack
2016/08/31 13:53:27
Done.
| |
773 light.pos().fY - (40 0 - y), | |
774 light.pos().fZ - pvD epth); | |
775 | |
776 SkScalar dist = fragToLight.length(); | |
777 SkScalar normalizedZ = fragToLight.fZ / dist; | |
778 | |
779 SkScalar attenuationValue = dist / light.intensity(); | |
jvanverth1
2016/08/31 17:18:23
This is the old lighting equation.
vjiaoblack
2016/08/31 17:58:28
Done.
| |
780 attenuationValue = attenuationValue * attenuationValue + 1.0 f; | |
781 | |
robertphillips
2016/08/31 13:44:27
// assume object normals are pointing straight up
vjiaoblack
2016/08/31 13:53:27
Done.
| |
782 totalLight.fX += normalizedZ * light.color().fX / attenuatio nValue; | |
jvanverth1
2016/08/31 17:18:22
If you precompute 1/attenuation and multiply by th
vjiaoblack
2016/08/31 17:58:28
Done.
| |
783 totalLight.fY += normalizedZ * light.color().fY / attenuatio nValue; | |
784 totalLight.fZ += normalizedZ * light.color().fZ / attenuatio nValue; | |
770 } | 785 } |
771 } | 786 } |
772 | 787 |
773 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota lLight.fX, | 788 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota lLight.fX, |
774 SkColorGetG(diffColor) * tota lLight.fY, | 789 SkColorGetG(diffColor) * tota lLight.fY, |
775 SkColorGetB(diffColor) * tota lLight.fZ); | 790 SkColorGetB(diffColor) * tota lLight.fZ); |
776 | 791 |
777 result[i] = convert(totalColor, SkColorGetA(diffColor)); | 792 result[i] = convert(totalColor, SkColorGetA(diffColor)); |
778 } | 793 } |
779 | 794 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
890 | 905 |
891 /////////////////////////////////////////////////////////////////////////////// | 906 /////////////////////////////////////////////////////////////////////////////// |
892 | 907 |
893 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) | 908 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) |
894 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) | 909 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) |
895 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 910 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
896 | 911 |
897 /////////////////////////////////////////////////////////////////////////////// | 912 /////////////////////////////////////////////////////////////////////////////// |
898 | 913 |
899 #endif | 914 #endif |
OLD | NEW |