| 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 | 17 |
| 17 class SK_API SkLightingShader { | 18 class SK_API SkLightingShader { |
| 18 public: | 19 public: |
| 19 /** Returns a shader that lights the diffuse and normal maps with a set of l
ights. | 20 /** Returns a shader that lights the diffuse map using the normals and a set
of lights. |
| 20 | 21 |
| 21 It returns a shader with a reference count of 1. | 22 It returns a shader with a reference count of 1. |
| 22 The caller should decrement the shader's reference count when done with
the shader. | 23 The caller should decrement the shader's reference count when done with
the shader. |
| 23 It is an error for count to be < 2. | 24 It is an error for count to be < 2. |
| 24 @param diffuse the diffuse bitmap | 25 @param diffuse the diffuse bitmap |
| 25 @param normal the normal map | |
| 26 @param lights the lights applied to the normal map | 26 @param lights the lights applied to the normal map |
| 27 @param invNormRotation rotation applied to the normal map's normals | |
| 28 @param diffLocalMatrix the local matrix for the diffuse map (transform
from | 27 @param diffLocalMatrix the local matrix for the diffuse map (transform
from |
| 29 texture coordinates to shape source coordinates)
. nullptr is | 28 texture coordinates to shape source coordinates)
. nullptr is |
| 30 interpreted as an identity matrix. | 29 interpreted as an identity matrix. |
| 31 @param normLocalMatrix the local matrix for the normal map (transform f
rom | 30 @param normalSource the source for the normals |
| 32 texture coordinates to shape source coordinates)
. nullptr is | |
| 33 interpreted as an identity matrix. | |
| 34 | 31 |
| 35 nullptr will be returned if: | 32 nullptr will be returned if: |
| 36 either 'diffuse' or 'normal' are empty | 33 'diffuse' is empty |
| 37 either 'diffuse' or 'normal' are too big (> 65535 on a side) | 34 'diffuse' is too big (> 65535 on any side) |
| 38 'diffuse' and 'normal' aren't the same size | |
| 39 | 35 |
| 40 The lighting equation is currently: | 36 The lighting equation is currently: |
| 41 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo
lor | 37 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo
lor |
| 42 | 38 |
| 43 The normal map is currently assumed to be an 8888 image where the normal
at a texel | |
| 44 is retrieved by: | |
| 45 N.x = R-127; | |
| 46 N.y = G-127; | |
| 47 N.z = B-127; | |
| 48 N.normalize(); | |
| 49 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis
is | |
| 50 (127, 127, 0). | |
| 51 */ | 39 */ |
| 52 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, | 40 static sk_sp<SkShader> Make(const SkBitmap& diffuse, sk_sp<SkLights> lights, |
| 53 sk_sp<SkLights> lights, const SkVector& invNormR
otation, | 41 const SkMatrix* diffLocalMatrix, |
| 54 const SkMatrix* diffLocalMatrix, const SkMatrix*
normLocalMatrix); | 42 sk_sp<SkNormalSource> normalSource); |
| 55 | 43 |
| 56 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 44 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
| 57 }; | 45 }; |
| 58 | 46 |
| 59 #endif | 47 #endif |
| OLD | NEW |