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

Side by Side Diff: gm/lightingshader.cpp

Issue 2080993002: Added API for Bevel NormalSource. (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-diffuse-api-change
Patch Set: Addressed patch 7 comments Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | src/core/SkNormalBevelSource.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
123 auto diffuseShader = SkBitmapProcShader::MakeBitmapShader(fDiffuse,
124 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix);
125 auto normalSource = SkNormalSource::MakeBevel(SkNormalSource::BevelType: :kLinear,
126 0.15f * SkIntToScalar(kTex Size),
127 0.2f * SkIntToScalar(kTexS ize));
128 paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::mo ve(normalSource),
129 fLights));
130
131 canvas->drawRect(r, paint);
132 }
133
115 void onDraw(SkCanvas* canvas) override { 134 void onDraw(SkCanvas* canvas) override {
116 SkMatrix m; 135 SkMatrix m;
117 SkRect r; 136 SkRect r;
118 137
119 { 138 {
120 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize)) ; 139 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize)) ;
121 this->drawRect(canvas, r, kHemi_NormalMap); 140 this->drawRect(canvas, r, kHemi_NormalMap);
122 141
123 canvas->save(); 142 canvas->save();
124 m.setRotate(45.0f, r.centerX(), r.centerY()); 143 m.setRotate(45.0f, r.centerX(), r.centerY());
125 m.postTranslate(kGMSize/2.0f - kTexSize/2.0f, 0.0f); 144 m.postTranslate(kGMSize/2.0f - kTexSize/2.0f, 0.0f);
126 canvas->setMatrix(m); 145 canvas->setMatrix(m);
127 this->drawRect(canvas, r, kHemi_NormalMap); 146 this->drawRect(canvas, r, kHemi_NormalMap);
128 canvas->restore(); 147 canvas->restore();
129 } 148 }
130 149
131 { 150 {
132 r.offset(kGMSize - kTexSize, 0); 151 r.offset(kGMSize - kTexSize, 0);
133 this->drawRect(canvas, r, kFrustum_NormalMap); 152 this->drawRect(canvas, r, kFrustum_NormalMap);
134 153
135 canvas->save(); 154 canvas->save();
136 m.setRotate(45.0f, r.centerX(), r.centerY()); 155 m.setRotate(45.0f, r.centerX(), r.centerY());
137 m.postTranslate(0.0f, kGMSize/2.0f - kTexSize/2.0f); 156 m.postTranslate(0.0f, kGMSize/2.0f - kTexSize/2.0f);
138 canvas->setMatrix(m); 157 canvas->setMatrix(m);
139 this->drawRect(canvas, r, kFrustum_NormalMap); 158 this->drawBevelRect(canvas, r);
egdaniel 2016/07/25 15:48:00 do we really want to change this GM from using nor
dvonbeck 2016/07/25 20:37:13 Agreed. Done.
140 canvas->restore(); 159 canvas->restore();
141 } 160 }
142 161
143 { 162 {
144 r.offset(0, kGMSize - kTexSize); 163 r.offset(0, kGMSize - kTexSize);
145 this->drawRect(canvas, r, kTetra_NormalMap); 164 this->drawRect(canvas, r, kTetra_NormalMap);
146 165
147 canvas->save(); 166 canvas->save();
148 m.setRotate(45.0f, r.centerX(), r.centerY()); 167 m.setRotate(45.0f, r.centerX(), r.centerY());
149 m.postTranslate(-kGMSize/2.0f + kTexSize/2.0f, 0.0f); 168 m.postTranslate(-kGMSize/2.0f + kTexSize/2.0f, 0.0f);
(...skipping 24 matching lines...) Expand all
174 193
175 sk_sp<SkLights> fLights; 194 sk_sp<SkLights> fLights;
176 195
177 typedef GM INHERITED; 196 typedef GM INHERITED;
178 }; 197 };
179 198
180 ////////////////////////////////////////////////////////////////////////////// 199 //////////////////////////////////////////////////////////////////////////////
181 200
182 DEF_GM(return new LightingShaderGM;) 201 DEF_GM(return new LightingShaderGM;)
183 } 202 }
OLDNEW
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | src/core/SkNormalBevelSource.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698