• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkLightingShader_DEFINED
9 #define SkLightingShader_DEFINED
10 
11 #include "SkLights.h"
12 #include "SkShader.h"
13 
14 class SkBitmap;
15 class SkMatrix;
16 class SkNormalSource;
17 
18 class SkLightingShader {
19 public:
20     /** Returns a shader that lights the shape, colored by the diffuseShader, using the
21         normals from normalSource, with the set of lights provided.
22 
23         @param  diffuseShader     the shader that provides the colors. If nullptr, uses the paint's
24                                   color.
25         @param  normalSource      the source for the shape's normals. If nullptr, assumes straight
26                                   up normals (<0,0,1>).
27         @param  lights            the lights applied to the normals
28 
29         The lighting equation is currently:
30             result = (LightColor * dot(Normal, LightDir) + AmbientColor) * DiffuseColor
31 
32     */
33     static sk_sp<SkShader> Make(sk_sp<SkShader> diffuseShader, sk_sp<SkNormalSource> normalSource,
34                                 sk_sp<SkLights> lights);
35 
36     static void RegisterFlattenables();
37 };
38 
39 #endif
40