diff options
author | 2015-08-20 05:15:06 -0700 | |
---|---|---|
committer | 2015-08-20 05:15:07 -0700 | |
commit | 2f0dbc761a626473c19db7de561c7072b12953c5 (patch) | |
tree | 5549b8e7359d6a55e171dd1b76634d93b343b491 /samplecode | |
parent | d1c6b7c5007b5c609b44a9cdfe95ef64a5a8f29f (diff) |
Update SkLightingShader to support rotation
This also:
makes the SkLightingShader handle normal maps where the rects aren't aligned between the diffuse and normal maps.
adds a light aggregating class (Lights) to SkLightingShader (along with a Builder nested class).
Split out of https://codereview.chromium.org/1261433009/ (Add SkCanvas::drawLitAtlas call)
Committed: https://skia.googlesource.com/skia/+/45b59ed6e4e231814dbdb9f707b3d2a7ee50de84
Review URL: https://codereview.chromium.org/1291783003
Diffstat (limited to 'samplecode')
-rwxr-xr-x | samplecode/SampleLighting.cpp | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/samplecode/SampleLighting.cpp b/samplecode/SampleLighting.cpp index 5b4f2e0931..4838cf8183 100755 --- a/samplecode/SampleLighting.cpp +++ b/samplecode/SampleLighting.cpp @@ -11,6 +11,21 @@ #include "SkCanvas.h" #include "SkImageDecoder.h" #include "SkLightingShader.h" +#include "SkPoint3.h" + +static const SkLightingShader::Lights* create_lights(SkScalar angle, SkScalar blue) { + + const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_ScalarPI*0.25f), + SkScalarCos(angle)*SkScalarSin(SK_ScalarPI*0.25f), + SkScalarCos(SK_ScalarPI*0.25f)); + + SkLightingShader::Lights::Builder builder; + + builder.add(SkLight(SkColor3f::Make(1.0f, 1.0f, blue), dir)); + builder.add(SkLight(SkColor3f::Make(0.1f, 0.1f, 0.1f))); + + return builder.finish(); +} //////////////////////////////////////////////////////////////////////////// @@ -21,7 +36,6 @@ public: SkBitmap fNormalBitmap; SkScalar fLightAngle; SkScalar fColorFactor; - SkColor3f fAmbientColor; LightingView() { SkString diffusePath = GetResourcePath("brickwork-texture.jpg"); @@ -32,16 +46,11 @@ public: fLightAngle = 0.0f; fColorFactor = 0.0f; - SkLightingShader::Light light; - light.fColor = SkColor3f::Make(1.0f, 1.0f, 1.0f); - light.fDirection.fX = SkScalarSin(fLightAngle)*SkScalarSin(SK_ScalarPI*0.25f); - light.fDirection.fY = SkScalarCos(fLightAngle)*SkScalarSin(SK_ScalarPI*0.25f); - light.fDirection.fZ = SkScalarCos(SK_ScalarPI*0.25f); - - fAmbientColor = SkColor3f::Make(0.1f, 0.1f, 0.1f); + SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLightAngle, 1.0f)); fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap, - light, fAmbientColor, nullptr)); + lights, SkVector::Make(1.0f, 0.0f), + nullptr, nullptr)); } virtual ~LightingView() {} @@ -63,14 +72,12 @@ protected: fColorFactor = 0.0f; } - SkLightingShader::Light light; - light.fColor = SkColor3f::Make(1.0f, 1.0f, fColorFactor); - light.fDirection.fX = SkScalarSin(fLightAngle)*SkScalarSin(SK_ScalarPI*0.25f); - light.fDirection.fY = SkScalarCos(fLightAngle)*SkScalarSin(SK_ScalarPI*0.25f); - light.fDirection.fZ = SkScalarCos(SK_ScalarPI*0.25f); + SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLightAngle, + fColorFactor)); fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap, - light, fAmbientColor, nullptr)); + lights, SkVector::Make(1.0f, 0.0f), + nullptr, nullptr)); SkPaint paint; paint.setShader(fShader); |