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 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkBitmapProcShader.h" | 10 #include "SkBitmapProcShader.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 | 52 |
53 builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f), | 53 builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f), |
54 SkVector3::Make(SK_ScalarRoot2Over2, | 54 SkVector3::Make(SK_ScalarRoot2Over2, |
55 0.0f, | 55 0.0f, |
56 SK_ScalarRoot2Over2))); | 56 SK_ScalarRoot2Over2))); |
57 builder.add(SkLights::Light(SkColor3f::Make(0.2f, 0.2f, 0.2f))); | 57 builder.add(SkLights::Light(SkColor3f::Make(0.2f, 0.2f, 0.2f))); |
58 | 58 |
59 fLights = builder.finish(); | 59 fLights = builder.finish(); |
60 } | 60 } |
61 | 61 |
62 protected: | 62 protected: |
robertphillips
2016/07/11 19:13:21
Would it make sense to convert this to an enum of
dvonbeck
2016/07/13 14:23:37
Can't do it. SkNormalSource's SkBitmapProcShader n
| |
63 enum NormalMap { | 63 enum NormalMap { |
64 kHemi_NormalMap, | 64 kHemi_NormalMap, |
65 kFrustum_NormalMap, | 65 kFrustum_NormalMap, |
66 kTetra_NormalMap, | 66 kTetra_NormalMap, |
67 | 67 |
68 kLast_NormalMap = kTetra_NormalMap | 68 kLast_NormalMap = kTetra_NormalMap |
69 }; | 69 }; |
70 | 70 |
71 static const int kNormalMapCount = kLast_NormalMap+1; | 71 static const int kNormalMapCount = kLast_NormalMap+1; |
72 | 72 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 sk_sp<SkShader> normalMap = SkMakeBitmapShader(fNormalMaps[mapType], | 105 sk_sp<SkShader> normalMap = SkMakeBitmapShader(fNormalMaps[mapType], |
106 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix, n ullptr); | 106 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix, n ullptr); |
107 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(s td::move(normalMap), | 107 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(s td::move(normalMap), |
108 c tm); | 108 c tm); |
109 paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::mo ve(normalSource), | 109 paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::mo ve(normalSource), |
110 fLights)); | 110 fLights)); |
111 | 111 |
112 canvas->drawRect(r, paint); | 112 canvas->drawRect(r, paint); |
113 } | 113 } |
114 | 114 |
115 void drawBevelRect(SkCanvas* canvas, const SkRect& r) { | |
116 | |
117 SkRect bitmapBounds = SkRect::MakeIWH(fDiffuse.width(), fDiffuse.height( )); | |
118 | |
119 SkMatrix matrix; | |
120 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); | |
121 | |
122 SkPaint paint; | |
robertphillips
2016/07/11 19:13:21
Add '\n'
dvonbeck
2016/07/13 14:23:37
Done.
| |
123 auto diffuseShader = SkBitmapProcShader::MakeBitmapShader(fDiffuse, | |
124 SkShader::kCla mp_TileMode, SkShader::kClamp_TileMode, &matrix); | |
125 auto normalSource = SkNormalSource::MakeBevel( | |
126 SkNormalSource::BevelType::kLinear, | |
127 0.15f * SkIntToScalar(kTexSize), | |
128 0.2f * SkIntToScalar(kTexSize)); | |
129 paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::mo ve(normalSource), | |
130 fLights)); | |
131 | |
132 canvas->drawRect(r, paint); | |
133 } | |
134 | |
115 void onDraw(SkCanvas* canvas) override { | 135 void onDraw(SkCanvas* canvas) override { |
116 SkMatrix m; | 136 SkMatrix m; |
117 SkRect r; | 137 SkRect r; |
118 | 138 |
119 { | 139 { |
120 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize)) ; | 140 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize)) ; |
121 this->drawRect(canvas, r, kHemi_NormalMap); | 141 this->drawRect(canvas, r, kHemi_NormalMap); |
122 | 142 |
123 canvas->save(); | 143 canvas->save(); |
124 m.setRotate(45.0f, r.centerX(), r.centerY()); | 144 m.setRotate(45.0f, r.centerX(), r.centerY()); |
125 m.postTranslate(kGMSize/2.0f - kTexSize/2.0f, 0.0f); | 145 m.postTranslate(kGMSize/2.0f - kTexSize/2.0f, 0.0f); |
126 canvas->setMatrix(m); | 146 canvas->setMatrix(m); |
127 this->drawRect(canvas, r, kHemi_NormalMap); | 147 this->drawRect(canvas, r, kHemi_NormalMap); |
128 canvas->restore(); | 148 canvas->restore(); |
129 } | 149 } |
130 | 150 |
131 { | 151 { |
132 r.offset(kGMSize - kTexSize, 0); | 152 r.offset(kGMSize - kTexSize, 0); |
133 this->drawRect(canvas, r, kFrustum_NormalMap); | 153 this->drawRect(canvas, r, kFrustum_NormalMap); |
134 | 154 |
135 canvas->save(); | 155 canvas->save(); |
136 m.setRotate(45.0f, r.centerX(), r.centerY()); | 156 m.setRotate(45.0f, r.centerX(), r.centerY()); |
137 m.postTranslate(0.0f, kGMSize/2.0f - kTexSize/2.0f); | 157 m.postTranslate(0.0f, kGMSize/2.0f - kTexSize/2.0f); |
138 canvas->setMatrix(m); | 158 canvas->setMatrix(m); |
139 this->drawRect(canvas, r, kFrustum_NormalMap); | 159 this->drawBevelRect(canvas, r); |
140 canvas->restore(); | 160 canvas->restore(); |
141 } | 161 } |
142 | 162 |
143 { | 163 { |
144 r.offset(0, kGMSize - kTexSize); | 164 r.offset(0, kGMSize - kTexSize); |
145 this->drawRect(canvas, r, kTetra_NormalMap); | 165 this->drawRect(canvas, r, kTetra_NormalMap); |
146 | 166 |
147 canvas->save(); | 167 canvas->save(); |
148 m.setRotate(45.0f, r.centerX(), r.centerY()); | 168 m.setRotate(45.0f, r.centerX(), r.centerY()); |
149 m.postTranslate(-kGMSize/2.0f + kTexSize/2.0f, 0.0f); | 169 m.postTranslate(-kGMSize/2.0f + kTexSize/2.0f, 0.0f); |
(...skipping 24 matching lines...) Expand all Loading... | |
174 | 194 |
175 sk_sp<SkLights> fLights; | 195 sk_sp<SkLights> fLights; |
176 | 196 |
177 typedef GM INHERITED; | 197 typedef GM INHERITED; |
178 }; | 198 }; |
179 | 199 |
180 ////////////////////////////////////////////////////////////////////////////// | 200 ////////////////////////////////////////////////////////////////////////////// |
181 | 201 |
182 DEF_GM(return new LightingShaderGM;) | 202 DEF_GM(return new LightingShaderGM;) |
183 } | 203 } |
OLD | NEW |