OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 for (int x = 0; x < texSize; ++x) { | 31 for (int x = 0; x < texSize; ++x) { |
32 SkScalar locX = (x + 0.5f - texSize/2.0f) / (texSize/2.0f); | 32 SkScalar locX = (x + 0.5f - texSize/2.0f) / (texSize/2.0f); |
33 SkScalar locY = (y + 0.5f - texSize/2.0f) / (texSize/2.0f); | 33 SkScalar locY = (y + 0.5f - texSize/2.0f) / (texSize/2.0f); |
34 | 34 |
35 SkScalar locZ = locX * locX + locY * locY; | 35 SkScalar locZ = locX * locX + locY * locY; |
36 if (locZ >= 1.0f) { | 36 if (locZ >= 1.0f) { |
37 locX = 0.0f; | 37 locX = 0.0f; |
38 locY = 0.0f; | 38 locY = 0.0f; |
39 locZ = 0.0f; | 39 locZ = 0.0f; |
40 } | 40 } |
41 locZ = sqrt(1.0f - locZ); | 41 locZ = sqrtf(1.0f - locZ); |
42 unsigned char r = static_cast<unsigned char>((0.5f * locX + 0.5f) *
255); | 42 unsigned char r = static_cast<unsigned char>((0.5f * locX + 0.5f) *
255); |
43 unsigned char g = static_cast<unsigned char>((-0.5f * locY + 0.5f) *
255); | 43 unsigned char g = static_cast<unsigned char>((-0.5f * locY + 0.5f) *
255); |
44 unsigned char b = static_cast<unsigned char>((0.5f * locZ + 0.5f) *
255); | 44 unsigned char b = static_cast<unsigned char>((0.5f * locZ + 0.5f) *
255); |
45 *hemi.getAddr32(x, y) = SkPackARGB32(0xFF, r, g, b); | 45 *hemi.getAddr32(x, y) = SkPackARGB32(0xFF, r, g, b); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 return hemi; | 49 return hemi; |
50 } | 50 } |
51 | 51 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 SkColor3f fAmbient; | 174 SkColor3f fAmbient; |
175 | 175 |
176 typedef GM INHERITED; | 176 typedef GM INHERITED; |
177 }; | 177 }; |
178 | 178 |
179 ////////////////////////////////////////////////////////////////////////////// | 179 ////////////////////////////////////////////////////////////////////////////// |
180 | 180 |
181 DEF_GM( return SkNEW(LightingShaderGM); ) | 181 DEF_GM( return SkNEW(LightingShaderGM); ) |
182 | 182 |
183 } | 183 } |
OLD | NEW |