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 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 static const GrGLShaderVar gSobelArgs[] = { | 1634 static const GrGLShaderVar gSobelArgs[] = { |
1635 GrGLShaderVar("a", kFloat_GrSLType), | 1635 GrGLShaderVar("a", kFloat_GrSLType), |
1636 GrGLShaderVar("b", kFloat_GrSLType), | 1636 GrGLShaderVar("b", kFloat_GrSLType), |
1637 GrGLShaderVar("c", kFloat_GrSLType), | 1637 GrGLShaderVar("c", kFloat_GrSLType), |
1638 GrGLShaderVar("d", kFloat_GrSLType), | 1638 GrGLShaderVar("d", kFloat_GrSLType), |
1639 GrGLShaderVar("e", kFloat_GrSLType), | 1639 GrGLShaderVar("e", kFloat_GrSLType), |
1640 GrGLShaderVar("f", kFloat_GrSLType), | 1640 GrGLShaderVar("f", kFloat_GrSLType), |
1641 GrGLShaderVar("scale", kFloat_GrSLType), | 1641 GrGLShaderVar("scale", kFloat_GrSLType), |
1642 }; | 1642 }; |
1643 SkString sobelFuncName; | 1643 SkString sobelFuncName; |
1644 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1644 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1645 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); | 1645 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); |
1646 | 1646 |
1647 fsBuilder->emitFunction(kFloat_GrSLType, | 1647 fsBuilder->emitFunction(kFloat_GrSLType, |
1648 "sobel", | 1648 "sobel", |
1649 SK_ARRAY_COUNT(gSobelArgs), | 1649 SK_ARRAY_COUNT(gSobelArgs), |
1650 gSobelArgs, | 1650 gSobelArgs, |
1651 "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scal
e;\n", | 1651 "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scal
e;\n", |
1652 &sobelFuncName); | 1652 &sobelFuncName); |
1653 static const GrGLShaderVar gPointToNormalArgs[] = { | 1653 static const GrGLShaderVar gPointToNormalArgs[] = { |
1654 GrGLShaderVar("x", kFloat_GrSLType), | 1654 GrGLShaderVar("x", kFloat_GrSLType), |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1899 SkASSERT(light->type() == SkLight::kPoint_LightType); | 1899 SkASSERT(light->type() == SkLight::kPoint_LightType); |
1900 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); | 1900 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); |
1901 setUniformPoint3(pdman, fLocationUni, pointLight->location()); | 1901 setUniformPoint3(pdman, fLocationUni, pointLight->location()); |
1902 } | 1902 } |
1903 | 1903 |
1904 void GrGLPointLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { | 1904 void GrGLPointLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { |
1905 const char* loc; | 1905 const char* loc; |
1906 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1906 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1907 kVec3f_GrSLType, kDefault_GrSLPrecision, | 1907 kVec3f_GrSLType, kDefault_GrSLPrecision, |
1908 "LightLocation", &loc); | 1908 "LightLocation", &loc); |
1909 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1909 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1910 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 1910 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", |
1911 loc, fsBuilder->fragmentPosition(), z); | 1911 loc, fsBuilder->fragmentPosition(), z); |
1912 } | 1912 } |
1913 | 1913 |
1914 /////////////////////////////////////////////////////////////////////////////// | 1914 /////////////////////////////////////////////////////////////////////////////// |
1915 | 1915 |
1916 void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman, | 1916 void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman, |
1917 const SkLight* light) const { | 1917 const SkLight* light) const { |
1918 INHERITED::setData(pdman, light); | 1918 INHERITED::setData(pdman, light); |
1919 SkASSERT(light->type() == SkLight::kSpot_LightType); | 1919 SkASSERT(light->type() == SkLight::kSpot_LightType); |
1920 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); | 1920 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); |
1921 setUniformPoint3(pdman, fLocationUni, spotLight->location()); | 1921 setUniformPoint3(pdman, fLocationUni, spotLight->location()); |
1922 pdman.set1f(fExponentUni, spotLight->specularExponent()); | 1922 pdman.set1f(fExponentUni, spotLight->specularExponent()); |
1923 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); | 1923 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); |
1924 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); | 1924 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); |
1925 pdman.set1f(fConeScaleUni, spotLight->coneScale()); | 1925 pdman.set1f(fConeScaleUni, spotLight->coneScale()); |
1926 setUniformNormal3(pdman, fSUni, spotLight->s()); | 1926 setUniformNormal3(pdman, fSUni, spotLight->s()); |
1927 } | 1927 } |
1928 | 1928 |
1929 void GrGLSpotLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { | 1929 void GrGLSpotLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { |
1930 const char* location; | 1930 const char* location; |
1931 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1931 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1932 kVec3f_GrSLType, kDefault_GrSLPrecision, | 1932 kVec3f_GrSLType, kDefault_GrSLPrecision, |
1933 "LightLocation", &location); | 1933 "LightLocation", &location); |
1934 | 1934 |
1935 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1935 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1936 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 1936 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", |
1937 location, fsBuilder->fragmentPosition(), z); | 1937 location, fsBuilder->fragmentPosition(), z); |
1938 } | 1938 } |
1939 | 1939 |
1940 void GrGLSpotLight::emitLightColor(GrGLFPBuilder* builder, | 1940 void GrGLSpotLight::emitLightColor(GrGLFPBuilder* builder, |
1941 const char *surfaceToLight) { | 1941 const char *surfaceToLight) { |
1942 | 1942 |
1943 const char* color = builder->getUniformCStr(this->lightColorUni()); // creat
ed by parent class. | 1943 const char* color = builder->getUniformCStr(this->lightColorUni()); // creat
ed by parent class. |
1944 | 1944 |
1945 const char* exponent; | 1945 const char* exponent; |
(...skipping 23 matching lines...) Expand all Loading... |
1969 lightColorBody.appendf("\tfloat cosAngle = -dot(surfaceToLight, %s);\n", s); | 1969 lightColorBody.appendf("\tfloat cosAngle = -dot(surfaceToLight, %s);\n", s); |
1970 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosOuter); | 1970 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosOuter); |
1971 lightColorBody.appendf("\t\treturn vec3(0);\n"); | 1971 lightColorBody.appendf("\t\treturn vec3(0);\n"); |
1972 lightColorBody.appendf("\t}\n"); | 1972 lightColorBody.appendf("\t}\n"); |
1973 lightColorBody.appendf("\tfloat scale = pow(cosAngle, %s);\n", exponent); | 1973 lightColorBody.appendf("\tfloat scale = pow(cosAngle, %s);\n", exponent); |
1974 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosInner); | 1974 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosInner); |
1975 lightColorBody.appendf("\t\treturn %s * scale * (cosAngle - %s) * %s;\n", | 1975 lightColorBody.appendf("\t\treturn %s * scale * (cosAngle - %s) * %s;\n", |
1976 color, cosOuter, coneScale); | 1976 color, cosOuter, coneScale); |
1977 lightColorBody.appendf("\t}\n"); | 1977 lightColorBody.appendf("\t}\n"); |
1978 lightColorBody.appendf("\treturn %s;\n", color); | 1978 lightColorBody.appendf("\treturn %s;\n", color); |
1979 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1979 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1980 fsBuilder->emitFunction(kVec3f_GrSLType, | 1980 fsBuilder->emitFunction(kVec3f_GrSLType, |
1981 "lightColor", | 1981 "lightColor", |
1982 SK_ARRAY_COUNT(gLightColorArgs), | 1982 SK_ARRAY_COUNT(gLightColorArgs), |
1983 gLightColorArgs, | 1983 gLightColorArgs, |
1984 lightColorBody.c_str(), | 1984 lightColorBody.c_str(), |
1985 &fLightColorFunc); | 1985 &fLightColorFunc); |
1986 | 1986 |
1987 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1987 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1988 } | 1988 } |
1989 | 1989 |
1990 #endif | 1990 #endif |
1991 | 1991 |
1992 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1992 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1993 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1993 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1994 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1994 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1995 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1995 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |