OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2016 Google Inc. | 3 * Copyright 2016 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkLights.h" | 9 #include "SkLights.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 return nullptr; | 22 return nullptr; |
23 } | 23 } |
24 | 24 |
25 if (isAmbient) { | 25 if (isAmbient) { |
26 builder.add(Light::MakeAmbient(color)); | 26 builder.add(Light::MakeAmbient(color)); |
27 } else { | 27 } else { |
28 SkVector3 dirOrPos; | 28 SkVector3 dirOrPos; |
29 if (!buf.readScalarArray(&dirOrPos.fX, 3)) { | 29 if (!buf.readScalarArray(&dirOrPos.fX, 3)) { |
30 return nullptr; | 30 return nullptr; |
31 } | 31 } |
| 32 SkScalar intensity = 0.0f; |
| 33 if (isPoint) { |
| 34 intensity = buf.readScalar(); |
| 35 } |
32 | 36 |
33 sk_sp<SkImage> depthMap; | 37 sk_sp<SkImage> depthMap; |
34 bool hasShadowMap = buf.readBool(); | 38 bool hasShadowMap = buf.readBool(); |
35 if (hasShadowMap) { | 39 if (hasShadowMap) { |
36 if (!(depthMap = buf.readImage())) { | 40 if (!(depthMap = buf.readImage())) { |
37 return nullptr; | 41 return nullptr; |
38 } | 42 } |
39 } | 43 } |
40 | 44 |
41 if (isPoint) { | 45 if (isPoint) { |
42 Light light = Light::MakePoint(color, dirOrPos); | 46 Light light = Light::MakePoint(color, dirOrPos, intensity); |
43 light.setShadowMap(depthMap); | 47 light.setShadowMap(depthMap); |
44 builder.add(light); | 48 builder.add(light); |
45 } else { | 49 } else { |
46 Light light = Light::MakeDirectional(color, dirOrPos); | 50 Light light = Light::MakeDirectional(color, dirOrPos); |
47 light.setShadowMap(depthMap); | 51 light.setShadowMap(depthMap); |
48 builder.add(light); | 52 builder.add(light); |
49 } | 53 } |
50 } | 54 } |
51 } | 55 } |
52 | 56 |
53 return builder.finish(); | 57 return builder.finish(); |
54 } | 58 } |
55 | 59 |
56 void SkLights::flatten(SkWriteBuffer& buf) const { | 60 void SkLights::flatten(SkWriteBuffer& buf) const { |
57 | 61 |
58 buf.writeInt(this->numLights()); | 62 buf.writeInt(this->numLights()); |
59 for (int l = 0; l < this->numLights(); ++l) { | 63 for (int l = 0; l < this->numLights(); ++l) { |
60 const Light& light = this->light(l); | 64 const Light& light = this->light(l); |
61 | 65 |
62 bool isAmbient = Light::kAmbient_LightType == light.type(); | 66 bool isAmbient = Light::kAmbient_LightType == light.type(); |
63 bool isPoint = Light::kPoint_LightType == light.type(); | 67 bool isPoint = Light::kPoint_LightType == light.type(); |
64 | 68 |
65 buf.writeBool(isAmbient); | 69 buf.writeBool(isAmbient); |
66 buf.writeBool(isPoint); | 70 buf.writeBool(isPoint); |
67 buf.writeScalarArray(&light.color().fX, 3); | 71 buf.writeScalarArray(&light.color().fX, 3); |
68 if (!isAmbient) { | 72 if (!isAmbient) { |
69 buf.writeScalarArray(&light.dir().fX, 3); | 73 if (isPoint) { |
| 74 buf.writeScalarArray(&light.pos().fX, 3); |
| 75 buf.writeScalar(light.intensity()); |
| 76 } else { |
| 77 buf.writeScalarArray(&light.dir().fX, 3); |
| 78 } |
70 bool hasShadowMap = light.getShadowMap() != nullptr; | 79 bool hasShadowMap = light.getShadowMap() != nullptr; |
71 buf.writeBool(hasShadowMap); | 80 buf.writeBool(hasShadowMap); |
72 if (hasShadowMap) { | 81 if (hasShadowMap) { |
73 buf.writeImage(light.getShadowMap()); | 82 buf.writeImage(light.getShadowMap()); |
74 } | 83 } |
75 } | 84 } |
76 } | 85 } |
77 } | 86 } |
OLD | NEW |