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 #ifndef SkLightingShader_DEFINED | 8 #ifndef SkLightingShader_DEFINED |
9 #define SkLightingShader_DEFINED | 9 #define SkLightingShader_DEFINED |
10 | 10 |
11 #include "SkLights.h" | 11 #include "SkLights.h" |
12 #include "SkShader.h" | 12 #include "SkShader.h" |
13 | 13 |
14 class SkBitmap; | 14 class SkBitmap; |
15 class SkMatrix; | 15 class SkMatrix; |
16 class SkNormalSource; | 16 class SkNormalSource; |
17 | 17 |
18 class SK_API SkLightingShader { | 18 class SK_API SkLightingShader { |
19 public: | 19 public: |
20 /** Returns a shader that lights the shape, colored by the diffuseShader, us
ing the | 20 /** Returns a shader that lights the shape, colored by the diffuseShader, us
ing the |
21 normals from normalSource, with the set of lights provided. | 21 normals from normalSource, with the set of lights provided. |
22 | 22 |
23 It returns a shader with a reference count of 1. | |
24 The caller should decrement the shader's reference count when done with
the shader. | |
25 It is an error for count to be < 2. | |
26 @param diffuseShader the shader that provides the colors. If nullpt
r, uses the paint's | 23 @param diffuseShader the shader that provides the colors. If nullpt
r, uses the paint's |
27 color. | 24 color. |
28 @param normalSource the source for the shape's normals. If nullptr
, assumes straight | 25 @param normalSource the source for the shape's normals. If nullptr
, assumes straight |
29 up normals (<0,0,1>). | 26 up normals (<0,0,1>). |
30 @param lights the lights applied to the normals | 27 @param lights the lights applied to the normals |
31 | 28 |
32 The lighting equation is currently: | 29 The lighting equation is currently: |
33 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo
lor | 30 result = (LightColor * dot(Normal, LightDir) + AmbientColor) * Diffu
seColor |
34 | 31 |
35 */ | 32 */ |
36 static sk_sp<SkShader> Make(sk_sp<SkShader> diffuseShader, sk_sp<SkNormalSou
rce> normalSource, | 33 static sk_sp<SkShader> Make(sk_sp<SkShader> diffuseShader, sk_sp<SkNormalSou
rce> normalSource, |
37 sk_sp<SkLights> lights); | 34 sk_sp<SkLights> lights); |
38 | 35 |
39 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 36 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
40 }; | 37 }; |
41 | 38 |
42 #endif | 39 #endif |
OLD | NEW |