Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkShader.h" |
| 12 | #include "src/shaders/SkLights.h" |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 13 | |
| 14 | class SkBitmap; |
| 15 | class SkMatrix; |
| 16 | class SkNormalSource; |
| 17 | |
Mike Reed | 0d84e80 | 2019-01-24 21:22:49 -0500 | [diff] [blame] | 18 | class SkLightingShader { |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 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 | |
Mike Klein | fa5f6ce | 2018-10-20 08:21:31 -0400 | [diff] [blame] | 36 | static void RegisterFlattenables(); |
Robert Phillips | a8cdbd7 | 2018-07-17 12:30:40 -0400 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | #endif |