Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Unified Diff: src/core/SkLights.cpp

Issue 2287553002: Moved ambient lights out of SkLight's light array (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: added ambient light calculations to Raster renderer of LightingShader Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkLightingShader.cpp ('k') | src/core/SkShadowShader.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkLights.cpp
diff --git a/src/core/SkLights.cpp b/src/core/SkLights.cpp
index 7d8f9ed7a58407c7a877d4089ae0741d0107a10c..962997fc31436c4a3b4428a194210b227d9cef24 100644
--- a/src/core/SkLights.cpp
+++ b/src/core/SkLights.cpp
@@ -10,11 +10,18 @@
#include "SkReadBuffer.h"
sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) {
+ Builder builder;
+
+ SkColor3f ambColor;
+ if (!buf.readScalarArray(&ambColor.fX, 3)) {
+ return nullptr;
+ }
+
+ builder.setAmbientLightColor(ambColor);
+
int numLights = buf.readInt();
- Builder builder;
for (int l = 0; l < numLights; ++l) {
- bool isAmbient = buf.readBool();
bool isPoint = buf.readBool();
SkColor3f color;
@@ -22,35 +29,29 @@ sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) {
return nullptr;
}
- if (isAmbient) {
- builder.add(Light::MakeAmbient(color));
- } else {
- SkVector3 dirOrPos;
- if (!buf.readScalarArray(&dirOrPos.fX, 3)) {
- return nullptr;
- }
- SkScalar intensity = 0.0f;
- if (isPoint) {
- intensity = buf.readScalar();
- }
+ SkVector3 dirOrPos;
+ if (!buf.readScalarArray(&dirOrPos.fX, 3)) {
+ return nullptr;
+ }
- sk_sp<SkImage> depthMap;
- bool hasShadowMap = buf.readBool();
- if (hasShadowMap) {
- if (!(depthMap = buf.readImage())) {
- return nullptr;
- }
+ sk_sp<SkImage> depthMap;
+ bool hasShadowMap = buf.readBool();
+ if (hasShadowMap) {
+ if (!(depthMap = buf.readImage())) {
+ return nullptr;
}
+ }
- if (isPoint) {
- Light light = Light::MakePoint(color, dirOrPos, intensity);
- light.setShadowMap(depthMap);
- builder.add(light);
- } else {
- Light light = Light::MakeDirectional(color, dirOrPos);
- light.setShadowMap(depthMap);
- builder.add(light);
- }
+ if (isPoint) {
+ SkScalar intensity = 0.0f;
+ intensity = buf.readScalar();
+ Light light = Light::MakePoint(color, dirOrPos, intensity);
+ light.setShadowMap(depthMap);
+ builder.add(light);
+ } else {
+ Light light = Light::MakeDirectional(color, dirOrPos);
+ light.setShadowMap(depthMap);
+ builder.add(light);
}
}
@@ -58,29 +59,24 @@ sk_sp<SkLights> SkLights::MakeFromBuffer(SkReadBuffer& buf) {
}
void SkLights::flatten(SkWriteBuffer& buf) const {
+ buf.writeScalarArray(&this->ambientLightColor().fX, 3);
buf.writeInt(this->numLights());
for (int l = 0; l < this->numLights(); ++l) {
const Light& light = this->light(l);
- bool isAmbient = Light::kAmbient_LightType == light.type();
bool isPoint = Light::kPoint_LightType == light.type();
- buf.writeBool(isAmbient);
buf.writeBool(isPoint);
buf.writeScalarArray(&light.color().fX, 3);
- if (!isAmbient) {
- if (isPoint) {
- buf.writeScalarArray(&light.pos().fX, 3);
- buf.writeScalar(light.intensity());
- } else {
- buf.writeScalarArray(&light.dir().fX, 3);
- }
- bool hasShadowMap = light.getShadowMap() != nullptr;
- buf.writeBool(hasShadowMap);
- if (hasShadowMap) {
- buf.writeImage(light.getShadowMap());
- }
+ buf.writeScalarArray(&light.dir().fX, 3);
+ bool hasShadowMap = light.getShadowMap() != nullptr;
+ buf.writeBool(hasShadowMap);
+ if (hasShadowMap) {
+ buf.writeImage(light.getShadowMap());
+ }
+ if (isPoint) {
+ buf.writeScalar(light.intensity());
}
}
}
« no previous file with comments | « src/core/SkLightingShader.cpp ('k') | src/core/SkShadowShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698