Chromium Code Reviews| 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 | 16 |
| 17 class SK_API SkLightingShader { | 17 class SK_API SkLightingShader { |
| 18 public: | 18 public: |
| 19 /** Abstract class that generates or reads in normals for use by SkLightingS hader. Currently | |
| 20 implements the GPU side only. Not to be used as part of the API yet. Use d internally by | |
| 21 SkLightingShader. | |
| 22 */ | |
| 23 class NormalSource : public SkFlattenable { | |
| 24 public: | |
| 25 virtual ~NormalSource(); | |
| 26 | |
| 27 #if SK_SUPPORT_GPU | |
| 28 | |
| 29 /** Returns a fragment processor that takes no input and outputs a norma l (already rotated) | |
|
egdaniel
2016/06/14 18:30:45
in general the no input here isn't true. I believe
dvonbeck
2016/06/14 18:41:44
That would be coming in as a universal though, rig
egdaniel
2016/06/14 19:01:18
Ah right this is asFragmentProcessor, I was thinki
| |
| 30 as its output color. To be used as a child fragment processor. | |
| 31 */ | |
| 32 virtual sk_sp<GrFragmentProcessor> asFragmentProcessor( | |
| 33 GrContext* context, | |
| 34 const SkMatrix& viewM, | |
| 35 const SkMatrix* localMatrix, | |
| 36 SkFilterQuality filterQuality, | |
| 37 SkSourceGammaTreatment gammaTreatment) const = 0; | |
| 38 #endif | |
| 39 | |
| 40 SK_DEFINE_FLATTENABLE_TYPE(NormalSource) | |
| 41 }; | |
| 42 | |
| 43 /** Returns a normal source that provides normals sourced from the the norma l map argument. | |
| 44 Not to be used as part of the API yet. Used internally by SkLightingShad er. | |
| 45 | |
| 46 @param normal the normal map | |
| 47 @param invNormRotation rotation applied to the normal map's norma ls | |
| 48 @param normLocalM the local matrix for the normal map | |
| 49 | |
| 50 nullptr will be returned if | |
| 51 'normal' is empty | |
| 52 'normal' too big (> 65535 on either side) | |
| 53 | |
| 54 The normal map is currently assumed to be an 8888 image where the normal at a texel | |
| 55 is retrieved by: | |
| 56 N.x = R-127; | |
| 57 N.y = G-127; | |
| 58 N.z = B-127; | |
| 59 N.normalize(); | |
| 60 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is | |
| 61 (127, 127, 0). | |
| 62 */ | |
| 63 class NormalMapSource { | |
| 64 public: | |
| 65 static sk_sp<NormalSource> Make(const SkBitmap& normal, const SkVector& invNormRotation, | |
| 66 const SkMatrix* normLocalM); | |
| 67 | |
| 68 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | |
| 69 }; | |
| 70 | |
| 19 /** Returns a shader that lights the diffuse and normal maps with a set of l ights. | 71 /** Returns a shader that lights the diffuse and normal maps with a set of l ights. |
| 20 | 72 |
| 21 It returns a shader with a reference count of 1. | 73 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. | 74 The caller should decrement the shader's reference count when done with the shader. |
| 23 It is an error for count to be < 2. | 75 It is an error for count to be < 2. |
| 24 @param diffuse the diffuse bitmap | 76 @param diffuse the diffuse bitmap |
| 25 @param normal the normal map | 77 @param normal the normal map |
| 26 @param lights the lights applied to the normal map | 78 @param lights the lights applied to the normal map |
| 27 @param invNormRotation rotation applied to the normal map's normals | 79 @param invNormRotation rotation applied to the normal map's normals |
| 28 @param diffLocalMatrix the local matrix for the diffuse texture | 80 @param diffLocalMatrix the local matrix for the diffuse texture |
| 29 @param normLocalMatrix the local matrix for the normal map | 81 @param normLocalMatrix the local matrix for the normal map |
| 30 | 82 |
| 31 nullptr will be returned if: | 83 nullptr will be returned if: |
| 32 either 'diffuse' or 'normal' are empty | 84 either 'diffuse' or 'normal' are empty |
| 33 either 'diffuse' or 'normal' are too big (> 65535 on a side) | 85 either 'diffuse' or 'normal' are too big (> 65535 on a side) |
| 34 'diffuse' and 'normal' aren't the same size | 86 'diffuse' and 'normal' aren't the same size |
| 35 | 87 |
| 36 The lighting equation is currently: | 88 The lighting equation is currently: |
| 37 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo lor | 89 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo lor |
| 38 | 90 |
| 39 The normal map is currently assumed to be an 8888 image where the normal at a texel | 91 The normal map is currently assumed to be an 8888 image where the normal at a texel |
| 40 is retrieved by: | 92 is retrieved by: |
| 41 N.x = R-127; | 93 N.x = R-127; |
| 42 N.y = G-127; | 94 N.y = G-127; |
| 43 N.z = B-127; | 95 N.z = B-127; |
| 44 N.normalize(); | 96 N.normalize(); |
| 45 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is | 97 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is |
| 46 (127, 127, 0). | 98 (127, 127, 0). |
| 47 */ | 99 */ |
| 48 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, | 100 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, |
|
egdaniel
2016/06/14 18:30:45
We should probably also have a version here that t
egdaniel
2016/06/14 18:35:48
Just saw this change in the next CL :)
dvonbeck
2016/06/14 18:41:44
Acknowledged.
| |
| 49 sk_sp<SkLights> lights, const SkVector& invNormR otation, | 101 sk_sp<SkLights> lights, const SkVector& invNormR otation, |
| 50 const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix); | 102 const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix); |
| 51 | 103 |
| 52 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 104 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
| 53 }; | 105 }; |
| 54 | 106 |
| 55 #endif | 107 #endif |
| OLD | NEW |