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 "SkError.h" | 8 #include "SkError.h" |
9 #include "SkErrorInternals.h" | 9 #include "SkErrorInternals.h" |
10 #include "SkLightingShader.h" | 10 #include "SkLightingShader.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 102 |
103 SkString dstNormalColorName("dstNormalColor"); | 103 SkString dstNormalColorName("dstNormalColor"); |
104 this->emitChild(0, nullptr, &dstNormalColorName, args); | 104 this->emitChild(0, nullptr, &dstNormalColorName, args); |
105 fragBuilder->codeAppendf("vec3 normal = normalize(%s.rgb - vec3(0.5)
);", | 105 fragBuilder->codeAppendf("vec3 normal = normalize(%s.rgb - vec3(0.5)
);", |
106 dstNormalColorName.c_str()); | 106 dstNormalColorName.c_str()); |
107 | 107 |
108 // TODO: inverse map the light direction vectors in the vertex shade
r rather than | 108 // TODO: inverse map the light direction vectors in the vertex shade
r rather than |
109 // transforming all the normals here! | 109 // transforming all the normals here! |
110 | 110 |
111 // If there's no x & y components, return (0, 0, +/- 1) instead to a
void division by 0 | 111 // If there's no x & y components, return (0, 0, +/- 1) instead to a
void division by 0 |
112 fragBuilder->codeAppend( "if (abs(normal.z) > 0.9999) {"); | 112 fragBuilder->codeAppend( "if (abs(normal.z) > 0.999) {"); |
113 fragBuilder->codeAppendf(" %s = normalize(vec4(0.0, 0.0, normal.z
, 0.0));", | 113 fragBuilder->codeAppendf(" %s = normalize(vec4(0.0, 0.0, normal.z
, 0.0));", |
114 args.fOutputColor); | 114 args.fOutputColor); |
115 // Else, Normalizing the transformed X and Y, while keeping constant
both Z and the | 115 // Else, Normalizing the transformed X and Y, while keeping constant
both Z and the |
116 // vector's angle in the XY plane. This maintains the "slope" for th
e surface while | 116 // vector's angle in the XY plane. This maintains the "slope" for th
e surface while |
117 // appropriately rotating the normal for any anisotropic scaling tha
t occurs. | 117 // appropriately rotating the normal for any anisotropic scaling tha
t occurs. |
118 // Here, we call scaling factor the number that must divide the tran
sformed X and Y so | 118 // Here, we call scaling factor the number that must divide the tran
sformed X and Y so |
119 // that the normal's length remains equal to 1. | 119 // that the normal's length remains equal to 1. |
120 fragBuilder->codeAppend( "} else {"); | 120 fragBuilder->codeAppend( "} else {"); |
121 fragBuilder->codeAppendf(" vec2 transformed = %s * normal.xy;", | 121 fragBuilder->codeAppendf(" vec2 transformed = %s * normal.xy;", |
122 xformUniName); | 122 xformUniName); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 return sk_make_sp<NormalMapSourceImpl>(std::move(map), invCTM); | 314 return sk_make_sp<NormalMapSourceImpl>(std::move(map), invCTM); |
315 } | 315 } |
316 | 316 |
317 //////////////////////////////////////////////////////////////////////////// | 317 //////////////////////////////////////////////////////////////////////////// |
318 | 318 |
319 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) | 319 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkNormalSource) |
320 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) | 320 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(NormalMapSourceImpl) |
321 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 321 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
322 | 322 |
323 //////////////////////////////////////////////////////////////////////////// | 323 //////////////////////////////////////////////////////////////////////////// |
OLD | NEW |