| 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 #include "DecodeFile.h" | 7 #include "DecodeFile.h" |
| 8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "Resources.h" | 9 #include "Resources.h" |
| 10 | 10 |
| 11 #include "SkBitmapProcShader.h" |
| 11 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 12 #include "SkLightingShader.h" | 13 #include "SkLightingShader.h" |
| 14 #include "SkNormalSource.h" |
| 13 #include "SkPoint3.h" | 15 #include "SkPoint3.h" |
| 14 | 16 |
| 15 static sk_sp<SkLights> create_lights(SkScalar angle, SkScalar blue) { | 17 static sk_sp<SkLights> create_lights(SkScalar angle, SkScalar blue) { |
| 16 | 18 |
| 17 const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_Scal
arPI*0.25f), | 19 const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_Scal
arPI*0.25f), |
| 18 SkScalarCos(angle)*SkScalarSin(SK_Scal
arPI*0.25f), | 20 SkScalarCos(angle)*SkScalarSin(SK_Scal
arPI*0.25f), |
| 19 SkScalarCos(SK_ScalarPI*0.25f)); | 21 SkScalarCos(SK_ScalarPI*0.25f)); |
| 20 | 22 |
| 21 SkLights::Builder builder; | 23 SkLights::Builder builder; |
| 22 | 24 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 59 |
| 58 void onDrawContent(SkCanvas* canvas) override { | 60 void onDrawContent(SkCanvas* canvas) override { |
| 59 fLightAngle += 0.015f; | 61 fLightAngle += 0.015f; |
| 60 fColorFactor += 0.01f; | 62 fColorFactor += 0.01f; |
| 61 if (fColorFactor > 1.0f) { | 63 if (fColorFactor > 1.0f) { |
| 62 fColorFactor = 0.0f; | 64 fColorFactor = 0.0f; |
| 63 } | 65 } |
| 64 | 66 |
| 65 sk_sp<SkLights> lights(create_lights(fLightAngle, fColorFactor)); | 67 sk_sp<SkLights> lights(create_lights(fLightAngle, fColorFactor)); |
| 66 SkPaint paint; | 68 SkPaint paint; |
| 67 paint.setShader(SkLightingShader::Make(fDiffuseBitmap, fNormalBitmap, | 69 sk_sp<SkShader> normalMap = SkMakeBitmapShader(fNormalBitmap, |
| 68 std::move(lights), SkVector::Make
(1.0f, 0.0f), | 70 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullp
tr); |
| 69 nullptr, nullptr)); | 71 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap( |
| 72 std::move(normalMap), SkMatrix::I()); |
| 73 paint.setShader(SkLightingShader::Make(fDiffuseBitmap, std::move(lights)
, nullptr, |
| 74 std::move(normalSource))); |
| 70 paint.setColor(SK_ColorBLACK); | 75 paint.setColor(SK_ColorBLACK); |
| 71 | 76 |
| 72 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(), | 77 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(), |
| 73 (SkScalar)fDiffuseBitmap.height()); | 78 (SkScalar)fDiffuseBitmap.height()); |
| 74 canvas->drawRect(r, paint); | 79 canvas->drawRect(r, paint); |
| 75 | 80 |
| 76 // so we're constantly updating | 81 // so we're constantly updating |
| 77 this->inval(nullptr); | 82 this->inval(nullptr); |
| 78 } | 83 } |
| 79 | 84 |
| 80 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { | 85 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { |
| 81 this->inval(nullptr); | 86 this->inval(nullptr); |
| 82 return this->INHERITED::onFindClickHandler(x, y, modi); | 87 return this->INHERITED::onFindClickHandler(x, y, modi); |
| 83 } | 88 } |
| 84 | 89 |
| 85 private: | 90 private: |
| 86 typedef SampleView INHERITED; | 91 typedef SampleView INHERITED; |
| 87 }; | 92 }; |
| 88 | 93 |
| 89 ////////////////////////////////////////////////////////////////////////////// | 94 ////////////////////////////////////////////////////////////////////////////// |
| 90 | 95 |
| 91 static SkView* MyFactory() { return new LightingView; } | 96 static SkView* MyFactory() { return new LightingView; } |
| 92 static SkViewRegister reg(MyFactory); | 97 static SkViewRegister reg(MyFactory); |
| OLD | NEW |