blob: cdf27cb40e31476a5e24f7997dd6d3aa92b5bd12 [file] [log] [blame]
Robert Phillipsa8cdbd72018-07-17 12:30:40 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkShader.h"
12#include "src/shaders/SkLights.h"
Robert Phillipsa8cdbd72018-07-17 12:30:40 -040013
14class SkBitmap;
15class SkMatrix;
16class SkNormalSource;
17
Mike Reed0d84e802019-01-24 21:22:49 -050018class SkLightingShader {
Robert Phillipsa8cdbd72018-07-17 12:30:40 -040019public:
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 Kleinfa5f6ce2018-10-20 08:21:31 -040036 static void RegisterFlattenables();
Robert Phillipsa8cdbd72018-07-17 12:30:40 -040037};
38
39#endif